1.3 Alternative Formulations:

1.3 Alternative Formulations:#

Consider the following problem with ini- tial values x=5, y=5.

\[min_{x,y} f(x,y) = (x-1.01)^{2} + y^{2}\]
\[s.t \;\;\;\; \frac{x-1}{y} = 1\]

Note that the solution to this problem is \(x=1.005\) and \(y=0.005\). There are several ways that the problem above can be reformulated. Some examples are shown below. Which ones do you expect to be better? Why? Note the number of iterations and quality of solutions. What can you learn about problem formulation from these examples?

(a)

\[min_{x,y} f(x,y) = (x-1.01)^{2} + y^{2}\]
\[s.t \;\;\;\; \frac{x-1}{y} = 1\]
import pyomo.environ as pyo

model = pyo.ConcreteModel()

model.x = pyo.Var(initialize=5.0)
model.y = pyo.Var(initialize=5.0)

def obj_rule(m):
    return (m.x-1.01)**2 + m.y**2
model.obj = pyo.Objective(rule=obj_rule)

def con_rule(m):
    return (m.x - 1.0) / m.y == 1.0
model.con = pyo.Constraint(rule=con_rule)

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

print(pyo.value(model.x))
print(pyo.value(model.y))
Ipopt 3.13.2: 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt

This version of Ipopt was compiled from source code available at
    https://github.com/IDAES/Ipopt as part of the Institute for the Design of
    Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE
    Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.

This version of Ipopt was compiled using HSL, a collection of Fortran codes
    for large-scale scientific computation.  All technical papers, sales and
    publicity material resulting from use of the HSL codes within IPOPT must
    contain the following acknowledgement:
        HSL, a collection of Fortran codes for large-scale scientific
        computation. See http://www.hsl.rl.ac.uk.
******************************************************************************

