How to Assign a Value to a Decision Variable? + How to Constrain for a Subset of Variables
回答済みenterSoC = [0.1, 0.2, 0.3]
m.addConstrs(SoC[0, b] == enterSoC[b] for b in range(noEV))
# constrain values of SoC[i+1] to SoC[i]+increment. must be done w add constraint
updatedSoC = m.addConstrs((SoC[count + 1, b] == SoC[count, b] for count in range(noPeriods) for b in range(noEV)),name="updatedSoC")

Why isn't SoC[0,0]+SoC[1,0] = 0.1 when it seems like SoC[0,1] was successfully assigned in initial value of 0.1 in the model?
Also, how do I rewrite a constraint so that it considers a subset of variables at each time? I want my binary decision variable schedule[i,j] to be optimised for each j by minimising the sum of their charging costs, but i get the following result.

How should I constrain my schedule binary variable?
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi,
Why isn't SoC[0,0]+SoC[1,0] = 0.1 when it seems like SoC[0,1] was successfully assigned in initial value of 0.1 in the model?
You set SoC[0,0] = 0.1.
Then, you set SoC[0,0] = SoC[1,0]. This implies that also SoC[1,0] = 0.1, so the sum is of course 0.2.In the definition of your constraints it seems you forgot to add the "increment" in the updatedSoC constraints.
I am not sure what exactly you want to model with your schedule-variables.
If you want to know how to write constraints with sums of variables, then you should consider our documentation, tutorials, and examples, e.g.:- Python example using sums of variables
- Gurobi Python API documentation
- Tutorial on the Gurobi Python API, and other videos in our YouTube channel
Best regards,
Mario0
投稿コメントは受け付けていません。
コメント
2件のコメント