Skip to content

Commit 78fbc1c

Browse files
authored
Merge pull request #47 from IBMDecisionOptimization/release_2.21.207
sync with release docplex 2.21
2 parents f540bcc + 2efff7f commit 78fbc1c

26 files changed

+1377
-1135
lines changed

examples/cp/visu/flow_shop.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
Please refer to documentation for appropriate setup of solving configuration.
1616
"""
1717

18-
from docplex.cp.model import CpoModel
19-
import docplex.cp.utils_visu as visu
18+
from docplex.cp.model import *
2019
import os
2120

22-
2321
#-----------------------------------------------------------------------------
2422
# Initialize the problem data
2523
#-----------------------------------------------------------------------------
@@ -30,11 +28,10 @@
3028
# The rest of the file consists of one line per job that contains the list of
3129
# operations given as durations for each machines.
3230

33-
filename = os.path.dirname(os.path.abspath(__file__)) + "/data/flowshop_default.data"
34-
with open(filename, "r") as file:
31+
filename = os.path.dirname(os.path.abspath(__file__)) + '/data/flowshop_default.data'
32+
with open(filename, 'r') as file:
3533
NB_JOBS, NB_MACHINES = [int(v) for v in file.readline().split()]
36-
JOB_DURATIONS = [[int(v) for v in file.readline().split()] for i in range(NB_JOBS)]
37-
34+
OP_DURATIONS = [[int(v) for v in file.readline().split()] for i in range(NB_JOBS)]
3835

3936
#-----------------------------------------------------------------------------
4037
# Build the model
@@ -44,40 +41,40 @@
4441
mdl = CpoModel()
4542

4643
# Create one interval variable per job operation
47-
job_operations = [[mdl.interval_var(size=JOB_DURATIONS[j][m], name="J{}-M{}".format(j, m)) for m in range(NB_MACHINES)] for j in range(NB_JOBS)]
44+
operations = [[interval_var(size=OP_DURATIONS[j][m], name='J{}-M{}'.format(j, m)) for m in range(NB_MACHINES)] for j in range(NB_JOBS)]
4845

4946
# Force each operation to start after the end of the previous
5047
for j in range(NB_JOBS):
51-
for m in range(1, NB_MACHINES):
52-
mdl.add(mdl.end_before_start(job_operations[j][m - 1], job_operations[j][m]))
48+
for m in range(1,NB_MACHINES):
49+
mdl.add(end_before_start(operations[j][m-1], operations[j][m]))
5350

5451
# Force no overlap for operations executed on a same machine
5552
for m in range(NB_MACHINES):
56-
mdl.add(mdl.no_overlap([job_operations[j][m] for j in range(NB_JOBS)]))
53+
mdl.add(no_overlap(operations[j][m] for j in range(NB_JOBS)))
5754

5855
# Minimize termination date
59-
mdl.add(mdl.minimize(mdl.max([mdl.end_of(job_operations[i][NB_MACHINES - 1]) for i in range(NB_JOBS)])))
60-
56+
mdl.add(minimize(max(end_of(operations[i][NB_MACHINES-1]) for i in range(NB_JOBS))))
6157

6258
#-----------------------------------------------------------------------------
6359
# Solve the model and display the result
6460
#-----------------------------------------------------------------------------
6561

6662
# Solve model
67-
print("Solving model....")
68-
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
69-
print("Solution: ")
70-
msol.print_solution()
63+
print('Solving model...')
64+
res = mdl.solve(TimeLimit=10,LogPeriod=1000000)
65+
print('Solution:')
66+
res.print_solution()
7167

7268
# Display solution
73-
if msol and visu.is_visu_enabled():
74-
visu.timeline("Solution for flow-shop " + filename)
75-
visu.panel("Jobs")
69+
import docplex.cp.utils_visu as visu
70+
if res and visu.is_visu_enabled():
71+
visu.timeline('Solution for flow-shop ' + filename)
72+
visu.panel('Jobs')
7673
for i in range(NB_JOBS):
7774
visu.sequence(name='J' + str(i),
78-
intervals=[(msol.get_var_solution(job_operations[i][j]), j, 'M' + str(j)) for j in range(NB_MACHINES)])
79-
visu.panel("Machines")
75+
intervals=[(res.get_var_solution(operations[i][j]), j, 'M' + str(j)) for j in range(NB_MACHINES)])
76+
visu.panel('Machines')
8077
for j in range(NB_MACHINES):
8178
visu.sequence(name='M' + str(j),
82-
intervals=[(msol.get_var_solution(job_operations[i][j]), j, 'J' + str(i)) for i in range(NB_JOBS)])
79+
intervals=[(res.get_var_solution(operations[i][j]), j, 'J' + str(i)) for i in range(NB_JOBS)])
8380
visu.show()

examples/cp/visu/flow_shop_permutation.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
Please refer to documentation for appropriate setup of solving configuration.
1717
"""
1818

