0

I would like to create a disjunction OR for each c in model.Cset. The code below somehow works, but it only takes the value of the last c in the for loop. The aim is to have a disjunction for each c: model.C2(c1), model.C2(c2),etc.

So, for each c, x[(p,c,m)] is forced to assume either the model.d1.c value or model.d2.c value for each m. I tried also by defining

model.C2 = pyo.ConstraintList() 

and then changing the last sentence as

model.C2.add( Disjunction(expr=[model.d1, model.d2] ) 

but it gives me the following error: ValueError: Constraint 'C2[1]' does not have a proper value. Found 'ScalarDisjunction' Expecting a tuple or relational expression. Examples: sum(model.costs) == model.income(0, model.price[item], 50) model.x is the variable model.Dparam is a parameter model.d1.c and model.d2.c are Constraint lists


for c in model.Cset :
    model.d1 = Disjunct()
    model.d1.c = Constraint(expr= sum(model.x[(p,c,m)] * model.Dparam[(p,c,m)] for m in list_m) 
                                == sum(model.Dparam[(p,c,m)] for m in list_m)
                               )
    model.d2 = Disjunct()
    model.d2.c = Constraint(expr= sum(model.x[(p,c,m)] * model.Dparam[(p,c,m)] for m in list_m) == 0)
        
    model.C2  = Disjunction(expr=[model.d1, model.d2])

0 Answers0