Save the data from a solver output to a list in Python

Viewed 77

In python when you run a solver, it displays some details along with the solutions.

For example, I used a solver called IPOPT using following code

solver = SolverFactory('ipopt')
solver.solve(model, tee=True)

and, I got the following output from a solver:

This is Ipopt version 3.11.1, running with linear solver mumps.

Number of nonzeros in equality constraint Jacobian...:        6
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        3

Total number of variables............................:        4
                     variables with only lower bounds:        2
                variables with lower and upper bounds:        2
                     variables with only upper bounds:        0
Total number of equality constraints.................:        2
Total number of inequality constraints...............:        0


iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0 2.0402000e+000 1.35e-002 1.00e+000  -1.0 0.00e+000    -  0.00e+000 0.00e+000   0
   1 2.2708093e+000 1.01e-001 1.38e-001  -1.0 1.72e+000    -  1.00e+000 1.00e+000f  1
   2 2.1698603e+000 2.96e-002 3.73e-002  -1.0 2.85e+000    -  1.00e+000 1.00e+000h  1
   3 2.0024980e+000 2.74e-001 4.00e-002  -2.5 4.47e+000    -  9.79e-001 9.85e-001h  1
   4 2.0056830e+000 1.35e-004 1.30e-004  -2.5 1.66e-001    -  1.00e+000 1.00e+000h  1
   5 2.0002989e+000 3.63e-006 3.17e-005  -3.8 2.68e-003    -  1.00e+000 1.00e+000h  1
   6 2.0000036e+000 1.09e-008 1.18e-007  -5.7 1.47e-004    -  1.00e+000 1.00e+000h  1
   7 2.0000000e+000 1.69e-012 1.73e-011  -8.6 1.84e-006    -  1.00e+000 1.00e+000h  1

And now from the display, I want to save some information, for example, columns from the above table into a list. For instance, from the table, I want two lists from columns "iter" and "objective".

So, is it possible to save those information? Can someone help me to do it?

Thank you very much in advance.

0 Answers
Related