19-
from docplex.cp.model import CpoModel
20-
import docplex.cp.utils_visu as visu
19+
from docplex.cp.model import *
2120
import os
2221

2322

@@ -30,10 +29,10 @@
3029
# First line contains the number of jobs, and the number of machines.
3130
# The rest of the file consists of one line per job that contains the list of
3231
# operations given as durations for each machines.
33-
filename = os.path.dirname(os.path.abspath(__file__)) + "/data/flowshop_default.data"
34-
with open(filename, "r") as file:
32+
filename = os.path.dirname(os.path.abspath(__file__)) + '/data/flowshop_default.data'
33+
with open(filename, 'r') as file:
3534
NB_JOBS, NB_MACHINES = [int(v) for v in file.readline().split()]
36-
JOB_DURATIONS = [[int(v) for v in file.readline().split()] for i in range(NB_JOBS)]
35+
OP_DURATIONS = [[int(v) for v in file.readline().split()] for i in range(NB_JOBS)]
3736

3837

3938
#-----------------------------------------------------------------------------
@@ -44,47 +43,46 @@
4443
mdl = CpoModel()
4544

4645
# Create one interval variable per job operation
47-
job_operations = [[mdl.interval_var(size=JOB_DURATIONS[j][m], name="J{}-M{}".format(j, m)) for m in range(NB_MACHINES)] for j in range(NB_JOBS)]
46+
operations = [[interval_var(size=OP_DURATIONS[j][m], name='J{}-M{}'.format(j, m)) for m in range(NB_MACHINES)] for j in range(NB_JOBS)]
4847

4948
# Create sequence of operation for each machine
50-
op_sequences = [mdl.sequence_var([job_operations[i][j] for i in range(NB_JOBS)], name="M{}".format(j)) for j in range(NB_MACHINES)]
49+
op_sequences = [sequence_var([operations[i][j] for i in range(NB_JOBS)], name='M{}'.format(j)) for j in range(NB_MACHINES)]
5150

5251
# Force each operation to start after the end of the previous
5352
for j in range(NB_JOBS):
5453
for m in range(1, NB_MACHINES):
55-
mdl.add(mdl.end_before_start(job_operations[j][m - 1], job_operations[j][m]))
54+
mdl.add(end_before_start(operations[j][m-1], operations[j][m]))
5655

5756
# Force no overlap for operations executed on a same machine
5857
for m in range(NB_MACHINES):
59-
mdl.add(mdl.no_overlap(op_sequences[m]))
58+
mdl.add(no_overlap(op_sequences[m]))
6059

6160
# Force sequences to be all identical on all machines
6261
for m in range(1, NB_MACHINES):
63-
mdl.add(mdl.same_sequence(op_sequences[0], op_sequences[m]))
62+
mdl.add(same_sequence(op_sequences[0], op_sequences[m]))
6463

6564
# Minimize termination date
66-
mdl.add(mdl.minimize(mdl.max([mdl.end_of(job_operations[i][NB_MACHINES - 1]) for i in range(NB_JOBS)])))
65+
mdl.add(minimize(max([end_of(operations[i][NB_MACHINES-1]) for i in range(NB_JOBS)])))
6766

6867

6968
#-----------------------------------------------------------------------------
7069
# Solve the model and display the result
7170
#-----------------------------------------------------------------------------
7271

7372
# Solve model
74-
print("Solving model....")
75-
msol = mdl.solve(FailLimit=10000, TimeLimit=10)
76-
print("Solution: ")
77-
msol.print_solution()
73+
print('Solving model...')
74+
res = mdl.solve(FailLimit=10000, TimeLimit=10)
7875

7976
# Draw solution
80-
if msol and visu.is_visu_enabled():
81-
visu.timeline("Solution for permutation flow-shop " + filename)
82-
visu.panel("Jobs")
77+
import docplex.cp.utils_visu as visu
78+
if res and visu.is_visu_enabled():
79+
visu.timeline('Solution for permutation flow-shop ' + filename)
80+
visu.panel('Jobs')
8381
for i in range(NB_JOBS):
8482
visu.sequence(name='J' + str(i),
85-
intervals=[(msol.get_var_solution(job_operations[i][j]), j, 'M' + str(j)) for j in range(NB_MACHINES)])
86-
visu.panel("Machines")
83+
intervals=[(res.get_var_solution(operations[i][j]), j, 'M' + str(j)) for j in range(NB_MACHINES)])
84+
visu.panel('Machines')
8785
for j in range(NB_MACHINES):
8886
visu.sequence(name='M' + str(j),
89-
intervals=[(msol.get_var_solution(job_operations[i][j]), j, 'J' + str(i)) for i in range(NB_JOBS)])
87+
intervals=[(res.get_var_solution(operations[i][j]), j, 'J' + str(i)) for i in range(NB_JOBS)])
9088
visu.show()

