about gurobi constraint name
Awaiting user inputI want to get the dual variable for specific constraints by name,
but m_dis.getConstrByName() return None when I input the name of auxiliary constraints.
So I check with following code.
for i in range(N.Agent):
c = m_dis.addConstr(aux - p_select[i] <= 0, name = "auxiliary constraint" + str(i))
m_dis.update()
print(c.ConstrName)
and the output is
['auxiliary constraint0[0]']
['auxiliary constraint1[0]']
['auxiliary constraint2[0]']
['auxiliary constraint3[0]']
['auxiliary constraint4[0]']
['auxiliary constraint1[0]']
['auxiliary constraint2[0]']
['auxiliary constraint3[0]']
['auxiliary constraint4[0]']
I want to know why the return constrain name isn't the same as the name I set and what should I do if I still want to get the dual variables by constraints name, can anyone help me? Thank you very much!
0
-
Official comment
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. -
Which version of Gurobi are you using? If \(\texttt{p_select}\) are your variables, how exactly do you define them?
I wonder if you are defining the variables as two-dimensional MVar objects:
p_select = m_dis.addMVar((5, 1), name="p_select")
If that's the case, your call to Model.addConstr() adds an array of constraints (of length 1), and Gurobi adds indices to the names of each constraint. Instead, try defining the variables as one-dimensional MVar objects:
p_select = m_dis.addMVar((5,), name="p_select")
Also, including spaces in variable/constraint names is not recommended, as such names cannot be written to an LP file.
0
Post is closed for comments.
Comments
2 comments