Skip to main content

Convert values of gurobi.LineExpr to integers

Answered

Comments

3 comments

  • Maliheh Aramon
    Gurobi Staff Gurobi Staff

    Hi, 

    You cannot pass Gurobi Python objects to a NetworkX algorithm function "local_edge_connectivity". This function expects a NetworkX graph object as the first argument. You cannot create a NetworkX object using an adjacency matrix whose values are Gurobi decision variables. 

    You can find the local edge connectivity values between the nodes in graph \(G\) and use those values in whatever optimization problem you are trying to solve.

    Best regards,

    Maliheh

    0
  • Huib Meulenbelt
    Gurobi-versary
    Curious
    Conversationalist

    Hi,

     

    Thank you for your reply. I understand that the "nx.from_numpy_array"-function doesn't accept Gurobi decision variables as input. However, is it possible to convert the values of the decision variables to a `numpy.array`?

    0
  • Maliheh Aramon
    Gurobi Staff Gurobi Staff

    However, is it possible to convert the values of the decision variables to a `numpy.array`?

    Yes, you can convert the values to a numpy array but the issue is that you do not have access to values until the optimization problem is solved. 

    If you define variables as Var objects using Model.addVar() or Model.addVars() methods, you can create an array using the values of individual variables by querying the X attribute after the optimization problem is solved.

    If you define variables as an MVar object using Model.addMVar(), querying the X attribute on an MVar object would result in a numpy array of decision values. However, the optimization problem needs to be solved before querying the values.

    Best regards,

    Maliheh

    0

Please sign in to leave a comment.