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.
Asked
Active
Viewed 572 times
1 Answers
-1
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);
}

halfer
- 19,824
- 17
- 99
- 186

Alex Fleischer
- 9,276
- 2
- 12
- 15
-
Thanks for the reply, I have one more question if you don't mind, at each iteration of the column generation method, do you write code to select the column that exits the basis? Otherwise, it would be such a waste to have the problem solved one more time with new columns. – Aaron_Geng Jun 17 '20 at 05:17
-
See https://link.medium.com/A00p8DmQn7 for an example – Alex Fleischer Jun 17 '20 at 05:42
-
Thanks, but it doesn't look like what I was looking for. In the post, he simply re-solves the master problem after new columns being generated, what I was looking for is some cplex function (may or may not be any) that can utilize the previous optimal solution. Like dual simple method, you don't need to resolve the problem from scratch after new rows being added to the primal problem. – Aaron_Geng Jun 17 '20 at 07:40
-
Hi, in https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/ you may have a look at incremental changes https://github.com/AlexFleischerParis/zoodocplex/blob/master/zooincremental.py – Alex Fleischer Jun 17 '20 at 09:53
-
Is there a way that I can access the final tableau in cplex? I did some research, but didn't find good reference, can you help? Thanks – Aaron_Geng Jun 17 '20 at 19:33
-
https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.8.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/APIs/Python/13_simplex_tableau_eg.html – Aaron_Geng Jun 17 '20 at 19:40