sasoptpy.Model.get_solution

Model.get_solution(self, vtype='Primal', solution=None, pivot=False)[source]

Returns the primal and dual problem solutions

Parameters
vtypestring, optional

Primal or Dual

solutioninteger, optional

Solution number to be returned (for the MILP solver)

pivotboolean, optional

When set to True, returns multiple solutions in columns as a pivot table

Returns
solutionpandas.DataFrame

Primal or dual solution table returned from the CAS action

Notes

  • If the Model.solve() method is used with frame=True parameter, the MILP solver returns multiple solutions. You can retreive different results by using the solution parameter.

Examples

>>> m.solve()
>>> print(m.get_solution('Primal'))
             var   lb             ub  value  solution
0       x[clock]  0.0  1.797693e+308    0.0       1.0
1          x[pc]  0.0  1.797693e+308    5.0       1.0
2   x[headphone]  0.0  1.797693e+308    2.0       1.0
3         x[mug]  0.0  1.797693e+308    0.0       1.0
4        x[book]  0.0  1.797693e+308    0.0       1.0
5         x[pen]  0.0  1.797693e+308    1.0       1.0
6       x[clock]  0.0  1.797693e+308    0.0       2.0
7          x[pc]  0.0  1.797693e+308    5.0       2.0
8   x[headphone]  0.0  1.797693e+308    2.0       2.0
9         x[mug]  0.0  1.797693e+308    0.0       2.0
10       x[book]  0.0  1.797693e+308    0.0       2.0
11        x[pen]  0.0  1.797693e+308    0.0       2.0
12      x[clock]  0.0  1.797693e+308    1.0       3.0
13         x[pc]  0.0  1.797693e+308    4.0       3.0
...
>>> print(m.get_solution('Primal', solution=2))
             var   lb             ub  value  solution
6       x[clock]  0.0  1.797693e+308    0.0       2.0
7          x[pc]  0.0  1.797693e+308    5.0       2.0
8   x[headphone]  0.0  1.797693e+308    2.0       2.0
9         x[mug]  0.0  1.797693e+308    0.0       2.0
10       x[book]  0.0  1.797693e+308    0.0       2.0
11        x[pen]  0.0  1.797693e+308    0.0       2.0
>>> print(m.get_solution(pivot=True))
solution      1.0  2.0  3.0  4.0  5.0
var
x[book]       0.0  0.0  0.0  1.0  0.0
x[clock]      0.0  0.0  1.0  1.0  0.0
x[headphone]  2.0  2.0  1.0  1.0  0.0
x[mug]        0.0  0.0  0.0  1.0  0.0
x[pc]         5.0  5.0  4.0  1.0  0.0
x[pen]        1.0  0.0  0.0  1.0  0.0
>>> print(m.get_solution('Dual'))
                     con  value  solution
0             weight_con   20.0       1.0
1       limit_con[clock]    0.0       1.0
2          limit_con[pc]    5.0       1.0
3   limit_con[headphone]    2.0       1.0
4         limit_con[mug]    0.0       1.0
5        limit_con[book]    0.0       1.0
6         limit_con[pen]    1.0       1.0
7             weight_con   19.0       2.0
8       limit_con[clock]    0.0       2.0
9          limit_con[pc]    5.0       2.0
10  limit_con[headphone]    2.0       2.0
11        limit_con[mug]    0.0       2.0
12       limit_con[book]    0.0       2.0
13        limit_con[pen]    0.0       2.0
...
>>> print(m.get_solution('dual', pivot=True))
solution               1.0   2.0   3.0   4.0  5.0
con
limit_con[book]        0.0   0.0   0.0   1.0  0.0
limit_con[clock]       0.0   0.0   1.0   1.0  0.0
limit_con[headphone]   2.0   2.0   1.0   1.0  0.0
limit_con[mug]         0.0   0.0   0.0   1.0  0.0
limit_con[pc]          5.0   5.0   4.0   1.0  0.0
limit_con[pen]         1.0   0.0   0.0   1.0  0.0
weight_con            20.0  19.0  20.0  19.0  0.0