-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxes.html
397 lines (388 loc) · 27 KB
/
boxes.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Objects in boxes — DOcplex.MP: Mathematical Programming Modeling for Python V2.14 documentation</title>
<link rel="stylesheet" href="_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/bizstyle.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Finding optimal locations of new stores" href="chicago_coffee_shops.html" />
<link rel="prev" title="load_balancing.py" href="load_balancing.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!--[if lt IE 9]>
<script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="chicago_coffee_shops.html" title="Finding optimal locations of new stores"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="load_balancing.html" title="load_balancing.py"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">DOcplex.MP: Mathematical Programming Modeling for Python V2.14 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="samples.html" accesskey="U">Examples of mathematical programming</a> »</li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Objects in boxes</a><ul>
<li><a class="reference internal" href="#describe-the-business-problem">Describe the business problem</a></li>
<li><a class="reference internal" href="#how-decision-optimization-can-help">How decision optimization can help</a></li>
<li><a class="reference internal" href="#use-decision-optimization">Use decision optimization</a><ul>
<li><a class="reference internal" href="#step-1-import-the-library">Step 1: Import the library</a></li>
<li><a class="reference internal" href="#step-2-model-the-data">Step 2: Model the data</a></li>
<li><a class="reference internal" href="#step-3-prepare-the-data">Step 3: Prepare the data</a></li>
<li><a class="reference internal" href="#step-4-set-up-the-prescriptive-model">Step 4: Set up the prescriptive model</a><ul>
<li><a class="reference internal" href="#create-the-docplex-model">Create the DOcplex model</a></li>
<li><a class="reference internal" href="#define-the-decision-variables">Define the decision variables</a></li>
<li><a class="reference internal" href="#express-the-business-constraints">Express the business constraints</a></li>
<li><a class="reference internal" href="#express-the-objective">Express the objective</a></li>
<li><a class="reference internal" href="#solve-the-model">Solve the model</a></li>
<li><a class="reference internal" href="#additional-constraint-1">Additional constraint #1</a></li>
<li><a class="reference internal" href="#additional-constraint-2">Additional constraint #2</a></li>
</ul>
</li>
<li><a class="reference internal" href="#step-5-investigate-the-solution-and-then-run-an-example-analysis">Step 5: Investigate the solution and then run an example analysis</a></li>
</ul>
</li>
<li><a class="reference internal" href="#summary">Summary</a></li>
<li><a class="reference internal" href="#references">References</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="load_balancing.html"
title="previous chapter">load_balancing.py</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="chicago_coffee_shops.html"
title="next chapter">Finding optimal locations of new stores</a></p>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="objects-in-boxes">
<h1>Objects in boxes<a class="headerlink" href="#objects-in-boxes" title="Permalink to this headline">¶</a></h1>
<p>This tutorial includes everything you need to set up IBM Decision
Optimization CPLEX Modeling for Python (DOcplex), build a Mathematical
Programming model, and get its solution by solving the model on the
cloud with IBM ILOG CPLEX Optimizer.</p>
<p>When you finish this tutorial, you’ll have a foundational knowledge of
<em>Prescriptive Analytics</em>.</p>
<blockquote>
<div><p>This notebook is part of <a class="reference external" href="http://ibmdecisionoptimization.github.io/docplex-doc/">Prescriptive Analytics for
Python</a></p>
<p>It requires either an <a class="reference external" href="http://ibmdecisionoptimization.github.io/docplex-doc/getting_started.html">installation of CPLEX
Optimizers</a>
or it can be run on <a class="reference external" href="https://www.ibm.com/cloud/watson-studio/">IBM Watson Studio
Cloud</a> (Sign up for a
<a class="reference external" href="https://dataplatform.cloud.ibm.com/registration/stepone?context=wdp&apps=all%3E">free IBM Cloud
account</a>
and you can start using Watson Studio Cloud right away).</p>
</div></blockquote>
<p>Table of contents:</p>
<ul class="simple">
<li><a class="reference internal" href="#describe-the-business-problem">Describe the business problem</a></li>
<li><a class="reference internal" href="#how-decision-optimization-can-help">How decision optimization can help</a></li>
<li><a class="reference internal" href="#use-decision-optimization">Use decision optimization</a><ul>
<li><a class="reference internal" href="#step-1-import-the-library">Step 1: Import the library</a></li>
<li><a class="reference internal" href="#step-2-model-the-data">Step 2: Model the data</a></li>
<li><a class="reference internal" href="#step-3-prepare-the-data">Step 3: Prepare the data</a></li>
<li><a class="reference internal" href="#step-4-set-up-the-prescriptive-model">Step 4: Set up the prescriptive model</a><ul>
<li><a class="reference internal" href="#define-the-decision-variables">Define the decision variables</a></li>
<li><a class="reference internal" href="#express-the-business-constraints">Express the business constraints</a></li>
<li><a class="reference internal" href="#express-the-objective">Express the objective</a></li>
<li><a class="reference internal" href="#solve-the-model">Solve the model</a></li>
</ul>
</li>
<li><a class="reference internal" href="#step-5-investigate-the-solution-and-then-run-an-example-analysis">Step 5: Investigate the solution and then run an example analysis</a></li>
</ul>
</li>
<li><a class="reference internal" href="#summary">Summary</a></li>
</ul>
<hr class="docutils" />
<div class="section" id="describe-the-business-problem">
<h2>Describe the business problem<a class="headerlink" href="#describe-the-business-problem" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li>We wish to put <span class="math notranslate nohighlight">\(N\)</span> objects which are scattered in the plane,
into a row of <span class="math notranslate nohighlight">\(N\)</span> boxes.</li>
<li>Boxes are aligned from left to right (if <span class="math notranslate nohighlight">\(i < i'\)</span>, box
<span class="math notranslate nohighlight">\(i\)</span> is to the left of box <span class="math notranslate nohighlight">\(i'\)</span>) on the <span class="math notranslate nohighlight">\(x\)</span> axis.</li>
<li>Box <span class="math notranslate nohighlight">\(i\)</span> is located at a point <span class="math notranslate nohighlight">\(B_i\)</span> of the <span class="math notranslate nohighlight">\((x,y)\)</span>
plane and object <span class="math notranslate nohighlight">\(j\)</span> is located at <span class="math notranslate nohighlight">\(O_j\)</span>.</li>
<li>We want to find an arrangement of objects such that:<ul>
<li>each box contains exactly one object,</li>
<li>each object is stored in one box,</li>
<li>the total distance from object <span class="math notranslate nohighlight">\(j\)</span> to its storage box is
minimal.</li>
</ul>
</li>
<li>First, we solve the problem described, and then we add two new
constraints and examine how the cost (and solution) changes.<ul>
<li>From the first solution, we impose that object #1 is assigned to
the box immediately to the left of object #2.</li>
<li>Then we impose that object #5 is assigned to a box next to the box
of object #6.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="how-decision-optimization-can-help">
<h2>How decision optimization can help<a class="headerlink" href="#how-decision-optimization-can-help" title="Permalink to this headline">¶</a></h2>
<ul>
<li><p class="first">Prescriptive analytics (decision optimization) technology recommends
actions that are based on desired outcomes. It takes into account
specific scenarios, resources, and knowledge of past and current
events. With this insight, your organization can make better
decisions and have greater control of business outcomes.</p>
</li>
<li><p class="first">Prescriptive analytics is the next step on the path to insight-based
actions. It creates value through synergy with predictive analytics,
which analyzes data to predict future outcomes.</p>
</li>
<li><div class="first line-block">
<div class="line">Prescriptive analytics takes that insight to the next level by
suggesting the optimal way to handle that future situation.
Organizations that can act fast in dynamic conditions and make
superior decisions in uncertain environments gain a strong
competitive advantage.</div>
<div class="line"><br /></div>
</div>
</li>
</ul>
<p>With prescriptive analytics, you can:</p>
<ul class="simple">
<li>Automate the complex decisions and trade-offs to better manage your
limited resources.</li>
<li>Take advantage of a future opportunity or mitigate a future risk.</li>
<li>Proactively update recommendations based on changing events.</li>
<li>Meet operational goals, increase customer loyalty, prevent threats
and fraud, and optimize business processes.</li>
</ul>
</div>
<div class="section" id="use-decision-optimization">
<h2>Use decision optimization<a class="headerlink" href="#use-decision-optimization" title="Permalink to this headline">¶</a></h2>
<div class="section" id="step-1-import-the-library">
<h3>Step 1: Import the library<a class="headerlink" href="#step-1-import-the-library" title="Permalink to this headline">¶</a></h3>
<p>Run the following code to import the Decision Optimization CPLEX
Modeling library. The <em>DOcplex</em> library contains the two modeling
packages, Mathematical Programming and Constraint Programming, referred
to earlier.</p>
<p>If <em>CPLEX</em> is not installed, install CPLEX Community edition.</p>
</div>
<div class="section" id="step-2-model-the-data">
<h3>Step 2: Model the data<a class="headerlink" href="#step-2-model-the-data" title="Permalink to this headline">¶</a></h3>
<p>The input data is the number of objects (and boxes) <em>N</em>, and their
positions in the (x,y) plane.</p>
</div>
<div class="section" id="step-3-prepare-the-data">
<h3>Step 3: Prepare the data<a class="headerlink" href="#step-3-prepare-the-data" title="Permalink to this headline">¶</a></h3>
<p>We use Euclidean distance to compute the distance between an object and
its assigned box.</p>
</div>
<div class="section" id="step-4-set-up-the-prescriptive-model">
<h3>Step 4: Set up the prescriptive model<a class="headerlink" href="#step-4-set-up-the-prescriptive-model" title="Permalink to this headline">¶</a></h3>
<pre class="literal-block">
* system is: Windows 64bit
* Python version 3.7.3, located at: c:\local\python373\python.exe
* docplex is present, version is (2, 11, 0)
* pandas is present, version is 0.25.1
</pre>
<div class="section" id="create-the-docplex-model">
<h4>Create the DOcplex model<a class="headerlink" href="#create-the-docplex-model" title="Permalink to this headline">¶</a></h4>
<p>The model contains all the business constraints and defines the
objective.</p>
</div>
<div class="section" id="define-the-decision-variables">
<h4>Define the decision variables<a class="headerlink" href="#define-the-decision-variables" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>For each box <span class="math notranslate nohighlight">\(i\)</span> (<span class="math notranslate nohighlight">\(i\)</span> in <span class="math notranslate nohighlight">\(1..N\)</span>) and object
<span class="math notranslate nohighlight">\(j\)</span> (<span class="math notranslate nohighlight">\(j\)</span> in <span class="math notranslate nohighlight">\(1..N\)</span>), we define a binary variable
<span class="math notranslate nohighlight">\(X_{i,j}\)</span> equal to <span class="math notranslate nohighlight">\(1\)</span> if and only if object <span class="math notranslate nohighlight">\(j\)</span> is
stored in box <span class="math notranslate nohighlight">\(i\)</span>.</li>
</ul>
</div>
<div class="section" id="express-the-business-constraints">
<h4>Express the business constraints<a class="headerlink" href="#express-the-business-constraints" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>The sum of <span class="math notranslate nohighlight">\(X_{i,j}\)</span> over both rows and columns must be equal
to <span class="math notranslate nohighlight">\(1\)</span>, resulting in <span class="math notranslate nohighlight">\(2\times N\)</span> constraints.</li>
</ul>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Model</span><span class="p">:</span> <span class="n">boxes</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">variables</span><span class="p">:</span> <span class="mi">225</span>
<span class="o">-</span> <span class="n">binary</span><span class="o">=</span><span class="mi">225</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">continuous</span><span class="o">=</span><span class="mi">0</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">constraints</span><span class="p">:</span> <span class="mi">30</span>
<span class="o">-</span> <span class="n">linear</span><span class="o">=</span><span class="mi">30</span>
<span class="o">-</span> <span class="n">parameters</span><span class="p">:</span> <span class="n">defaults</span>
<span class="o">-</span> <span class="n">problem</span> <span class="nb">type</span> <span class="ow">is</span><span class="p">:</span> <span class="n">MILP</span>
</pre></div>
</div>
</div>
<div class="section" id="express-the-objective">
<h4>Express the objective<a class="headerlink" href="#express-the-objective" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>The objective is to minimize the total distance between each object
and its storage box.</li>
</ul>
</div>
<div class="section" id="solve-the-model">
<h4>Solve the model<a class="headerlink" href="#solve-the-model" title="Permalink to this headline">¶</a></h4>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Model</span><span class="p">:</span> <span class="n">boxes</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">variables</span><span class="p">:</span> <span class="mi">225</span>
<span class="o">-</span> <span class="n">binary</span><span class="o">=</span><span class="mi">225</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">continuous</span><span class="o">=</span><span class="mi">0</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">constraints</span><span class="p">:</span> <span class="mi">30</span>
<span class="o">-</span> <span class="n">linear</span><span class="o">=</span><span class="mi">30</span>
<span class="o">-</span> <span class="n">parameters</span><span class="p">:</span> <span class="n">defaults</span>
<span class="o">-</span> <span class="n">problem</span> <span class="nb">type</span> <span class="ow">is</span><span class="p">:</span> <span class="n">MILP</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">*</span> <span class="n">model</span> <span class="n">boxes</span> <span class="n">solved</span> <span class="k">with</span> <span class="n">objective</span> <span class="o">=</span> <span class="mi">8858</span>
<span class="o">*</span> <span class="n">solution</span><span class="p">:</span> <span class="p">[</span><span class="mi">15</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">13</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="additional-constraint-1">
<h4>Additional constraint #1<a class="headerlink" href="#additional-constraint-1" title="Permalink to this headline">¶</a></h4>
<p>As an additional constraint, we want to impose that object #1 is stored
immediately to the left of object #2. As a consequence, object #2 cannot
be stored in box #1, so we add:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">docplex</span><span class="o">.</span><span class="n">mp</span><span class="o">.</span><span class="n">LinearConstraint</span><span class="p">[](</span><span class="n">x_1_2</span><span class="p">,</span><span class="n">EQ</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<p>Now, we must state that for <span class="math notranslate nohighlight">\(k \geq 2\)</span> if <span class="math notranslate nohighlight">\(x[k,2] == 1\)</span> then
<span class="math notranslate nohighlight">\(x[k-1,1] == 1\)</span>; this is a logical implication that we express by
a relational operator:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Model</span><span class="p">:</span> <span class="n">boxes</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">variables</span><span class="p">:</span> <span class="mi">225</span>
<span class="o">-</span> <span class="n">binary</span><span class="o">=</span><span class="mi">225</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">continuous</span><span class="o">=</span><span class="mi">0</span>
<span class="o">-</span> <span class="n">number</span> <span class="n">of</span> <span class="n">constraints</span><span class="p">:</span> <span class="mi">45</span>
<span class="o">-</span> <span class="n">linear</span><span class="o">=</span><span class="mi">45</span>
<span class="o">-</span> <span class="n">parameters</span><span class="p">:</span> <span class="n">defaults</span>
<span class="o">-</span> <span class="n">problem</span> <span class="nb">type</span> <span class="ow">is</span><span class="p">:</span> <span class="n">MILP</span>
</pre></div>
</div>
<p>Now let’s solve again and check that our new constraint is satisfied,
that is, object #1 is immediately left to object #2</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">*</span> <span class="n">model</span> <span class="n">boxes</span> <span class="n">solved</span> <span class="k">with</span> <span class="n">objective</span> <span class="o">=</span> <span class="mi">8878</span>
<span class="n">solution</span> <span class="c1">#2 =[15, 11, 14, 4, 8, 12, 7, 9, 10, 3, 6, 13, 1, 2, 5]</span>
</pre></div>
</div>
<p>The constraint is indeed satisfied, with a higher objective, as
expected.</p>
</div>
<div class="section" id="additional-constraint-2">
<h4>Additional constraint #2<a class="headerlink" href="#additional-constraint-2" title="Permalink to this headline">¶</a></h4>
<p>Now, we want to add a second constraint to state that object #5 is
stored in a box that is next to the box of object #6, either to the left
or right.</p>
<p>In other words, when <span class="math notranslate nohighlight">\(x[k,6]\)</span> is equal to <span class="math notranslate nohighlight">\(1\)</span>, then one of
<span class="math notranslate nohighlight">\(x[k-1,5]\)</span> and <span class="math notranslate nohighlight">\(x[k+1,5]\)</span> is equal to <span class="math notranslate nohighlight">\(1\)</span>; this is
again a logical implication, with an OR in the right side.</p>
<p>We have to handle the case of extremities with care.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">*</span> <span class="n">model</span> <span class="n">boxes</span> <span class="n">solved</span> <span class="k">with</span> <span class="n">objective</span> <span class="o">=</span> <span class="mi">9078</span>
<span class="n">solution</span> <span class="c1">#3 =[15, 11, 14, 4, 8, 12, 7, 9, 10, 3, 13, 6, 5, 1, 2]</span>
</pre></div>
</div>
<p>As expected, the constraint is satisfied; objects #5 and #6 are next to
each other. Predictably, the objective is higher.</p>
</div>
</div>
<div class="section" id="step-5-investigate-the-solution-and-then-run-an-example-analysis">
<h3>Step 5: Investigate the solution and then run an example analysis<a class="headerlink" href="#step-5-investigate-the-solution-and-then-run-an-example-analysis" title="Permalink to this headline">¶</a></h3>
<p>Present the solution as a vector of object indices, sorted by box
indices. We use maptplotlib to display the assignment of objects to
boxes.</p>
<p>The first solution shows no segments crossing, which is to be expected.</p>
<img alt="_images/boxes_35_0.png" src="_images/boxes_35_0.png" />
<p>The second solution, by enforcing that object #1 must be to the left of
object #2, introduces crossings.</p>
<img alt="_images/boxes_37_0.png" src="_images/boxes_37_0.png" />
<img alt="_images/boxes_38_0.png" src="_images/boxes_38_0.png" />
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">'d1'</span><span class="p">,</span> <span class="mi">858</span><span class="p">),</span> <span class="p">(</span><span class="s1">'d2'</span><span class="p">,</span> <span class="mi">878</span><span class="p">),</span> <span class="p">(</span><span class="s1">'d3'</span><span class="p">,</span> <span class="mi">1078</span><span class="p">)])</span>
</pre></div>
</div>
<img alt="_images/boxes_39_1.png" src="_images/boxes_39_1.png" />
</div>
</div>
<div class="section" id="summary">
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p>You learned how to set up and use IBM Decision Optimization CPLEX
Modeling for Python to formulate a Mathematical Programming model and
solve it with CPLEX.</p>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><a class="reference external" href="http://ibmdecisionoptimization.github.io/docplex-doc/">CPLEX Modeling for Python
documentation</a></li>
<li><a class="reference external" href="https://developer.ibm.com/docloud/">Decision Optimization on
Cloud</a></li>
<li>Need help with DOcplex or to report a bug? Please go
<a class="reference external" href="https://stackoverflow.com/questions/tagged/docplex">here</a>.</li>
<li>Contact us at <a class="reference external" href="mailto:dofeedback%40wwpdl.vnet.ibm.com">dofeedback<span>@</span>wwpdl<span>.</span>vnet<span>.</span>ibm<span>.</span>com</a>.</li>
</ul>
<p>Copyright ? 2017-2019 IBM. IPLA licensed Sample Materials.</p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="chicago_coffee_shops.html" title="Finding optimal locations of new stores"
>next</a> |</li>
<li class="right" >
<a href="load_balancing.html" title="load_balancing.py"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">DOcplex.MP: Mathematical Programming Modeling for Python V2.14 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="samples.html" >Examples of mathematical programming</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2016-2019, IBM®.
</div>
</body>
</html>