This is Ipopt version 3.13.2, running with linear solver ma27.

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

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

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  4.0920100e+01 2.00e-01 9.99e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  5.9762286e-01 2.27e+00 1.52e+01  -1.0 5.48e+00    -  1.00e+00 1.00e+00f  1
   2  1.9787064e-01 2.97e+00 2.40e+01  -1.0 8.02e+00    -  1.00e+00 1.25e-01f  4
   3  6.5241867e+01 2.82e+00 2.98e+01  -1.0 6.68e+00    -  1.00e+00 1.00e+00h  1
   4  9.5583161e+01 1.54e+00 2.31e+01  -1.0 4.70e+00    -  1.00e+00 1.00e+00h  1
   5  1.8959813e+02 4.39e-01 2.77e+01  -1.0 1.14e+01    -  1.00e+00 1.00e+00h  1
   6  2.2666991e+01 2.02e+00 1.24e+01  -1.0 1.54e+01    -  1.00e+00 1.00e+00f  1
   7  3.7976779e+01 9.23e-01 1.21e+01  -1.0 3.88e+00    -  1.00e+00 1.00e+00h  1
   8  2.0620942e+01 6.84e-02 1.64e+01  -1.0 5.65e+00    -  1.00e+00 5.00e-01f  2
   9  9.8180623e-02 8.02e-01 1.24e+02  -1.0 3.63e+00    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  2.3622224e+03 7.97e-01 1.42e+02  -1.0 4.73e+01    -  1.00e+00 1.00e+00h  1
  11  3.6759509e+03 1.64e-01 2.37e+02  -1.0 3.63e+01    -  1.00e+00 1.00e+00h  1
  12  7.0378669e+01 6.52e-01 5.20e+02  -1.0 4.32e+01    -  1.00e+00 1.00e+00f  1
  13  2.5142436e+04 6.17e-01 5.94e+02  -1.0 1.40e+02    -  1.00e+00 1.00e+00h  1
  14  2.6505724e+04 3.06e-01 1.02e+03  -1.7 7.26e+01    -  1.00e+00 1.00e+00h  1
  15  3.7335004e+03 2.99e-01 5.43e+02  -1.7 9.42e+01    -  1.00e+00 1.00e+00f  1
  16  3.5127061e+03 7.10e-02 3.16e+02  -1.7 9.60e+00    -  1.00e+00 1.00e+00f  1
  17  3.2134630e+01 4.96e-01 1.50e+03  -1.7 4.08e+01    -  1.00e+00 1.00e+00f  1
  18  1.0915648e+05 4.88e-01 1.76e+03  -1.7 2.89e+02    -  1.00e+00 1.00e+00h  1
  19  1.1667899e+05 1.53e-01 1.76e+03  -1.7 1.07e+02    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  3.7449172e+03 4.78e-01 3.37e+03  -1.7 2.30e+02    -  1.00e+00 1.00e+00f  1
  21  4.9463570e+05 4.36e-01 3.65e+03  -1.7 5.58e+02    -  1.00e+00 1.00e+00h  1
  22  3.6988313e+05 2.75e-01 5.13e+03  -1.7 2.37e+02    -  1.00e+00 1.00e+00f  1
  23  8.9309627e+04 1.73e-01 1.92e+03  -1.7 2.88e+02    -  1.00e+00 1.00e+00f  1
  24  4.0590995e+04 3.57e-02 4.55e+02  -1.7 1.71e+02    -  1.00e+00 5.00e-01f  2
  25  1.8907970e+01 5.44e+00 1.24e+05  -1.7 1.46e+02    -  1.00e+00 1.00e+00f  1
  26  1.4670968e+01 5.44e+00 1.24e+05  -1.7 1.63e+04    -  1.00e+00 4.88e-04f 12
  27  2.3540992e+01 5.44e+00 1.24e+05  -1.7 1.63e+04    -  1.00e+00 6.10e-05h 15
  28  2.8758563e+01 5.44e+00 1.24e+05  -1.7 1.63e+04    -  1.00e+00 3.05e-05h 16
  29  3.1562971e+01 5.44e+00 1.24e+05  -1.7 1.63e+04    -  1.00e+00 1.53e-05h 17
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  30  2.8032208e+08 5.44e+00 1.32e+05  -1.7 1.63e+04    -  1.00e+00 1.00e+00s 22
  31  2.9975467e+08 2.93e+00 7.23e+04  -1.7 4.29e+03    -  1.00e+00 1.00e+00s 22
  32  5.0495436e+08 1.67e+00 5.58e+04  -1.7 1.07e+04    -  1.00e+00 1.00e+00s 22
  33r 5.0495436e+08 1.67e+00 9.99e+02   0.2 0.00e+00    -  0.00e+00 0.00e+00R  1
  34r 5.1181880e+08 1.63e+00 3.35e-03   0.2 5.20e+02    -  1.00e+00 1.00e+00f  1
  35r 5.1039583e+08 1.63e+00 4.77e-02  -1.9 4.51e+01    -  9.96e-01 9.97e-01h  1
  36r 4.9195690e+08 1.35e+00 4.46e-02  -4.2 4.64e+03    -  1.00e+00 1.00e+00f  1
  37r 4.9179264e+08 1.33e+00 4.40e-02  -4.2 4.40e+02  -4.0 1.00e+00 1.00e+00h  1
  38r 4.8990727e+08 1.27e+00 4.25e-02  -4.2 1.27e+03  -4.5 1.00e+00 1.00e+00f  1
  39r 4.7382990e+08 1.10e+00 3.97e-02  -4.2 3.57e+03  -5.0 1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  40r 3.7628486e+08 4.51e-01 4.52e-02  -4.2 1.15e+04  -5.4 1.00e+00 1.00e+00f  1
  41  1.0535429e+08 1.06e-01 2.99e+04  -1.7 2.02e+04    -  1.00e+00 5.00e-01f  2
  42  5.0568867e+05 9.22e-01 1.26e+05  -2.5 7.56e+03    -  1.00e+00 1.00e+00f  1
  43  3.3347854e+09 9.11e-01 1.34e+05  -2.5 5.68e+04    -  1.00e+00 1.00e+00h  1
  44  5.8840295e+09 1.09e-01 2.61e+05  -2.5 5.18e+04    -  1.00e+00 1.00e+00h  1
  45  4.1193681e+07 7.84e-01 1.00e+06  -2.5 5.56e+04    -  1.00e+00 1.00e+00f  1
  46  1.4749624e+11 7.71e-01 1.15e+06  -2.5 3.68e+05    -  1.00e+00 1.00e+00h  1
  47  2.1551056e+11 2.01e-01 1.98e+06  -2.5 2.71e+05    -  1.00e+00 1.00e+00h  1
  48  6.9492790e+09 5.76e-01 3.13e+06  -2.5 3.24e+05    -  1.00e+00 1.00e+00f  1
  49  6.6118466e+11 5.16e-01 3.38e+06  -2.5 6.55e+05    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  50  4.9827616e+11 4.07e-01 6.68e+06  -2.5 3.23e+05    -  1.00e+00 1.00e+00f  1
  51  2.5070264e+11 5.12e-02 9.66e+05  -2.5 2.31e+05    -  1.00e+00 1.00e+00f  1
  52  6.1554282e+10 1.85e-03 3.55e+05  -2.5 3.76e+05    -  1.00e+00 5.00e-01f  2
  53  5.2610595e+04 1.97e+00 5.11e+06  -2.5 1.76e+05    -  1.00e+00 1.00e+00f  1
  54  4.4943971e+05 1.97e+00 5.11e+06  -2.5 2.59e+06    -  1.00e+00 1.22e-04h 14
  55r 4.4943971e+05 1.97e+00 9.99e+02   0.3 0.00e+00    -  0.00e+00 4.77e-07R 22
  56r 9.1590793e+05 9.92e-01 3.10e+02   0.3 6.91e+02    -  1.00e+00 6.90e-01f  1
  57r 2.2644173e+05 9.86e-01 1.97e+01   0.3 4.81e+02    -  1.09e-01 1.00e+00h  1
  58  1.1167372e+05 1.33e-02 1.43e+03  -2.5 4.82e+02    -  1.00e+00 5.00e-01f  2
  59  2.4761840e+01 6.53e-01 4.64e+04  -2.5 2.36e+02    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  60  8.0631714e+05 6.53e-01 4.69e+04  -2.5 1.35e+04    -  1.00e+00 6.25e-02h  5
  61  2.0421100e+08 6.11e-01 5.31e+04  -2.5 1.25e+04    -  1.00e+00 1.00e+00h  1
  62  2.0547303e+08 3.37e-01 9.62e+04  -2.5 6.30e+03    -  1.00e+00 1.00e+00h  1
  63  3.8551062e+07 2.46e-01 3.78e+04  -2.5 7.74e+03    -  1.00e+00 1.00e+00f  1
  64  9.8551263e+06 4.34e-01 1.01e+05  -2.5 3.16e+03    -  1.00e+00 1.00e+00f  1
  65  7.0643113e+07 2.83e-01 7.29e+04  -2.5 4.05e+03    -  1.00e+00 1.00e+00h  1
  66  1.8786849e+07 1.58e-01 2.41e+04  -2.5 3.84e+03    -  1.00e+00 1.00e+00f  1
  67  7.4748196e+06 2.41e-02 4.91e+03  -2.5 2.72e+03    -  1.00e+00 5.00e-01f  2
  68  1.8818509e+06 2.10e-04 2.01e+03  -2.5 1.97e+03    -  1.00e+00 5.00e-01f  2
  69  2.2872308e-02 1.84e+00 6.28e+05  -2.5 9.70e+02    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  70r 2.2872308e-02 1.84e+00 9.99e+02   0.3 0.00e+00    -  0.00e+00 4.77e-07R 22
  71r 4.4351946e-02 8.81e-01 1.76e+01   0.3 1.81e+03    -  1.00e+00 1.01e-03f  1
  72  1.7776427e-02 9.56e-02 6.09e-01  -2.5 2.31e-01    -  1.00e+00 5.00e-01h  2
  73  3.1709471e-04 4.13e-01 1.65e+00  -2.5 9.34e-02    -  1.00e+00 1.00e+00h  1
  74  7.3004326e-03 3.89e-01 1.61e+00  -2.5 2.37e-01    -  1.00e+00 2.50e-01h  3
  75  1.6285131e-02 3.21e-01 1.35e+00  -2.5 1.32e-01    -  1.00e+00 2.50e-01h  3
  76  2.6559704e-02 3.14e-02 3.18e-01  -2.5 4.34e-02    -  1.00e+00 1.00e+00h  1
  77  2.0352617e-05 1.52e+00 1.02e+01  -2.5 1.19e-01    -  1.00e+00 1.00e+00h  1
  78  6.3246080e-05 1.51e+00 1.01e+01  -2.5 1.06e+00    -  1.00e+00 3.91e-03h  9
  79  9.8814789e-05 1.41e+00 9.41e+00  -2.5 1.04e+00    -  1.00e+00 1.95e-03h 10
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  80  9.9989710e-05 1.40e+00 9.34e+00  -2.5 9.66e-01    -  1.00e+00 6.10e-05h 15
  81  1.0975944e+00 1.40e+00 1.01e+01  -2.5 9.58e-01    -  1.00e+00 1.00e+00s 22
  82  1.1421887e+00 4.64e-01 4.82e+00  -2.5 1.98e-01    -  1.00e+00 1.00e+00s 22
  83  1.2756204e-01 4.39e-01 2.00e+00  -2.5 7.03e-01    -  1.00e+00 1.00e+00s 22
  84r 1.2756204e-01 4.39e-01 9.99e+02  -0.4 0.00e+00    -  0.00e+00 0.00e+00R  1
  85r 1.4318780e-01 9.50e-02 2.05e+01  -0.4 4.30e+02    -  1.00e+00 1.01e-03f  1
  86r 1.2257823e-01 1.78e-03 2.63e-02  -1.1 3.20e-02    -  1.00e+00 9.90e-01f  1
  87  5.4518642e-05 8.47e-02 4.97e-01  -2.5 2.48e-01    -  1.00e+00 1.00e+00f  1
  88  6.5899060e-05 3.67e-02 2.08e-01  -2.5 1.17e-02    -  1.00e+00 2.50e-01h  3
  89  5.7483881e-05 9.65e-03 5.44e-02  -2.5 8.75e-04    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  90  5.0200713e-05 3.49e-03 1.84e-02  -2.5 1.78e-03    -  1.00e+00 1.00e+00h  1
  91  5.0003939e-05 6.90e-05 3.59e-04  -3.8 1.15e-04    -  1.00e+00 1.00e+00h  1
  92  5.0000011e-05 2.16e-07 1.02e-06  -5.7 1.60e-05    -  1.00e+00 1.00e+00h  1
  93  5.0000000e-05 2.35e-13 1.03e-12  -8.6 6.18e-09    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 93

                                   (scaled)                 (unscaled)
