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

Defining Variable with Dynamic shape

回答済み

コメント

2件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    You will have to formulate this property via additional variables and constraints. You have to define all variables for \(W_i\) as if it would attain its maximum dimension.

    M is defined according to number of 1 elements in ith row of another variable matrix A with shape (Q*P)

    You can define an equality constraint and add an integer variable counting the number of 1 elements in \(A\)

    \[\begin{align*}
    \sum A_{ij} = ones
    \end{align*}\]

    where \(ones\) is a non-negative integer variable.

    You can then add a binary variable \(b\) and an inequality constraint for each variable \(x\) of matrix \(W_i\) stating

    \[\begin{align*}
    c\cdot b \leq ones
    \end{align*}\]

    where \(c\) is an integer constant large enough to force \(b=0\) if \(ones\) is not big enough. For example, if variable \(x\) of the \(W_i\) matrix is not present when there are less than 5 ones in \(A\) then \(5 b \leq ones\) will force \(b=0\) for \(ones < 5\). You can then use variable \(b\) to turn on and off variable bounds for variable \(x\) via \(x^{LB} b \leq x \leq x^{UB} b\), with \(x \in [x^{LB}, x^{UB}]\).

    Note that the above is just an example and you will probably have to adjust it for your application. But I think it should be enough to get the idea of how such a formulation can be done.

    Also note that the above idea can probably be improved and maybe there are more involved formulations for your application so it is best to also search for it in the literature.

    Best regards, 
    Jaromił

    0

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