Opened 7 years ago
Last modified 3 years ago
#18466 new enhancement
Optimal dual solution of LP from MixedIntegerLinearProgram
Reported by: | Rudi | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-wishlist |
Component: | numerical | Keywords: | Linear optimization |
Cc: | Rudi, mkoeppe, dcoudert | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Currently, there is no direct way to access the optimal dual solution of a linear optimization problem. Dual solutions are used for analysing the sensitivity of the optimal solution, and also for column generation.
In MixedIntegerLinearProgram? it is possible to assign a name to constraint and so, to point out dual variables. The following would resolve this ticket:
sage: LP=MixedIntegerLinearProgram() sage: x = LP.new_variable() sage: LP.set_objective(4*x[1]+5*x[2]) sage: LP.add_constraint( x[1]+2*x[2] <= 7, name = 'first' ) sage: LP.add_constraint( 2*x[1]+x[2] <= 5, name = 'second' ) sage: LP.solve() 19.0 sage: LP.get_values(x) {1: 1. , 2: 3.} sage: LP.get_dual_values() {'first': 2. , 'second': 1.}
Right now, MixedIntegerLinearProgram? is already a terrific piece of work. But this enhancement would eliminate the need for me to use another interface to LP solvers, in all but few cases.
I cannot properly estimate how much extra work it would be to realise, but if the dual variables behaved as dictionaries, just like the current primal variables, the interface would be even more convenient. In my dreams, the following works:
sage: LP=MixedIntegerLinearProgram() sage: x = LP.new_variable() sage: y = LP.new_dual_variable(nonnegative = True) sage: LP.set_objective(4*x[1]+5*x[2]) sage: LP.add_constraint( x[1]+2*x[2] <= 7, id = y[1] ) sage: LP.add_constraint( 2*x[1]+x[2] <= 5, id = y[2] ) sage: LP.solve() 19.0 sage: LP.get_values(x) {1: 1. , 2: 3.} sage: LP.get_values(y) {1: 2. , 2: 1.}
It would be nice as well to have a method for changing the coefficient of variable x[i] in constraint y[j], a method to add a whole column to the constraint matrix, and a method for creating the dual.
sage: LP[x[2],y[1]]= 3 sage: LP.add_dual_constraint(y[1]+7*y[2] == 4, id = x[3]) sage: LP.dual() Mixed Integer Program ( minimization, 2 variables, 3 constraints )
Change History (2)
comment:1 Changed 6 years ago by
- Cc mkoeppe added; ncohen removed
comment:2 Changed 3 years ago by
- Cc dcoudert added
I agree that this would be a nice addition, but we should also get a way to extend a constraint (add a variable).