I have a list of products (i), each with given weight and volume. The optimization goes in two steps, of which I have been unable to solve the second step.
First optimization: minimize number of bins used (solved)
Minimize number of bins used to pack list of products. I have fixed bins with with maximum volume and weight constraints. Python code:
prob = pp.LpProblem("algorithm",pp.LpMinimize) #pp=pulp solver Y_max=10 #bins will not exceed this number #Y_min = minimum number of bins (calculated) # j = index of jth bin # i = index of ith product w=weights #list of weights w_i for product i v=volumes #list of volumes v_i for product i W=W_max #maximum weight of a bin V=V_max #maximum volume of a bin #len(order) = number of products x=pp.LpVariable.dicts("x_i,j", ((i, j) for i in range(len(order)) for j in range(Y_max)),0,1,pp.LpBinary) #variable indicating if product i is placed in bin j y=pp.LpVariable.dicts("y_j", ((j,0) for j in range(Y_max)),0,1,pp.LpBinary) #variable indicating if bin j is used or unused Y=pp.LpVariable('Y') prob +=Y , 'objective function' prob += pp.lpSum([y[j,0] for j in range(Y_max)]) == Y, "" for i in range(len(order)): prob += pp.lpSum([x[i,j] for j in range(Y_max)]) == 1,'' #product i can only be placed in 1 bin for j in range(Y_max): prob += pp.lpSum([x[i,j]*w[i] for i in range(len(order))]) <= W*y[j,0],"" #weight constraint for j in range(Y_max): prob += pp.lpSum([x[i,j]*v[i] for i in range(len(order))]) <= V*y[j,0],"" #volume constraint for j in range(Y_max): for i in range(len(order)): prob += x[i,j] <= y[j,0],"" #products i may not be placed in bin j if bin j is unnused. prob += pp.lpSum([y[j,0] for i in range(len(order))]) >=Y_min,"" pp.LpSolverDefault.msg = 1 prob.solve()`
Second optimization: minimize the number of zones that the bin travels to (how to solve in linear optimization?)
Each product comes from 1 out of two zones (Zone 1 or Zone 2). We have a list of these zones z_i (e.g. Zone 1 <==> 1, Zone 2 <==> 0).
Under the constraint that the number of bins does not exceed the minimum number of bins (determined in first optimization), can I split the products over the bins such that the number of zones that each bin travels to is minimized?
Volume and weight constraints of first optimization still apply.
Ideally a bin would never travel to two zones, but in some cases it is forced to do so. (e.g. first optimization leads to 1 bin containing products of zone 1 and zone 2).