I try add a constraint expressions to a python/pyomo model: the code I tried is this:
for r_k in VAR1:
for p_v in VAR2:
for b_n in VAR3:
IF mix[b_n][p_v]() >= 0:
model.cons.add(model.func2[r_k,b_n,p_v]*q1[b_n][p_v] - model.func1[r_k,b_n,p_v] ==0)
If I leave the IF
loop away it runs fine. The code above produces a Syntax error. Only downside is it creates 1000s of extra mathematically trivial constraints that are not needed.
"mix" is only a sparsely populated "binary" dictionary (i.e. mostly zeros, a few ones in between). A constraint is only needed where there is a "1". It seems there is an issue with evaluating/calling the dictionary values within the for loops. Any idea how to resolve this would be much appreciated. Thanks.
Aucun commentaire:
Enregistrer un commentaire