Opened 6 years ago

# Optimal dual solution of LP from MixedIntegerLinearProgram

Reported by: Owned by: Rudi major sage-wishlist numerical Linear optimization Rudi, mkoeppe, dcoudert N/A

### 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+5*x)
sage: LP.add_constraint( x+2*x <= 7, name = 'first' )
sage: LP.add_constraint( 2*x+x <= 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+5*x)
sage: LP.add_constraint( x+2*x <= 7, id = y )
sage: LP.add_constraint( 2*x+x <= 5, id = y )
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,y]= 3
sage: LP.add_dual_constraint(y+7*y == 4, id = x)
sage: LP.dual()
Mixed Integer Program  ( minimization, 2 variables, 3 constraints )
```

### comment:1 Changed 5 years ago by mkoeppe

• Cc mkoeppe added; ncohen removed