Skip to main content

Programming sequence with combined constraints, min_() or or_()

Answered

Comments

3 comments

  • Official comment
    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?.
  • Maliheh Aramon
    • Gurobi Staff

    Hi Antoine, 

    • The first error occurs because Gurobi does not directly support multiplication of three variables. Please have a look at How do I model multilinear terms in Gurobi? article that explains an indirect approach to represent constraints containing general multilinear terms.
    •  The second error occurs because it is not possible to sum over GenExpr() objects. To do so, each min_() general expression needs to be assigned to an auxiliary Gurobi Var() object and the sum() can then be defined over auxiliary variables.
    • The third error occurs because the Python math.floor() function takes a real number as an input and not a Gurobi LinExpr()

    That being said, for every pair of \((t_i, t_j)\) tools in set \(S\) that needs to be placed in adjacent locations, you can represent the constraint as below where \(L\) is the number of locations.

    \[x_{t_il} \leq x_{t_j(l+1)}, ~~ l = 1, ..., L -1; ~~ (t_i, t_j) \in S \]

    The above constraint guarantees that if tool \(t_i\) is assigned to location \(l\), tool \(t_j\) is then assigned to location \(l+1\). The code snippet below shows how to implement this:

    for s in series:
    for ti, tj in zip(s[:-1], s[1:]):
    m.addConstrs(
    (x[ti, l] <= x[tj, l + 1] for l in range(len(l_ids) - 1)),
    name="ordering",
    )

    Best regards,

    Maliheh

    1
  • Antoine Gros
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Maliheh,

    Thanks for the input and the clarification of the errors outputed. Your solution and a discussion I had this morning with a fellow theorist helped me understand how I was looking for something too complicated ... for something that seems to me - rather - simple after all !

    Glad to have an answer as precise and as soon !

    Best regards,
    Antoine

    0

Post is closed for comments.