# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
# ---

from pulp import *


L = 4
W = 2
H = 2
n = 8
l = [1, 1, 1, 1, 2, 2, 2, 2, ]
w = [1, 1, 1, 1, 1, 1, 1, 1, ]
h = [2, 2, 2, 2, 1, 1, 1, 1, ]
M = max([L, W, H])


m = LpProblem(sense=LpMinimize)


x = [
    LpVariable("x%d" %i, lowBound=0, upBound=L, cat=LpInteger) for i in range(n)
]
y = [
    LpVariable("y%d" %i, lowBound=0, upBound=M, cat=LpInteger) for i in range(n)
]
z = [
    LpVariable("z%d" %i, lowBound=0, upBound=H, cat=LpInteger) for i in range(n)
]


a = [[LpVariable("a%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
b = [[LpVariable("b%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
c = [[LpVariable("c%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]


L = LpVariable("L")

m += L

for i in range(n):
    for j in range(n):
        m += x[i] + l[i] <= x[j] + M * (1 - a[i][j])
        m += y[i] + w[i] <= y[j] + M * (1 - b[i][j])
        m += z[i] + h[i] <= z[j] + M * (1 - c[i][j])
        if i < j:
            m += a[i][j] + a[j][i] + b[i][j] + b[j][i] + c[i][j] + c[j][i] == 1
for i in range(n):
    m += x[i] <= L - l[i]
    m += y[i] <= W - w[i]
    m += z[i] <= H - h[i]


# %%time
m.solve(PULP_CBC_CMD(threads=4))


from pulp import *


# L = 4
# W = 2
# H = 2
# n = 8
# l = [1, 1, 1, 1, 2, 2, 2, 2, ]
# w = [1, 1, 1, 1, 1, 1, 1, 1, ]
# h = [2, 2, 2, 2, 1, 1, 1, 1, ]
L = 6
W = 2
H = 2
n = 10
l = [1, 1, 2, 2, 2, 2, 1, 1, 1, 1, ]
w = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ]
h = [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, ]
M = max([L, W, H])


m = LpProblem(sense=LpMinimize)


x = [
    LpVariable("x%d" %i, lowBound=0, upBound=L, cat=LpInteger) for i in range(n)
]
y = [
    LpVariable("y%d" %i, lowBound=0, upBound=M, cat=LpInteger) for i in range(n)
]
z = [
    LpVariable("z%d" %i, lowBound=0, upBound=H, cat=LpInteger) for i in range(n)
]


a = [[LpVariable("a%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
b = [[LpVariable("b%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
c = [[LpVariable("c%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]


L = LpVariable("L")

m += L

for i in range(n):
    for j in range(n):
        m += x[i] + l[i] <= x[j] + M * (1 - a[i][j])
        m += y[i] + w[i] <= y[j] + M * (1 - b[i][j])
        m += z[i] + h[i] <= z[j] + M * (1 - c[i][j])
        if i < j:
            m += a[i][j] + a[j][i] + b[i][j] + b[j][i] + c[i][j] + c[j][i] == 1
for i in range(n):
    m += x[i] <= L - l[i]
    m += y[i] <= W - w[i]
    m += z[i] <= H - h[i]


# %%time
m.solve(PULP_CBC_CMD(threads=4))


from pulp import *


# L = 4
# W = 2
# H = 2
# n = 8
# l = [1, 1, 1, 1, 2, 2, 2, 2, ]
# w = [1, 1, 1, 1, 1, 1, 1, 1, ]
# h = [2, 2, 2, 2, 1, 1, 1, 1, ]
#
# L = 6
# W = 2
# H = 2
# n = 10
# l = [1, 1, 2, 2, 2, 2, 1, 1, 1, 1, ]
# w = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ]
# h = [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, ]
#
L = 8
W = 2
H = 2
n = 12
l = [1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, ]
w = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ]
h = [2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, ]
M = max([L, W, H])


m = LpProblem(sense=LpMinimize)


x = [
    LpVariable("x%d" %i, lowBound=0, upBound=L, cat=LpContinuous) for i in range(n)
]
y = [
    LpVariable("y%d" %i, lowBound=0, upBound=M, cat=LpContinuous) for i in range(n)
]
z = [
    LpVariable("z%d" %i, lowBound=0, upBound=H, cat=LpContinuous) for i in range(n)
]


a = [[LpVariable("a%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
b = [[LpVariable("b%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]
c = [[LpVariable("c%02d%02d" %(i, j), cat=LpBinary)
    for j in range(n)] for i in range(n)]


L = LpVariable("L")

m += L

for i in range(n):
    for j in range(n):
        m += x[i] + l[i] <= x[j] + M * (1 - a[i][j])
        m += y[i] + w[i] <= y[j] + M * (1 - b[i][j])
        m += z[i] + h[i] <= z[j] + M * (1 - c[i][j])
        if i < j:
            m += a[i][j] + a[j][i] + b[i][j] + b[j][i] + c[i][j] + c[j][i] == 1
for i in range(n):
    m += x[i] <= L - l[i]
    m += y[i] <= W - w[i]
    m += z[i] <= H - h[i]


# %%time
m.solve(PULP_CBC_CMD(threads=4, msg=True))


StarcoderdataJupyterScriptsDedupFiltered