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

Creating diagonal matrix from binary variables

回答済み

コメント

6件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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

    Which API are you using? (Your first line looks like Python, but the definition of Z does not.)

    Note that until version 8, the Gurobi Python API does not directly support matrix-oriented modeling, but this is going to change with Gurobi 9 (due later this year).

    1
  • Sagnik Basumallik
    • Gurobi-versary
    • Investigator
    • Conversationalist

    Hi Silke, I am using Python. The definition of Z was just an example.

     

    Do you think there is any indirect way I can create a matrix with binary variables in the diagonals? 

    0
  • Silke Horn
    • Gurobi Staff

    You can certainly create a numpy matrix with your variables on the diagonals; e.g.

    Z = np.diag([z[i] for i in arcs])

    but the question is what you want to do with this matrix once you have it...

    0
  • Sagnik Basumallik
    • Gurobi-versary
    • Investigator
    • Conversationalist

    Thank you Silke, I was able to define the binary matrix with your help.

    Z = np.diag([z[i,j] for i,j in arcs])
    print(Z)
    [[<gurobi.Var z[163,111]> 0 0 ..., 0 0 0]
    [0 <gurobi.Var z[47,54]> 0 ..., 0 0 0]
    [0 0 <gurobi.Var z[150,88]> ..., 0 0 0]...]

    What I want to do with the Z matrix is this: I have another matrix H that is multiplied to Z like this: Z*H. I want to maximize the rank of Z*H in the objective function.

    Do you think setting the objective function like maximize  rank(Z*H) is allowed in Gurobi? I am not sure if Z*H is counted as matrix-oriented modeling?

     

    0
  • Silke Horn
    • Gurobi Staff

    I am glad you got the matrix definition to work.

    The objective function needs to be a linear or quadratic expression, which, unfortunately, the rank of a matrix is not. (In fact, it is not even continuous.) I would expect that numpy cannot compute the rank of (Z*H) since it does not know what Gurobi variables are...

    So this is not going to work (because the math involved is more complicated -- this is not a short-coming of numpy or Gurobi).

    0

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