メインコンテンツへスキップ

Variables names not availables

回答済み

コメント

7件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff

    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
  • hamza addi
    • Gurobi-versary
    • Curious
    • Conversationalist

    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 byte



    1
  • Jaromił Najman
    • Gurobi Staff

    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
  • hamza addi
    • Gurobi-versary
    • Curious
    • Conversationalist

    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
  • hamza addi
    • Gurobi-versary
    • Curious
    • Conversationalist

    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
  • Jaromił Najman
    • Gurobi Staff

    The issue was caused by 2 non-standard ASCII characters ï and â. Removing those solved the issue.

    1

投稿コメントは受け付けていません。