How to handle constraints to the problem?
Awaiting user inputI have 2 questions for my post:
1. How to handle constraints to my problem?
2. Can I get values from gurobi variable in <class 'gurobi.tupledict'> and store them in list array?
The figure below is the result of running the program and shows the status code number equal to 4.
I want to minimize the objective function below, by finding an optimal value of genSupply variable.
obj = gp.quicksum(a+(b*genSupply[n])+(c*(genSupply[n]**2)) for n in period)
where a,b,c are constant numbers. genSupply[n] is the generator output at time n and is used when the status[t] variable is lower than a minimum value.
This is my constraints condition,
you can ignore other variables and focus on genSupply variable.
period = 10
initial = 80
status = [0,0,0,0,0,0,0,0,0,0]
for n in range(period):
if (status[n] <= min_soc):
model.addConstr((totSupply[n]==(((solar[n]-((totCon[n]+cl_load[n])/effInv)+genSupply[n])*effBatt)/Ebatt_total)*100),name='totSupply')
model.addConstr(diffCharge[n]==initial*(1-sdr)+totSupply[n])
model.addConstr((diffCharge[n]>=min_soc))
model.addConstr((diffCharge[n]<=max_soc))
model.addConstr((genSupply[n]>=min_gen),name='genSupply')
model.addConstr((genSupply[n]<=max_gen),name='genSupply')
status[n] == diffCharge[n]
else:
model.addConstr((totSupply[n]== (((solar[n]-((totCon[n]+cl_load[n])/effInv)+genSupply[n])*effBatt)/Ebatt_total)*100),name='totSupply')
model.addConstr(diffCharge[n]== status[n-1]*(1-sdr)+totSupply[n])
model.addConstr((diffCharge[n] >= min_soc))
model.addConstr((diffCharge[n] <= max_soc))
model.addConstr((genSupply[n]==0),name='genSupply')
status[n] == diffCharge[n]
If status[n] is more than a min_soc value, i want to assign genSupply[n] equal to 0. Then the system updates a value from diffCharge[n] (class of gurobi.tupledict) to status[n] (list array).
Thank you very much for any advice.
-
Hi,
It seems your status variable is a given list of constants, not a Gurobi variable, right?
What exactly are model variables and what is given input data?
It seems for example that diffCharge are model variables but then you state "status[n] == diffCharge[n]" which does not make sense for me. Could you clarify this?Additionally, if you have an infeasible model and do not know why, you could compute an IIS which is a subset of your constraints that form an infeasible system. This often helps to identify the issue.
In your case you cannot retrieve the variable values since there is no solution, but in general it works as described in this article.
Best regards,
Mario0
Please sign in to leave a comment.
Comments
1 comment