Can we change the linear expression's lines randomly in gurobi ??
Answered
lin_exp_2 = K * sum(
z_dual[i, l].x * model.getVarByName('z_' + str(i) + '_' + str(l)) for l in L for i in range(N + 1))
+ K * sum(r_dual[i, j].x * model.getVarByName('r_' + str(i) + '_' + str(j)) for j in range(N+1) for i in range(N+1))
If I use the expression above, the expression will not include the last line.
lin_exp_2 = K * sum(
z_dual[i, l].x * model.getVarByName('z_' + str(i) + '_' + str(l)) for l in L for i in range(N + 1)) + K * sum(r_dual[i, j].x * model.getVarByName('r_' + str(i) + '_' + str(j)) for j in range(N+1) for i in range(N+1))
The expression above is correct.
Why would that happen?
0
-
Official comment
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. -
It is quite hard to help here, because the snippets you provided are not reproducible.
I would guess that it some identation + editor issue which is not correctly displayed. You should try using a backslash when you want to write multi line expressions in Python.
lin_exp_2 = K * sum(
z_dual[i, l].x * model.getVarByName('z_' + str(i) + '_' + str(l)) for l in L for i in range(N + 1)) \
+ K * sum(r_dual[i, j].x * model.getVarByName('r_' + str(i) + '_' + str(j)) for j in range(N+1) for i in range(N+1))If this does not help, you can always use parentheses to make sure that the whole expression is used instead of putting it into 1 long line.
0
Post is closed for comments.
Comments
2 comments