model succeeds when equality constraint is replaced by two equivalent inequality constraints

334 views
Skip to first unread message

Michel Jadoul

unread,
Jan 8, 2018, 8:47:50 AM1/8/18
to Pyomo Forum

Hello,

Below is:

- a code extract where equality constraints (grey, commented out)  have been replaced 
              by equivalent inequality constraints (black)
- the error message I get, when only the equalities are used

With the inequalities, the model using these constraints is successfully solved (with excellent precision).
With equalities if fails totally, not even attempting a solution, just keeping the initialization values.

This does not occur for all models, only some examples cause this failure.

Would you have some suggestions to understand the reason of this problem and to find a  good way to solve it.
My concern in not about the code below which works well, but without me knowing exactly why.
My concern is more about trying to totally avoid this problem later since it might not always be obvious to find a workaround.

Thanks,

Michel 



Error message

WARNING: Loading a SolverResults object with a warning status into model=unknown;
	message from solver=Too few degrees of freedom (rethrown)!
Solver returned :  warning



Sample code  (fails if equality constraints replace inequalities)

class balanceBox():
def __init__(self, *args):
self.ports = []
self.model = Block()
self.model.ports = Block()
for port in args:
self.substances = port.material.composition.substances
self.ports.append(port)
setattr(self.model.ports, port.material.materialName, port)

def chemicalBalance(self):
self.model.chemicalBalance = Block()
for atom in self.substances.atoms:
atomBalance = sum([p.material.element(atom)*p.sign for p in self.ports])
setattr(self.model.chemicalBalance, "chemicalBalance1_" + atom, Constraint(expr=atomBalance>=0))
setattr(self.model.chemicalBalance, "chemicalBalance2_" + atom, Constraint(expr=atomBalance<=0))
# setattr(self.model.chemicalBalance, "chemicalBalance_" + atom, Constraint(expr=atomBalance==0))
return self

def heatBalance(self):
heatBalance = sum([p.material.hM(p.material.T) * p.material.tons * p.sign for p in self.ports])
setattr(self.model, "heatBalance1", Constraint(expr=heatBalance>=0))
setattr(self.model, "heatBalance2", Constraint(expr=heatBalance<=0))
# setattr(self.model, "heatBalance", Constraint(expr=heatBalance==0))
return self

Michael Bynum

unread,
Jan 9, 2018, 10:41:06 AM1/9/18
to Pyomo Forum
Did you look at the ipopt output? I suspect you are having numerical issues. Ipopt is a nonlinear solver, and the way your write your constraints can drastically affect the computational difficulty of the problem. For example, 

y = x

is a much nicer constraint than 

1 = y/x

even though the two are mathematically equivalent. I would not blindly replace all equality constraints with inequality constraints. The behavior of ipopt is difficult to predict with these types of problems. Depending on the ipopt output (whether or not you are actually having numerical issues), you may need to reformulate your problem (e.g., rescale).

Michael

Michel Jadoul

unread,
Jan 10, 2018, 2:07:05 AM1/10/18
to pyomo...@googlegroups.com
Below is the message received from Ipopt.

The  "Too few degrees of freedom" message suggests to me a simple counting of variables and equality constraints.
It looks like Ipopt doesn't even attempt to solve the problem: only the initial values are found in the variables after the attempt to solve.
The same problem works perfectly well when each equality is replaced by two inequalities.
I don't know how Ipopt works, but I guess that this error occurs in a preliminary stage before numerics goes on.

One more test: I just added a few dummy variables to the model, and this did not change the result.
This suggest that it is not a simple count of variables and constraints which is involved.
It is "really" degrees of freedom that are involved.
I guess that numerical problem can pop up there.



message received from Ipopt

Exception of type: TOO_FEW_DOF in file "../../../../Ipopt/src/Interfaces/IpIpoptApplication.cpp" at line 860:
 Exception message: status != TOO_FEW_DEGREES_OF_FREEDOM evaluated false: Too few degrees of freedom (rethrown)!

EXIT: Problem has too few degrees of freedom.
WARNING: Loading a SolverResults object with a warning status into model=unknown;
	message from solver=Too few degrees of freedom (rethrown)!
Solver returned :  warning

Artem B

unread,
Jun 30, 2018, 4:28:42 PM6/30/18
to Pyomo Forum
WOW! I found your comment extremely useful! I tried to implement non-anticipative constraints for a stochastic programme. This requires quite many equality constraints. For some instances, it worked as expected, but then I just constantly get this error. Once I did inequality constraints, the problem disappeared. 

Thx! 

понедельник, 8 января 2018 г., 14:47:50 UTC+1 пользователь Michel Jadoul написал:
Reply all
Reply to author
Forward
0 new messages