Variables names not availables
回答済みHello,
I hope you are doing good,
I'm trying to retrive variables names with values but i don't get them in thhe results, i try this :
mvars = model.getVars()
names = model.getAttr('VarName', mvars)
values = model.getAttr('X', mvars)
result = dict(zip(names, values))
result
and i get this :
'C185': 1476.4134095253548, 'C186': 715.6403569907727,
Thanks in advance;
Best Regards.
-
正式なコメント
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?. -
Hi Hamza,
You post seems to be very badly edited. Could you try editing your post such that it becomes more readable?
From what I can see in your post, the \(\texttt{result}\) object holds the names of your variables and their solution point values, e.g.,
'C202': 658.422563285164
Isn't this what you were asking for?
Best regards,
Jaromił1 -
Hello,
i'm sorry for the poor quality of the post,
and yes the result object holds names of variables and the solution is :
'C202': 658.422563285164
i actually solved that problem, but now when i try to print the names with this line of code :
mvars = model.getVars()
names = model.getAttr('VarName', mvars)
values = model.getAttr('X', mvars)
result = dict(zip(names, values))
print(result)i get this error :
UnicodeDecodeError Traceback (most recent call last) C:\Users\HAMZA~1.ADD\AppData\Local\Temp/ipykernel_10292/2862146907.py in <module>
1 mvars = model.getVars()
----> 2 names = model.getAttr('VarName', mvars)
3 values = model.getAttr('X', mvars)
4 result = dict(zip(names, values))
src\gurobipy\model.pxi in gurobipy.Model.getAttr()
src\gurobipy\attrutil.pxi in gurobipy.__gettypedattrlist()
src\gurobipy\extern.pxi in gurobipy.__bytestostring()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 31: invalid continuation byte1 -
Hi,
Are you using any special ascii character for your variable names? In particular, what is the character in position 31 of all the variable names. Is one of the character a non-standard ascii character?
Best regards,
Jaromił1 -
This is what i have :
- i bring the variables names by iterating over an xlsx file
like this for example :
var1= model.addVars(list_excel1, list_excel2, list_excel3, list_excel4,lb = 0,vtype = GRB.CONTINUOUS,name='var1')
and i don't know how to verifiy if i don't have ascii characters in my xlsx file.
Best Regards,
Hamza
0 -
I wanted to add that i verified the lists :
list_excel1, list_excel2, list_excel3, list_excel4
but i cannot see any non-standard ascii characters.
Best regards,
Hamza ADDI
0 -
The issue was caused by 2 non-standard ASCII characters ï and â. Removing those solved the issue.
1
投稿コメントは受け付けていません。
コメント
7件のコメント