Storing all solutions in one dictionary (Python)
回答済みHi,
Is there a way to store the solution obtained from Gurobi in one dictionary, where the dictionary key would be the variable name?
Gurobi has the command Model.getVarByName that can be used inside a for loop, but for our case, we found that this is a very slow process.
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 why not try our AI Gurobot?. -
You could use Model.getAttr() to retrieve all of the variable names and values at once:
mvars = m.getVars()
names = m.getAttr('VarName', mvars)
values = m.getAttr('X', mvars)
result = dict(zip(names, values))This should be a bit faster.
0
投稿コメントは受け付けていません。
コメント
2件のコメント