Skip to main content

MVar constraint loops

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

    Hi Robert,

    One possible way would be to use the list version of your \(\texttt{MVars}\) when adding the constraints, e.g.,

    xsize = 1000
    ysize = 100
    zsize = 4

    xyz = model.addMVar((xsize,ysize,zsize))
    xy = model.addMVar((xsize,ysize))

    xyz_list = xyz.tolist()
    xy_list = xy.tolist()

    for i in range(xsize):
    for j in range(ysize):
    model.addConstr(gp.quicksum(xyz_list[i][j][z] for z in range(zsize)) == xy_list[i][j])

    Best regards,
    Jaromił

    0
  • Robert Vick
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks very much!  That did the job nicely.  I noticed a related and more severe problem is that setting ub on xyz can make creating the MVar extremely slow (like about 5 minutes) if each component has a different ub.  I can avoid that by setting a single value ub, and using constraints.  That also seems wrong, but at least there is a workaround.

    0

Post is closed for comments.