メインコンテンツへスキップ

How to define a list of n tuples, each tuple contains 2 variables

回答済み

コメント

5件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Mario Ruthmair
    • 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

    1
  • Fei Wang
    • Gurobi-versary
    • Conversationalist
    • First Question

    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?  

    0
  • Mario Ruthmair
    • 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.

    1
  • Fei Wang
    • Gurobi-versary
    • Conversationalist
    • First Question

    Thanks! That's the method I am looking for

    0

投稿コメントは受け付けていません。