4 Use a position index formulation for modeling the permutation flow
5 shop problem, with the objective of minimizing the makespan (maximum
8 Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
12 from pyscipopt
import Model, quicksum
16 """gpp -- model for the graph partitioning problem
19 - m: number of machines
20 - p[i,j]: processing time of job i on machine j
21 Returns a model, ready to be solved.
23 model = Model(
"permutation flow shop")
26 for j
in range(1, n + 1):
27 for k
in range(1, n + 1):
28 x[j, k] = model.addVar(vtype=
"B", name=
"x(%s,%s)" % (j, k))
30 for i
in range(1, m + 1):
31 for k
in range(1, n + 1):
32 s[i, k] = model.addVar(vtype=
"C", name=
"start(%s,%s)" % (i, k))
33 f[i, k] = model.addVar(vtype=
"C", name=
"finish(%s,%s)" % (i, k))
35 for j
in range(1, n + 1):
36 model.addCons(
quicksum(x[j, k]
for k
in range(1, n + 1)) == 1,
"Assign1(%s)" % (j))
37 model.addCons(
quicksum(x[k, j]
for k
in range(1, n + 1)) == 1,
"Assign2(%s)" % (j))
39 for i
in range(1, m + 1):
40 for k
in range(1, n + 1):
42 model.addCons(f[i, k] <= s[i, k + 1],
"FinishStart(%s,%s)" % (i, k))
44 model.addCons(f[i, k] <= s[i + 1, k],
"Machine(%s,%s)" % (i, k))
46 model.addCons(s[i, k] +
quicksum(p[i, j] * x[j, k]
for j
in range(1, n + 1)) <= f[i, k],
47 "StartFinish(%s,%s)" % (i, k))
49 model.setObjective(f[m, n],
"minimize")
56 """make_data: prepare matrix of m times n random processing times"""
58 for i
in range(1, m + 1):
59 for j
in range(1, n + 1):
60 p[i, j] = random.randint(1, 10)
65 """creates example data set"""
66 proc = [[2, 3, 1], [4, 2, 3], [1, 4, 1]]
70 p[i + 1, j + 1] = proc[j][i]
74 if __name__ ==
"__main__":
83 print(
"processing times (%s jobs, %s machines):" % (n, m))
84 for i
in range(1, m + 1):
85 for j
in range(1, n + 1):
93 print(
"Optimal value:", model.getObjVal())
106 seq = [j
for (k, j)
in sorted([(k, j)
for (j, k)
in x
if model.getVal(x[j, k]) > 0.5])]
107 print(
"optimal job permutation:", seq)