Objective...............:   5.0000000000011841e-05    5.0000000000011841e-05
Dual infeasibility......:   1.0301603320383990e-12    1.0301603320383990e-12
Constraint violation....:   2.3503421431314564e-13    2.3503421431314564e-13
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   1.0301603320383990e-12    1.0301603320383990e-12


Number of objective function evaluations             = 321
Number of objective gradient evaluations             = 86
Number of equality constraint evaluations            = 321
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 98
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 93
Total CPU secs in IPOPT (w/o function evaluations)   =      0.057
Total CPU secs in NLP function evaluations           =      0.004

EXIT: Optimal Solution Found.

1.0049999999999448
0.004999999999946002

(b)

\[min_{x,y} f(x,y) = (x-1.01)^{2} + y^{2}\]
\[s.t \;\;\;\; \frac{x}{y + 1} = 1\]
import pyomo.environ as pyo

model = pyo.ConcreteModel()

model.x = pyo.Var(initialize=5.0)
model.y = pyo.Var(initialize=5.0)

def obj_rule(m):
    return (m.x-1.01)**2 + m.y**2
model.obj = pyo.Objective(rule=obj_rule)

def con_rule(m):
    return m.x / (m.y + 1.0) == 1.0
model.con = pyo.Constraint(rule=con_rule)

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

