Skip to main content

What does "x[i,j].x" means?

Answered

Comments

3 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?.
  • Silke Horn
    Gurobi Staff Gurobi Staff

    Welcome to Gurobi!

    With the X attribute, you access the variable's value in the current solution. Note that the code first does

    m.optimize()

    to find the optimal solution. The /(x[i,j].x/) is then part of the code that prints the solution to the screen.

    You should actually add the same to y[i] in this line:

    facilities=[i for i in y if y[i]==1 ]

    Also, it is recommended to allow for some tolerances when comparing the values of variables with other numbers (because some small deviations are unavoidable in computations with floating-point numbers). E.g. instead of \(x[i,j].x \neq 0\) you should check for \(x[i,j].X > \epsilon\) or \(x[i,j].X < -\epsilon\) for some appropriate \(\epsilon\) (e.g. 1e-6). Since y is binary, you could instead of \(y[i].X == 1\) simply check for \(y[i].X > 0.5\).

     

    A few more remarks on your code: The line

    keys= ((i,j) for (i,j) in x )

    building the same object for each i in I and j  in J and could be moved outside the loop. (The variables i and j in this line are not the ones your looping over with "for i in I" and "for j in J".)

    The line

    edges[keys]=x[i,j]

    also does not really make sense it keeps overwriting edges[keys] in each iteration of the loop.

    0
  • Ragia Shaaban
    Gurobi-versary
    First Comment
    First Question

    Thank you very much, your support is greatly appreciated :)

    0

Post is closed for comments.