Skip to content

Commit 9868f69

Browse files
committed
2.0.15
1 parent d06d7de commit 9868f69

File tree

11 files changed

+88
-18
lines changed

11 files changed

+88
-18
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# --------------------------------------------------------------------------
2+
# Source file provided under Apache License, Version 2.0, January 2004,
3+
# http://www.apache.org/licenses/
4+
# (c) Copyright IBM Corp. 2015, 2016
5+
# --------------------------------------------------------------------------
6+
7+
"""
8+
In mathematics, a Golomb ruler is a set of marks at integer positions along
9+
an imaginary ruler such that no two pairs of marks are the same distance apart.
10+
The number of marks on the ruler is its order, and the largest distance
11+
between two of its marks is its length.
12+
13+
This implementation differs from the 'basic' one because it calls the solver
14+
twice:
15+
* First time to know the minimal size of the ruler for the required order,
16+
* A second time to list all possible rulers for this optimal size
17+
18+
See https://en.wikipedia.org/wiki/Golomb_ruler for more information.
19+
20+
For order 5: 2 solutions 0 1 4 9 11 ; 0 2 7 8 11
21+
22+
Please refer to documentation for appropriate setup of solving configuration.
23+
"""
24+
25+
from docplex.cp.model import *
26+
from sys import stdout
27+
28+
from docplex.cp.config import context
29+
30+
# Set model parameters
31+
ORDER = 10 # Number of marks
32+
MAX_LENGTH = (ORDER - 1) ** 2 # Max rule length
33+
34+
# Create model
35+
mdl = CpoModel()
36+
37+
# Create array of variables corresponding to position rule marks
38+
marks = integer_var_list(ORDER, 0, MAX_LENGTH, "M")
39+
40+
# Create marks distances that should be all different
41+
dist = [marks[i] - marks[j] for i in range(1, ORDER) for j in range(0, i)]
42+
mdl.add(all_diff(dist))
43+
44+
# Avoid symmetric solutions by ordering marks
45+
mdl.add(marks[0] == 0)
46+
for i in range(1, ORDER):
47+
mdl.add(marks[i] > marks[i - 1])
48+
49+
# Avoid mirror solution
50+
mdl.add((marks[1] - marks[0]) < (marks[ORDER - 1] - marks[ORDER - 2]))
51+
52+
# Minimize ruler size (position of the last mark)
53+
minexpr = minimize(marks[ORDER - 1])
54+
mdl.add(minexpr)
55+
56+
# Call propagation
57+
solver = CpoSolver(mdl)
58+
try:
59+
msol = solver.propagate()
60+
msol.print_solution()
61+
except CpoNotSupportedException:
62+
print("The configured solver agent does not support propagation.")

examples/cp/jupyter/sched_square.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@
277277
},
278278
"outputs": [],
279279
"source": [
280-
"mdl.add(always_in(rx, 0, SIZE_SQUARE, SIZE_SQUARE, SIZE_SQUARE))\n",
281-
"mdl.add(always_in(ry, 0, SIZE_SQUARE, SIZE_SQUARE, SIZE_SQUARE))"
280+
"mdl.add(always_in(rx, (0, SIZE_SQUARE), SIZE_SQUARE, SIZE_SQUARE))\n",
281+
"mdl.add(always_in(ry, (0, SIZE_SQUARE), SIZE_SQUARE, SIZE_SQUARE))"
282282
]
283283
},
284284
{

examples/cp/visu/sched_RCPSP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
resources[j] += pulse(tasks[i], demands[i][j])
8080
for j in range(nbResources):
8181
# mdl.add(resources[j]<=capacities[j])
82-
mdl.add(always_in(resources[j], INTERVAL_MIN, INTERVAL_MAX, 0, capacities[j]))
82+
mdl.add(always_in(resources[j], (INTERVAL_MIN, INTERVAL_MAX), 0, capacities[j]))
8383

8484

8585
# Add minimization objective

examples/cp/visu/sched_RCPSPMM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def demand_non_renewable(self):
175175

176176
for j in range(nb_renewable):
177177
# mdl.add(renewables[j]<=capRenewables[j])
178-
mdl.add(always_in(renewables[j], INTERVAL_MIN, INTERVAL_MAX, 0, cap_renewables[j]))
178+
mdl.add(always_in(renewables[j], (INTERVAL_MIN, INTERVAL_MAX), 0, cap_renewables[j]))
179179

180180
for j in range(nb_non_renewable):
181181
mdl.add(non_renewables[j] <= cap_non_renewables[j])

examples/cp/visu/sched_cumul.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def make_house(loc, rd):
122122
# mdl.add(workers_usage <= NB_WORKERS)
123123
# mdl.add(0 <= cash)
124124

125-
mdl.add(always_in(workers_usage, INTERVAL_MIN, INTERVAL_MAX, 0, NB_WORKERS))
126-
mdl.add(always_in(cash, INTERVAL_MIN, INTERVAL_MAX, 0, INT_MAX))
125+
mdl.add(always_in(workers_usage, (INTERVAL_MIN, INTERVAL_MAX), 0, NB_WORKERS))
126+
mdl.add(always_in(cash, (INTERVAL_MIN, INTERVAL_MAX), 0, INT_MAX))
127127

128128
# Add minimization objective
129129
mdl.add(minimize(max([end_of(task) for task in all_tasks])))

examples/cp/visu/sched_square.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
| (end_of(y[i]) <= start_of(y[j]))
6464
| (end_of(y[j]) <= start_of(y[i])))
6565