print(pyo.value(model.x))
print(pyo.value(model.y))
Ipopt 3.13.2: 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt

This version of Ipopt was compiled from source code available at
    https://github.com/IDAES/Ipopt as part of the Institute for the Design of
    Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE
    Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.

This version of Ipopt was compiled using HSL, a collection of Fortran codes
    for large-scale scientific computation.  All technical papers, sales and
    publicity material resulting from use of the HSL codes within IPOPT must
    contain the following acknowledgement:
        HSL, a collection of Fortran codes for large-scale scientific
        computation. See http://www.hsl.rl.ac.uk.
******************************************************************************

This is Ipopt version 3.13.2, running with linear solver ma27.

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

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

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  4.0920100e+01 1.67e-01 9.83e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  4.0023722e-01 1.49e+00 2.82e+01  -1.0 5.39e+00    -  1.00e+00 1.00e+00f  1
   2  1.0494629e+01 1.04e+00 2.24e+01  -1.0 2.58e+00    -  1.00e+00 1.00e+00h  1
   3  5.4394796e+00 1.78e-01 8.48e+00  -1.0 1.23e+00    -  1.00e+00 1.00e+00f  1
   4  1.0538196e-01 1.52e-01 3.90e+00  -1.0 1.75e+00    -  1.00e+00 1.00e+00f  1
   5  4.6918851e-02 2.17e-02 1.20e+00  -1.0 1.63e-01    -  1.00e+00 1.00e+00h  1
   6  1.3071752e-04 2.88e-03 1.19e-01  -1.0 1.62e-01    -  1.00e+00 1.00e+00h  1
   7  4.9833353e-05 1.79e-05 1.02e-03  -2.5 6.25e-03    -  1.00e+00 1.00e+00h  1
   8  5.0000013e-05 1.28e-09 6.30e-08  -5.7 9.00e-05    -  1.00e+00 1.00e+00h  1
   9  5.0000000e-05 2.22e-16 4.77e-16  -8.6 4.58e-09    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 9

                                   (scaled)                 (unscaled)