examples/cp/visu/house_building_basic.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
Please refer to documentation for appropriate setup of solving configuration.
1414
"""
1515

16-
from docplex.cp.model import CpoModel
17-
import docplex.cp.utils_visu as visu
16+
from docplex.cp.model import *
1817

1918

2019
#-----------------------------------------------------------------------------
@@ -24,44 +23,45 @@
2423
# Create model
2524
mdl = CpoModel()
2625

27-
masonry = mdl.interval_var(name='masonry', size=35)
28-
carpentry = mdl.interval_var(name='carpentry', size=15)
29-
plumbing = mdl.interval_var(name='plumbing', size=40)
30-
ceiling = mdl.interval_var(name='ceiling', size=15)
31-
roofing = mdl.interval_var(name='roofing', size=5)
32-
painting = mdl.interval_var(name='painting', size=10)
33-
windows = mdl.interval_var(name='windows', size=5)
34-
facade = mdl.interval_var(name='facade', size=10)
35-
garden = mdl.interval_var(name='garden', size=5)
36-
moving = mdl.interval_var(name='moving', size=5)
26+
masonry = interval_var(name='masonry', size=35)
27+
carpentry = interval_var(name='carpentry', size=15)
28+
plumbing = interval_var(name='plumbing', size=40)
29+
ceiling = interval_var(name='ceiling', size=15)
30+
roofing = interval_var(name='roofing', size=5)
31+
painting = interval_var(name='painting', size=10)
32+
windows = interval_var(name='windows', size=5)
33+
facade = interval_var(name='facade', size=10)
34+
garden = interval_var(name='garden', size=5)
35+
moving = interval_var(name='moving', size=5)
3736

3837
# Add precedence constraints
39-
mdl.add(mdl.end_before_start(masonry, carpentry))
40-
mdl.add(mdl.end_before_start(masonry, plumbing))
41-
mdl.add(mdl.end_before_start(masonry, ceiling))
42-
mdl.add(mdl.end_before_start(carpentry, roofing))
43-
mdl.add(mdl.end_before_start(ceiling, painting))
44-
mdl.add(mdl.end_before_start(roofing, windows))
45-
mdl.add(mdl.end_before_start(roofing, facade))
46-
mdl.add(mdl.end_before_start(plumbing, facade))
47-
mdl.add(mdl.end_before_start(roofing, garden))
48-
mdl.add(mdl.end_before_start(plumbing, garden))
49-
mdl.add(mdl.end_before_start(windows, moving))
50-
mdl.add(mdl.end_before_start(facade, moving))
51-
mdl.add(mdl.end_before_start(garden, moving))
52-
mdl.add(mdl.end_before_start(painting, moving))
38+
mdl.add(end_before_start(masonry, carpentry))
39+
mdl.add(end_before_start(masonry, plumbing))
40+
mdl.add(end_before_start(masonry, ceiling))
41+
mdl.add(end_before_start(carpentry, roofing))
42+
mdl.add(end_before_start(ceiling, painting))
43+
mdl.add(end_before_start(roofing, windows))
44+
mdl.add(end_before_start(roofing, facade))
45+
mdl.add(end_before_start(plumbing, facade))
46+
mdl.add(end_before_start(roofing, garden))
47+
mdl.add(end_before_start(plumbing, garden))
48+
mdl.add(end_before_start(windows, moving))
49+
mdl.add(end_before_start(facade, moving))
50+
mdl.add(end_before_start(garden, moving))
51+
mdl.add(end_before_start(painting, moving))
5352

5453

5554
#-----------------------------------------------------------------------------
5655
# Solve the model and display the result
5756
#-----------------------------------------------------------------------------
5857

5958
# Solve model
60-
print("Solving model....")
61-
msol = mdl.solve(TimeLimit=10)
62-
print("Solution: ")
63-
msol.print_solution()
59+
print('Solving model...')
60+
res = mdl.solve(TimeLimit=10)
61+
print('Solution:')
62+
res.print_solution()
6463

6564
# Draw solution
66-
if msol and visu.is_visu_enabled():
67-
visu.show(msol)
65+
import docplex.cp.utils_visu as visu
66+
if res and visu.is_visu_enabled():
67+
visu.show(res)

0 commit comments

Comments
 (0)