Display output 2D variable
回答済みHi,
I optimized a 6x8 Mvar.
How can i print this table?
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. -
Hi Joël,
Assuming \(\texttt{x}\) represents the matrix variables, you can use one of the approaches below to print the values of the MVar object in the current solution.
x = m.addMVar(shape=(6, 8), name="x")
# Approach 1: This prints a numpy array with the (i, j) element being the value of
# the decision variable x[i, j]
values = m.getAttr("X", m.getVars())
values = np.array(values).reshape((6, 8))
# Approach 2: This prints a key-value pair mapping the variable indices to the
# variable values in the current solution
values = {(i, j): x[i, j].X for i in range(6) for j in range(8)}Best regards,
Maliheh
0 -
Hi Joël,
There is also a third approach that is much neater. You can simply query the attribute \(\texttt{X}\) on the MVar object \(\texttt{x}\) and this will give you a numpy array.
# Approach 3
x.XSorry for missing this easy and efficient approach!
Best regards,
Maliheh
0
投稿コメントは受け付けていません。
コメント
3件のコメント