Objective...............:   5.0000000000001568e-05    5.0000000000001568e-05
Dual infeasibility......:   4.7704895589362195e-16    4.7704895589362195e-16
Constraint violation....:   2.2204460492503131e-16    2.2204460492503131e-16
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   4.7704895589362195e-16    4.7704895589362195e-16


Number of objective function evaluations             = 10
Number of objective gradient evaluations             = 10
Number of equality constraint evaluations            = 10
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 10
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 9
Total CPU secs in IPOPT (w/o function evaluations)   =      0.005
Total CPU secs in NLP function evaluations           =      0.000

EXIT: Optimal Solution Found.

1.005
0.005000000000000042

(c)

\[min_{x,y} f(x,y) = (x-1.01)^{2} + y^{2}\]
\[s.t \;\;\;\; y = x - 1\]
import pyomo.environ as pyo

model = pyo.ConcreteModel()

model.x = pyo.Var(initialize=5.0)
model.y = pyo.Var(initialize=5.0)

def obj_rule(m):
    return (m.x-1.01)**2 + m.y**2
model.obj = pyo.Objective(rule=obj_rule)

def con_rule(m):
    return m.y == m.x - 1.0
model.con = pyo.Constraint(rule=con_rule)

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

print(pyo.value(model.x))
print(pyo.value(model.y))
Ipopt 3.13.2: 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt

This version of Ipopt was compiled from source code available at
    https://github.com/IDAES/Ipopt as part of the Institute for the Design of
    Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE
    Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.

This version of Ipopt was compiled using HSL, a collection of Fortran codes
    for large-scale scientific computation.  All technical papers, sales and
    publicity material resulting from use of the HSL codes within IPOPT must
    contain the following acknowledgement:
        HSL, a collection of Fortran codes for large-scale scientific
        computation. See http://www.hsl.rl.ac.uk.
******************************************************************************

This is Ipopt version 3.13.2, running with linear solver ma27.

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

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

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  4.0920100e+01 1.00e+00 8.99e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  5.0000000e-05 0.00e+00 4.44e-16  -1.0 5.00e+00    -  1.00e+00 1.00e+00f  1

Number of Iterations....: 1

                                   (scaled)                 (unscaled)
Objective...............:   5.0000000000000090e-05    5.0000000000000090e-05
Dual infeasibility......:   4.4408920985006262e-16    4.4408920985006262e-16
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   4.4408920985006262e-16    4.4408920985006262e-16


Number of objective function evaluations             = 2
Number of objective gradient evaluations             = 2
Number of equality constraint evaluations            = 2
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 2
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 1
Total CPU secs in IPOPT (w/o function evaluations)   =      0.001
Total CPU secs in NLP function evaluations           =      0.000

EXIT: Optimal Solution Found.

1.005
0.004999999999999893

(d) Bounds and initialization can be very helpful when solving nonlinear optimization problems. Starting with the code below, resolve the original problem, but add bounds, \(y \geq 0\). Note the number of iterations and quality of solution, and compare with what you found in 1.2 (a).

import pyomo.environ as pyo

model = pyo.ConcreteModel()

model.x = pyo.Var(initialize=5.0)
model.y = pyo.Var(initialize=5.0, bounds=(0,None))

def obj_rule(m):
    return (m.x-1.01)**2 + m.y**2
model.obj = pyo.Objective(rule=obj_rule)

def con_rule(m):
    return (m.x - 1.0) / m.y == 1.0
model.con = pyo.Constraint(rule=con_rule)

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

print(pyo.value(model.x))
print(pyo.value(model.y))
Ipopt 3.13.2: 

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt

This version of Ipopt was compiled from source code available at
    https://github.com/IDAES/Ipopt as part of the Institute for the Design of
    Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE
    Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.

This version of Ipopt was compiled using HSL, a collection of Fortran codes
    for large-scale scientific computation.  All technical papers, sales and
    publicity material resulting from use of the HSL codes within IPOPT must
    contain the following acknowledgement:
        HSL, a collection of Fortran codes for large-scale scientific
        computation. See http://www.hsl.rl.ac.uk.
******************************************************************************

This is Ipopt version 3.13.2, running with linear solver ma27.

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

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

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  4.0920100e+01 2.00e-01 9.38e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  9.7049410e-01 1.89e+01 2.29e+03  -1.0 5.19e+00    -  1.00e+00 9.54e-01f  1
   2  2.8303563e+03 1.85e+01 2.25e+03  -1.0 5.21e+01    -  1.88e-02 1.00e+00h  1
   3  2.9704435e+03 9.12e+00 1.14e+03  -1.0 2.64e+00    -  1.00e+00 1.00e+00h  1
   4  2.5293245e+03 4.09e+00 5.51e+02  -1.0 4.89e+00    -  8.94e-01 1.00e+00f  1
   5  1.7547126e+03 1.52e+00 2.52e+02  -1.0 1.04e+01    -  1.00e+00 1.00e+00f  1
   6  6.8047428e+02 1.49e-01 8.49e+01  -1.0 1.93e+01    -  1.00e+00 1.00e+00f  1
   7  7.4721920e+00 8.01e-01 2.32e+02  -1.0 1.91e+01    -  1.00e+00 1.00e+00f  1
   8  8.1969347e+03 7.77e-01 2.62e+02  -1.0 8.57e+01    -  3.37e-02 1.00e+00h  1
   9  1.1605265e+04 2.36e-01 4.89e+02  -1.0 6.40e+01    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  5.5411085e+02 5.19e-01 5.83e+02  -1.0 7.36e+01    -  1.00e+00 1.00e+00f  1
  11  1.7377623e+04 4.22e-01 5.65e+02  -1.0 9.29e+01    -  3.00e-01 1.00e+00h  1
  12  1.1573362e+04 1.25e-01 1.63e+02  -1.0 6.64e+01    -  1.00e+00 5.00e-01f  2
  13  3.3128549e+03 8.55e-03 9.20e+01  -1.0 8.52e+01    -  1.00e+00 4.70e-01f  2
  14  7.1443870e-01 8.34e-01 1.80e+03  -1.0 4.11e+01    -  1.00e+00 9.85e-01f  1
  15  3.2462198e-05 4.75e-01 1.05e+03  -1.0 1.73e+02    -  1.00e+00 4.30e-03f  1
  16  9.8963008e-05 2.74e-01 8.52e+02  -1.0 1.41e+00    -  1.00e+00 4.23e-03h  1
  17  9.2105755e-05 2.40e-01 5.57e+02  -1.0 3.56e-04    -  1.00e+00 1.00e+00f  1
  18  7.9772743e-05 1.58e-01 3.60e+02  -1.0 7.13e-04    -  1.00e+00 1.00e+00h  1
  19  6.9741224e-05 6.86e-02 1.47e+02  -1.0 7.40e-04    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  4.9888137e-05 3.97e-02 6.88e+01  -1.0 2.39e-03    -  1.00e+00 1.00e+00h  1
  21  3.3950490e-04 3.02e-02 4.89e+01  -1.0 1.32e-02    -  1.00e+00 1.00e+00f  1
  22  3.7536170e-03 1.95e-02 3.11e+01  -1.0 3.12e-02    -  1.00e+00 1.00e+00h  1
  23  1.2981580e-02 8.58e-03 1.36e+01  -1.0 3.74e-02    -  1.00e+00 1.00e+00h  1
  24  3.4681398e-02 3.23e-03 5.01e+00  -1.0 5.13e-02    -  1.00e+00 1.00e+00h  1
  25  4.7179466e-02 4.50e-04 7.03e-01  -1.0 2.21e-02    -  1.00e+00 1.00e+00h  1
  26  1.7082443e-02 2.83e-04 3.55e-01  -1.7 6.13e-02    -  1.00e+00 1.00e+00f  1
  27  1.0216180e-02 7.79e-05 1.09e-01  -1.7 2.10e-02    -  1.00e+00 1.00e+00h  1
  28  3.1289054e-03 5.64e-05 3.27e-02  -2.5 3.21e-02    -  1.00e+00 1.00e+00h  1
  29  1.4987215e-03 2.18e-05 2.21e-02  -2.5 1.23e-02    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  30  3.8554063e-04 1.69e-05 4.50e-03  -3.8 1.40e-02    -  1.00e+00 1.00e+00h  1
  31  1.3832051e-04 9.18e-06 4.39e-03  -3.8 6.31e-03    -  1.00e+00 1.00e+00h  1
  32  8.9968997e-05 2.11e-06 9.99e-06  -3.8 2.18e-03    -  1.00e+00 1.00e+00h  1
  33  5.4301800e-05 9.79e-07 2.80e-03  -5.7 3.00e-03    -  1.00e+00 1.00e+00h  1
  34  5.0216846e-05 2.09e-07 1.11e-04  -5.7 1.14e-03    -  1.00e+00 1.00e+00h  1
  35  5.0020268e-05 9.37e-09 2.55e-05  -5.7 2.29e-04    -  1.00e+00 1.00e+00h  1
  36  5.0016425e-05 1.85e-11 1.06e-08  -5.7 1.00e-05    -  1.00e+00 1.00e+00h  1
  37  5.0000006e-05 3.39e-13 3.16e-06  -8.6 8.89e-05    -  1.00e+00 1.00e+00h  1
  38  5.0000000e-05 5.55e-15 4.02e-13  -8.6 1.58e-06    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 38

                                   (scaled)                 (unscaled)
Objective...............:   5.0000000031647193e-05    5.0000000031647193e-05
Dual infeasibility......:   4.0225288377992996e-13    4.0225288377992996e-13
Constraint violation....:   5.5511151231257827e-15    5.5511151231257827e-15
Complementarity.........:   2.5158913589264014e-09    2.5158913589264014e-09
Overall NLP error.......:   2.5158913589264014e-09    2.5158913589264014e-09


Number of objective function evaluations             = 44
Number of objective gradient evaluations             = 39
Number of equality constraint evaluations            = 44
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 39
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 38
Total CPU secs in IPOPT (w/o function evaluations)   =      0.013
Total CPU secs in NLP function evaluations           =      0.001

EXIT: Optimal Solution Found.

1.0050001257911454
0.005000125791145421