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
-
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
Please sign in to leave a comment.
Comments
1 comment