66-
mdl.add(always_in(rx, 0, SIZE_SQUARE, SIZE_SQUARE, SIZE_SQUARE))
67-
mdl.add(always_in(ry, 0, SIZE_SQUARE, SIZE_SQUARE, SIZE_SQUARE))
66+
mdl.add(always_in(rx, (0, SIZE_SQUARE), SIZE_SQUARE, SIZE_SQUARE))
67+
mdl.add(always_in(ry, (0, SIZE_SQUARE), SIZE_SQUARE, SIZE_SQUARE))
6868

6969
# Define search phases
7070
mdl.set_search_phases([search_phase(x), search_phase(y)])

examples/cp/visu/sched_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def make_house(loc, rd):
137137

138138
# TODO:
139139
# mdl.add(workersUsage <= nbWorkers)
140-
mdl.add(always_in(workers_usage, INTERVAL_MIN, INTERVAL_MAX, 0, NB_WORKERS))
140+
mdl.add(always_in(workers_usage, (INTERVAL_MIN, INTERVAL_MAX), 0, NB_WORKERS))
141141

142142
# Add minimization objective
143143
mdl.add(minimize(max([end_of(task) for task in all_tasks])))

examples/mp/jupyter/chicago_coffee_shops.ipynb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@
154154
"This code snippet represents library \"**3401 W. Foster Avenue**\" located at **41.975456, -87.71409**\n"
155155
]
156156
},
157+
{
158+
"cell_type": "markdown",
159+
"metadata": {},
160+
"source": [
161+
"Disclaimer:\n",
162+
"This site provides applications using data that has been modified for use from its original source, www.cityofchicago.org, the official website of the City of Chicago. The City of Chicago makes no claims as to the content, accuracy, timeliness, or completeness of any of the data provided at this site. The data provided at this site is subject to change at any time. It is understood that the data provided at this site is being used at one’s own risk."
163+
]
164+
},
157165
{
158166
"cell_type": "markdown",
159167
"metadata": {
@@ -677,23 +685,24 @@
677685
}
678686
],
679687
"metadata": {
688+
"anaconda-cloud": {},
680689
"celltoolbar": "Dashboard",
681690
"kernelspec": {
682-
"display_name": "Python 2",
691+
"display_name": "Python [conda root]",
683692
"language": "python",
684-
"name": "python2"
693+
"name": "conda-root-py"
685694
},
686695
"language_info": {
687696
"codemirror_mode": {
688697
"name": "ipython",
689-
"version": 2.0
698+
"version": 3
690699
},
691700
"file_extension": ".py",
692701
"mimetype": "text/x-python",
693702
"name": "python",
694703
"nbconvert_exporter": "python",
695-
"pygments_lexer": "ipython2",
696-
"version": "2.7.10"
704+
"pygments_lexer": "ipython3",
705+
"version": "3.5.2"
697706
}
698707
},
699708
"nbformat": 4,

examples/mp/modeling/sport_scheduling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ def print_sports_solution(mdl):
144144
with get_environment().get_output_stream("solution.json") as fp:
145145
model.solution.export(fp, "json")
146146
else:
147-
print("Problem has no solution")
147+
print("Problem could not be solved: " + model.get_solve_details().get_status())

examples/mp/workflow/cutstock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99

1010
from docplex.util.environment import get_environment
11-
from docplex.mp.model import AbstractModel
11+
from docplex.mp.absmodel import AbstractModel
1212

1313
# ------------------------------
1414

0 commit comments

Comments
 (0)