Skip to main content

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




  • 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


    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


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

  • Ragia Shaaban
    First Comment
    First Question

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


Please sign in to leave a comment.