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