I am using python with docplex library to solve a linear programming problem. I want to get its simplex multipliers, or coefficients (of slack variables) in the final tableau.
Have you had a look at dual value ?
dual_values(cts)
Returns the dual values of a sequence of linear constraints.
Note: the model must a pure LP: no integer or binary variable, no piecewise, no SOS. The model must also be solved successfully before
calling this method.
In http://ibmdecisionoptimization.github.io/docplex-doc/mp/docplex.mp.model.html
Let me translate the OPL example volsay into docplex
from docplex.mp.model import Model
mdl = Model(name='volsay')
Gas = mdl.continuous_var(name='Gas')
Chloride = mdl.continuous_var(name='Cloride')
mdl.add_constraint(Gas + Chloride <= 50, 'ctMaxTotal1')
mdl.add_constraint(3 * Gas + 4 * Chloride <= 180, 'ctMaxTotal2')
mdl.add_constraint(Chloride <= 40, 'ctMaxChloride')
mdl.maximize(40 * Gas + 50 * Chloride)
mdl.solve()
for v in mdl.iter_continuous_vars():
print(v," = ",v.solution_value)
print("ctMaxTotalDual = ",mdl.dual_values(mdl.find_matching_linear_constraints('ctMaxTotal1')));
In OPL CPLEX to display the dual we would write
// --------------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55
// Copyright IBM Corporation 1998, 2013. All Rights Reserved.
//
// Note to U.S. Government Users Restricted Rights:
// Use, duplication or disclosure restricted by GSA ADP Schedule
// Contract with IBM Corp.
// --------------------------------------------------------------------------
dvar float+ Gas;
dvar float+ Chloride;
maximize
40 * Gas + 50 * Chloride;
subject to {
ctMaxTotal:
Gas + Chloride <= 50;
ctMaxTotal2:
3 * Gas + 4 * Chloride <= 180;
ctMaxChloride:
Chloride <= 40;
}
tuple SolutionT{
float Gas;
float Chloride;
};
{SolutionT} Solution = {<Gas,Chloride>};
execute{
writeln(Solution);
}
execute
{
writeln("ctMaxTotalDual = ",ctMaxTotal.dual);
}