XiongPengNUS / rsome

Robust Stochastic Optimization Made Easy
GNU General Public License v3.0
282 stars 54 forks source link

invalid syntax error when using forall(random_set) in robust model #12

Closed AmalNammouchi closed 2 years ago

AmalNammouchi commented 2 years ago

I am trying to solve robust model using Gamma robusteness. However, when I define the constraint that is dependent on the randon variable using 'forall(random_Set) I keep getting syntax error even though in the guide it was used the same way. What am I missing??? I appreciate your help

def robust(r): """ The function robust implements the robust optimiztion model, given the budget of uncertainty r """

model = ro.Model('robust')
#decision variables
Pimp = model.dvar()             
Pexp = model.dvar()                
Bch = model.dvar(n)                
Bdis = model.dvar(n)
SoE = model.dvar(n)
b = model.dvar(1, 'B')
c = model.dvar(n, 'B')

#define the uncertain/random variable
Pprod = model.rvar(n)               

#Define the uncertainty set

Pprod_set = (abs(Pprod) <= 1, rso.norm(Pprod, 1) <= r)
model.min(PriceImp*Pimp - PriceEx * Pexp)

#Constraints
model.st((sum(Pprod) - sum(Pcons) - sum(Bch) + sum(Bdis) + Pimp - Pexp) == 0).forall(Pprod_set))   # constraint (1)

model.st(Pimp <= (1-b) * UB_x )   #constraint (2) x <= (1-b) * UB_x  ,y <= b * UB_y
model.st(Pexp <= b * UB_y )
model.st(Pimp>=0)
model.st(Pexp>=0)

other constraints

model.solve(grb, display=False) # disable solution message

return model.get(), Pimp.get(), Pexp.get()     # the optimal objective and solution
XiongPengNUS commented 2 years ago

Seems that the parentheses for that line of code do not match.