Skip to main content

How to model the problem of cutting a polyhedron into parts

Answered

Comments

3 comments

  • Official comment
    Juan Orozco
    • Gurobi Staff Gurobi Staff

    To get non-overlapping rectangles of the same area, you can solve the following feasibility model (implemented in Python):

    import gurobipy as gp
    from gurobipy import GRB

    TOTAL_HEIGHT = 5
    TOTAL_WIDTH = 10
    N = 4

    model = gp.Model("myModel")
    model.setParam("NonConvex",2)

    x = model.addVars(N, ub=TOTAL_WIDTH, name="x")
    y = model.addVars(N, ub=TOTAL_HEIGHT, name="y")
    width = model.addVars(N, name="width")
    height = model.addVars(N, name="height")
    excess_x = model.addVars(N-1, name="excess_x")
    excess_y = model.addVars(N-1, name="excess_y")
    is_smaller_x = model.addVars(N-1, vtype=GRB.BINARY, name="is_smaller_x")
    is_smaller_y = model.addVars(N-1, vtype=GRB.BINARY, name="is_smaller_y")

    model.addConstrs((x[i] + width[i] <= TOTAL_WIDTH for i in range(N)))
    model.addConstrs((y[i] + height[i] <= TOTAL_HEIGHT for i in range(N)))

    model.addConstrs((x[i] + width[i] - excess_x[i] <= x[i+1] for i in range(N-1)))
    model.addConstrs((y[i] + height[i] - excess_y[i] <= y[i+1] for i in range(N-1)))

    for i in range(N-1):
    model.addSOS(GRB.SOS_TYPE1, [excess_x[i], is_smaller_x[i]])
    model.addSOS(GRB.SOS_TYPE1, [excess_y[i], is_smaller_y[i]])

    model.addConstrs((is_smaller_x[i] + is_smaller_y[i] >= 1 for i in range(N-1)))

    model.addConstrs((width[i]*height[i] == TOTAL_WIDTH*TOTAL_HEIGHT/N for i in range(N)))

    model.optimize()

    The trick is to compare the final coordinates of a given rectangle with the initial coordinates of the next one, to prevent that the latter coordinates are located in the bottom-left of the former.

  • Official comment
    Simranjit Kaur
    • Gurobi Staff 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?.
  • Jiangfei DUAN
    • Gurobi-versary
    • Conversationalist
    • Curious

    Thanks a lot.

    I got it. 

    0

Post is closed for comments.