Skip to main content

Defining Variable with Dynamic shape

Answered

Comments

1 comment

  • Jaromił Najman
    Gurobi Staff 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

Please sign in to leave a comment.