Skip to main content

how can I retrieve the values for a single variable? The variable is something like d(b,t).

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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?.
  • Eli Towle
    Gurobi Staff Gurobi Staff

    Hi Yiwen,

    The variable l is a tupledict that maps a set of indices to Var objects. The values() method of a tupledict returns a list of the corresponding Var objects. Finally, the X attribute of a Var object stores the variable's value at the current solution.

    So, after optimizing, you can iterate through each variable in the tupledict and retrieve the variable's solution value. For example:

    for v in l.values():
    print("{}: {}".format(v.varName, v.X))

    You could also use a dictionary comprehension to construct a dictionary that maps the variable indices to the corresponding solution values. This can be done by iterating over the tupledict's key-value pairs:

    vals = { k : v.X for k,v in l.items() }

    I hope this helps!

    1
  • Yiwen Zhou
    Gurobi-versary
    First Comment
    First Question

    Thanks a lot Eli! :-)

    0
  • Mai Elgazzar

    how can I get the result in one list? 

    as my case is:

    for v in   A.values(): 
        z= (v.X)
        print ((z))

     

    my result is:

    0.0
    361.0
    709.0
    0.0

     

    while I need to have them in one list to be able to do further operations on them

     

    0

Post is closed for comments.