-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPModel_ALBP.py
More file actions
65 lines (51 loc) · 1.62 KB
/
CPModel_ALBP.py
File metadata and controls
65 lines (51 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from docplex.cp.model import CpoModel
from docplex.cp.config import context
context.solver.agent = 'local'
context.solver.local.execfile = '/Applications/CPLEX_Studio_Community129/cpoptimizer/bin/x86-64_osx/cpoptimizer'
# """ Initialize the problem data """
# # operating time of task i
# TaskTime = [81, 109, 65, 51, 92, 77, 51, 50, 43, 45, 76]
#
# # number of workstations
# nbStations = 5
#
# # immediate precedence tasks of task i
# PrecedenceTasks = [
# [],
# [1],
# [1],
# [1],
# [1],
# [1, 2],
# [1, 3, 4, 5],
# [1, 2, 6],
# [1, 3, 4, 5, 7],
# [1, 2, 6, 8],
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]
#
def ALBP(TaskTime, nbStations, PrecedenceTasks):
""" Prepare the data for modeling """
# tasks set
TASKS = range(len(TaskTime))
# workstations set
WORKSTATIONS = range(nbStations)
""" Build the model """
# Create CPO model
myModel = CpoModel()
# Assign tasks to workstation
WhichWorkstation = myModel.integer_var_list(len(TaskTime), 0, nbStations - 1)
# Cycle time
CycleTime = myModel.integer_var(max(TaskTime), sum(TaskTime))
# Add station load constraints
for k in WORKSTATIONS:
myModel.add(sum(TaskTime[i] * (WhichWorkstation[i] == k) for i in TASKS) <= CycleTime)
# Add precedence constraints
for i in TASKS:
for j in PrecedenceTasks[i]:
myModel.add(WhichWorkstation[j] <= WhichWorkstation[i])
# Create model objective
myModel.add(myModel.minimize(CycleTime))
""" Solve model """
solution = myModel.solve(FailLimit=100000, TimeLimit=10)
""" Print solution """
return solution