Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimal dual solution of LP from MixedIntegerLinearProgram #18466

Open
sagetrac-Rudi mannequin opened this issue May 21, 2015 · 1 comment
Open

Optimal dual solution of LP from MixedIntegerLinearProgram #18466

sagetrac-Rudi mannequin opened this issue May 21, 2015 · 1 comment

Comments

@sagetrac-Rudi
Copy link
Mannequin

sagetrac-Rudi mannequin commented May 21, 2015

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 )

CC: @sagetrac-Rudi @mkoeppe @dcoudert

Component: numerical

Issue created by migration from https://trac.sagemath.org/ticket/18466

@dcoudert
Copy link
Contributor

comment:2

I agree that this would be a nice addition, but we should also get a way to extend a constraint (add a variable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant