Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.97k stars 506 forks source link

References to constraints cause duplicate constraints to go to solvers #1401

Open michaelbynum opened 4 years ago

michaelbynum commented 4 years ago

The following model should only have one constraint. However, the Ipopt log says that there are two constraints. There is a duplicate constraint due to the reference.

>>> import pyomo.environ as pe
>>> m = pe.ConcreteModel()
>>> m.x = pe.Var()
>>> m.y = pe.Var()
>>> m.obj = pe.Objective(expr=m.x**2 + m.y**2)
>>> m.c1 = pe.Constraint(expr=m.y >= pe.exp(m.x))
>>> m.c1_ref = pe.Reference(m.c1)
>>> opt = pe.SolverFactory('ipopt')
>>> res = opt.solve(m, tee=True)
Ipopt 3.12.9: linear_solver=mumps

******************************************************************************
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 is Ipopt version 3.12.9, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:        4
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.................:        0
Total number of inequality constraints...............:        2
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        2

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  6.0803678e-01 0.00e+00 2.57e-01  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  6.3884027e-01 0.00e+00 7.76e-04  -1.7 1.81e-02    -  1.00e+00 1.00e+00h  1
   2  6.0909833e-01 0.00e+00 1.48e-04  -3.8 2.25e-02    -  1.00e+00 1.00e+00f  1
   3  6.0804141e-01 0.00e+00 2.08e-07  -5.7 8.28e-04    -  1.00e+00 1.00e+00h  1
   4  6.0803678e-01 0.00e+00 3.86e-12  -8.6 3.58e-06    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 4

                                   (scaled)                 (unscaled)
Objective...............:   6.0803677849485571e-01    6.0803677849485571e-01
Dual infeasibility......:   3.8616887465536820e-12    3.8616887465536820e-12
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   2.5155363307369499e-09    2.5155363307369499e-09
Overall NLP error.......:   2.5155363307369499e-09    2.5155363307369499e-09

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

EXIT: Optimal Solution Found.
michaelbynum commented 4 years ago

Additionally, a reference to an active objective causes an error.

michaelbynum commented 4 years ago

A follow-on issue: If references to variables and constraints are are put on a block, and that block is passed to a function, I don't think it is possible to identify whether or not components are references. Is that True?