PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
pfs.py
Go to the documentation of this file.
1 
3 """
4 Use a position index formulation for modeling the permutation flow
5 shop problem, with the objective of minimizing the makespan (maximum
6 completion time).
7 
8 Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
9 """
10 import random
11 
12 from pyscipopt import Model, quicksum
13 
14 
15 def permutation_flow_shop(n, m, p):
16  """gpp -- model for the graph partitioning problem
17  Parameters:
18  - n: number of jobs
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.
22  """
23  model = Model("permutation flow shop")
24 
25  x, s, f = {}, {}, {}
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))
29 
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))
34 
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))
38 
39  for i in range(1, m + 1):
40  for k in range(1, n + 1):
41  if k != n:
42  model.addCons(f[i, k] <= s[i, k + 1], "FinishStart(%s,%s)" % (i, k))
43  if i != m:
44  model.addCons(f[i, k] <= s[i + 1, k], "Machine(%s,%s)" % (i, k))
45 
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))
48 
49  model.setObjective(f[m, n], "minimize")
50 
51  model.data = x, s, f
52  return model
53 
54 
55 def make_data(n, m):
56  """make_data: prepare matrix of m times n random processing times"""
57  p = {}
58  for i in range(1, m + 1):
59  for j in range(1, n + 1):
60  p[i, j] = random.randint(1, 10)
61  return p
62 
63 
64 def example():
65  """creates example data set"""
66  proc = [[2, 3, 1], [4, 2, 3], [1, 4, 1]]
67  p = {}
68  for i in range(3):
69  for j in range(3):
70  p[i + 1, j + 1] = proc[j][i]
71  return p
72 
73 
74 if __name__ == "__main__":
75  random.seed(1)
76  n = 15
77  m = 10
78  p = make_data(n, m)
79 
80  # n = 3
81  # m = 3
82  # p = example()
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):
86  print(p[i, j], )
87  print
88 
89  model = permutation_flow_shop(n, m, p)
90  # model.write("permflow.lp")
91  model.optimize()
92  x, s, f = model.data
93  print("Optimal value:", model.getObjVal())
94 
95 
104 
105  # x[j,k] = 1 if j is the k-th job; extract job sequence:
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)
pyscipopt.expr.quicksum
def quicksum(termlist)
Definition: expr.pxi:357
pfs.example
def example()
Definition: pfs.py:64
pfs.make_data
def make_data(n, m)
Definition: pfs.py:55
pfs.permutation_flow_shop
def permutation_flow_shop(n, m, p)
Definition: pfs.py:15