How to add equation containing decision variable into an array.
回答済みI got a problem to store the equation containing the decision variable into an array.
Here, This is my code and noted that y[j,k] is my binary decision variable.
Time_span = 16
Expo_noise_matrix = range(1,Time_span+1)
Times = range(1,Time_span+1)
for k in Times:
Expo_noise_matrix[k] = ((70*y[1,k]+60*y[2,k]+80*y[3,k])*(1-((-1+y[1,k]+y[2,k]+y[3,k])*0.2)))
The error showed this,
3 for k in Times: ----> 4 Expo_noise_matrix[k] = ((70*y[1,k]+60*y[2,k]+80*y[3,k])*(1-((-1+y[1,k]+y[2,k]+y[3,k])*0.2))) TypeError: 'range' object does not support item assignment
I need to store those decision variable equations in array to call and calculate the objective function next.
0
-
正式なコメント
This post is more than three 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. -
In your code \(\texttt{Expo_noise_matrix}\) is a range object and thus, you cannot assign values to it.
You should rather use a dictionary for \(\texttt{Expo_noise_matrix}\).
Time_span = 16
Expo_noise_matrix = {}
Times = range(1,Time_span+1)
for k in Times:
Expo_noise_matrix[k] = ((70*y[1,k]+60*y[2,k]+80*y[3,k])*(1-((-1+y[1,k]+y[2,k]+y[3,k])*0.2)))Best regards,
Jaromił0 -
Dear: Jaromił
It's work now, thank you :).
Best regards,
Thunwa.
0
投稿コメントは受け付けていません。
コメント
3件のコメント