• Gurobi Staff

Hi,

As you defined the names of your variables, I would suggest to use two variable dicts, e.g.,

x = model.addVars(n, vtype=GRB.CONTINUOUS, name="x")y = model.addVars(n, vtype=GRB.CONTINUOUS, name="y")

Would this be uncomfortable to use for you?

Best regards,
Mario

Hi Mario,

Thanks for the answer, but I want to generalise it to  define a vector which represent a point in r dimensional space, If I use this approach, I would have to modify the code to define z if I want to define a point in R^3, instead of just changing r in the input.

The reason I want to extract a row from x is that I want to add some constraints regarding the distances between two points which is a second order cone constraint.
For example,  something like d @ d <= t @ t where d =  [x[i] - x[ j], y[i] - y[j], z[i] - y[j],...., ] (there are r component in d), I am not sure how to do this. Instead of x,y,z I should use x_1,x_2,....,x_r?

• Gurobi Staff

It seems you could use the gurobipy Matrix API to handle your vars and constraints. Here is some material:

Basically, you can add a matrix variable like this:

x = model.addMVar((n,r), vtype=GRB.CONTINUOUS, name="x")

Then, you can slice this matrix variable similar to how you would do it in numpy to build your constraints.

Thanks! That's the method I am looking for