'Python : Pyomo: problem contrainst 'Cannot convert non-constant expression to bool."
I have a problem on the following form:
**model.obj= Objective(
expr= sum([ cost_fonction( model.Q[((i1,j1),t)], for (i1,j1) in Routes_reel for t in time]) ,sense=minimize)**
I would like add a conditionnal constrainst as like : model.reservoir_SM= Var(model.months,domain=NonNegativeReals,doc="Optimized stocks") model.constraint_Saint_Michel= ConstraintList( )
for t in time:
if t<6:
model.constraint_Saint_Michel.add(
model.reservoir_SM[t] == 0
)
elif t==6:
model.constraint_Saint_Michel.add(
model.reservoir_SM[t] == Initial_Stock
)
else :
model.constraint_Saint_Michel.add(
model.reservoir_SM[t] == model.reservoir_SM[t - 1] -np.maximum(0,(sum([model.Q[((i,j),t)] for (i,j) in Routes_SMA ]) - Vol_prelevable[t-1]))
)
But i receive this error message : Cannot convert non-constant expression to bool. This error is usually caused by using an expression in a boolean context such as an if statement. For example, m.x = Var() if m.x <= 0: ... would cause this exception.
I try to force by using model.Q[((i,j),t)].value. The model solves but the stock incrementation does not work correctly Do you have any idea ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
