Doc automatic update
@@ -1,4 +1,24 @@
|
||||
|
||||
v.0.1.5: (2012-04-30 12:46:04)
|
||||
------------------------------
|
||||
* Major changes in the scripts to generate the doc:
|
||||
- the scripts have been completely rewritten and the directories
|
||||
completely rearranged.
|
||||
* Minor enhancements to the manual:
|
||||
- html version: several graphic enhancements.
|
||||
- preface: comments from Hakan (Thanks again and again! ;-) )
|
||||
- chap2:
|
||||
+ table with cryptarithmetic puzzle improved in both version.
|
||||
+ figures "at a glance" done anew.
|
||||
+ comments from Hakan.
|
||||
* FAQ:
|
||||
- several graphic enhancements.
|
||||
* Tutorials:
|
||||
- few corrections in the C++ code.
|
||||
* Lab sessions:
|
||||
- chap2: questions posted.
|
||||
|
||||
|
||||
v.0.1.4: (2012-04-23 22:55:42)
|
||||
------------------------------
|
||||
* Major changes in the scripts to generate the doc:
|
||||
|
||||
@@ -72,17 +72,24 @@ Thank you very much.
|
||||
<h2>What's new?</h2>
|
||||
<hr>
|
||||
<p id="new">Here is a little summary:</p>
|
||||
<pre id="verbatim">v.0.1.4: (2012-04-23 22:55:42)
|
||||
<pre id="verbatim">v.0.1.5: (2012-04-30 12:46:04)
|
||||
------------------------------
|
||||
* Major changes in the scripts to generate the doc:
|
||||
- the scripts have been completely rewritten and the directories
|
||||
completely rearranged.
|
||||
* Minor enhancements to the manual:
|
||||
chap3:
|
||||
- a lots of small improvements from Hakan (Thanks again!).
|
||||
- some images resized in html version.
|
||||
- html version: several graphic enhancements.
|
||||
- preface: comments from Hakan (Thanks again and again! ;-) )
|
||||
- chap2:
|
||||
+ table with cryptarithmetic puzzle improved in both version.
|
||||
+ figures "at a glance" done anew.
|
||||
+ comments from Hakan.
|
||||
* FAQ:
|
||||
- several graphic enhancements.
|
||||
* Tutorials:
|
||||
- few corrections in the C++ code.
|
||||
* Lab sessions:
|
||||
- chap2: questions posted.
|
||||
|
||||
</pre>
|
||||
|
||||
@@ -97,9 +104,9 @@ Thank you very much.
|
||||
<ul>
|
||||
<li>Progress at a glance: <a href="#manual_progress">Manual</a> - <a href="#documentation_progress">Documentation generation</a></li>
|
||||
<li><a href="user_manual/index.html">Online version</a></li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual_A4.v.0.1.4.pdf.zip">A4 pdf version</a></li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual_USletter.v.0.1.4.pdf.zip">Letter pdf version</a></li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual.v.0.1.4.epub.zip">epub version</a> (experimental)</li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual_A4.v.0.1.5.pdf.zip">A4 pdf version</a></li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual_USletter.v.0.1.5.pdf.zip">Letter pdf version</a></li>
|
||||
<li class="manual_download"><a href="http://or-tools.googlecode.com/files/user_manual.v.0.1.5.epub.zip">epub version</a> (experimental)</li>
|
||||
</ul>
|
||||
|
||||
<h4 id="progress">Progress at a glance:</h4>
|
||||
@@ -341,8 +348,8 @@ Thank you very much.
|
||||
<td>Documentation hub</td>
|
||||
<td>
|
||||
<div class="progress_background">
|
||||
<div class="progress_foreground_green" style="width:95%;">
|
||||
<span>95%</span>
|
||||
<div class="progress_foreground_green" style="width:100%;">
|
||||
<span>100%</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
Before Width: | Height: | Size: 155 KiB |
BIN
documentation/user_manual/_images/anatomy1_2.png
Normal file
|
After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 58 KiB |
BIN
documentation/user_manual/_images/anatomy3_4.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 294 B After Width: | Height: | Size: 316 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 202 B |
|
Before Width: | Height: | Size: 423 B After Width: | Height: | Size: 447 B |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 457 B After Width: | Height: | Size: 479 B |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 470 B |
|
Before Width: | Height: | Size: 483 B After Width: | Height: | Size: 505 B |
|
Before Width: | Height: | Size: 411 B After Width: | Height: | Size: 431 B |
|
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 212 B |
|
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 339 B |
|
Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 261 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 567 B After Width: | Height: | Size: 589 B |
|
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 279 B |
|
Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 261 B |
|
Before Width: | Height: | Size: 330 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 193 B After Width: | Height: | Size: 215 B |
|
Before Width: | Height: | Size: 492 B After Width: | Height: | Size: 516 B |
|
Before Width: | Height: | Size: 444 B After Width: | Height: | Size: 466 B |
|
Before Width: | Height: | Size: 577 B After Width: | Height: | Size: 610 B |
|
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 367 B |
|
Before Width: | Height: | Size: 456 B After Width: | Height: | Size: 478 B |
|
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 288 B |
|
Before Width: | Height: | Size: 713 B After Width: | Height: | Size: 741 B |
|
Before Width: | Height: | Size: 390 B After Width: | Height: | Size: 412 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 202 B |
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 318 B |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 304 B |
|
Before Width: | Height: | Size: 347 B After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 320 B After Width: | Height: | Size: 342 B |
|
Before Width: | Height: | Size: 293 B After Width: | Height: | Size: 315 B |
|
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 261 B |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 274 B |
|
Before Width: | Height: | Size: 316 B After Width: | Height: | Size: 339 B |
|
Before Width: | Height: | Size: 622 B After Width: | Height: | Size: 650 B |
|
Before Width: | Height: | Size: 594 B After Width: | Height: | Size: 618 B |
|
Before Width: | Height: | Size: 750 B After Width: | Height: | Size: 769 B |
|
Before Width: | Height: | Size: 409 B After Width: | Height: | Size: 428 B |
|
Before Width: | Height: | Size: 381 B After Width: | Height: | Size: 403 B |
|
Before Width: | Height: | Size: 975 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 458 B After Width: | Height: | Size: 482 B |
|
Before Width: | Height: | Size: 752 B After Width: | Height: | Size: 732 B |
|
Before Width: | Height: | Size: 209 B After Width: | Height: | Size: 231 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 338 B After Width: | Height: | Size: 360 B |
|
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 201 B |
|
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 256 B |
|
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 379 B After Width: | Height: | Size: 401 B |
|
Before Width: | Height: | Size: 466 B After Width: | Height: | Size: 488 B |
|
Before Width: | Height: | Size: 284 B After Width: | Height: | Size: 302 B |
|
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 456 B |
|
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 165 B |
|
Before Width: | Height: | Size: 175 B After Width: | Height: | Size: 197 B |
|
Before Width: | Height: | Size: 332 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 318 B |
|
Before Width: | Height: | Size: 184 B After Width: | Height: | Size: 206 B |
|
Before Width: | Height: | Size: 405 B After Width: | Height: | Size: 427 B |
|
Before Width: | Height: | Size: 214 B After Width: | Height: | Size: 236 B |
|
Before Width: | Height: | Size: 418 B After Width: | Height: | Size: 440 B |
|
Before Width: | Height: | Size: 388 B After Width: | Height: | Size: 410 B |
|
Before Width: | Height: | Size: 330 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 720 B After Width: | Height: | Size: 744 B |
|
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 484 B |
|
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 458 B |
@@ -169,7 +169,7 @@ and how to use the full potential of our library.</p>
|
||||
<span id="foreword-will-not-learn"></span><h2>What you will not learn in this document</h2>
|
||||
<p>This document is by no means a tutorial on Operations Research nor on Contraint Programming.
|
||||
It is also NOT a reference manual (refer to the documentation hub to find the reference manual).
|
||||
There are way too many methods, parameters, functions, . . . to explain them all in details. Once
|
||||
There are way too many methods, parameters, functions, etc. to explain them all in details. Once
|
||||
you understand the concepts and methods explained in this manual, you shouldn’t have any
|
||||
trouble scanning the reference manual and find the right method, parameter, function, . . . or code
|
||||
them yourselves!</p>
|
||||
@@ -177,7 +177,8 @@ them yourselves!</p>
|
||||
questions about the non-CP part of the library, don’t hesitate to ask them on the mailing list. See
|
||||
the section <a class="reference internal" href="#how-to-reach-us">How to reach us?</a> below.</p>
|
||||
<p>This document will not describe how to use the library (and the syntactic sugar introduced when
|
||||
possible) with Python, Java nor C#. This could possibly change in the future.</p>
|
||||
possible) with <tt class="docutils literal"><span class="pre">Python</span></tt>, <tt class="docutils literal"><span class="pre">Java</span></tt> nor <tt class="docutils literal"><span class="pre">C#</span></tt>. This could possibly change in the future. The tutorial examples
|
||||
(see below) exist also in <tt class="docutils literal"><span class="pre">Python</span></tt>, <tt class="docutils literal"><span class="pre">Java</span></tt> and <tt class="docutils literal"><span class="pre">C#</span></tt> though.</p>
|
||||
</div>
|
||||
<div class="section" id="how-to-read-this-document">
|
||||
<span id="foreword-how-read"></span><h2>How to read this document?</h2>
|
||||
@@ -190,7 +191,7 @@ probably the most efficient and rewarding one!</p>
|
||||
<p>That said, the manual is kept short so that you can read it in its entirety. The first part (<em>Basics</em>)
|
||||
is an introduction on how to use the CP solver to solve small problems. For real problems, you
|
||||
need to customize your search and this is explained in the second part (<em>Customization</em>). If you are
|
||||
interested in the routing part of the library, the third part if for you (<em>Routing</em>). Finally, some utilities
|
||||
interested in the routing part of the library, the third part is for you (<em>Routing</em>). Finally, some utilities
|
||||
and tricks are explained in the appendices.</p>
|
||||
</div>
|
||||
<div class="section" id="targeted-audience">
|
||||
|
||||
@@ -71,8 +71,8 @@ about the other supported languages (Python, Java and C#).</p>
|
||||
steps to write a basic program.</p>
|
||||
<p class="rubric">Prerequisites:</p>
|
||||
<ul class="simple">
|
||||
<li>Some basic knowledge of C++.</li>
|
||||
<li>Some basic knowledge of Constraint Programming (see chapter <a class="reference internal" href="introduction.html#chapter-introduction"><em>Introduction to constraint programming</em></a>).</li>
|
||||
<li>basic knowledge of C++.</li>
|
||||
<li>basic knowledge of Constraint Programming (see chapter <a class="reference internal" href="introduction.html#chapter-introduction"><em>Introduction to constraint programming</em></a>).</li>
|
||||
</ul>
|
||||
<p class="rubric">Files:</p>
|
||||
<p>You can find the code in the directory <tt class="docutils literal"><span class="pre">documentation/tutorials/C++/chap2</span></tt>.</p>
|
||||
|
||||
@@ -63,8 +63,8 @@ the cryptarithmetic puzzle in C++. In the next chapters, we will cover some of t
|
||||
in more details.</p>
|
||||
<div class="section" id="at-a-glance">
|
||||
<span id="anatomy-at-a-glance"></span><h2>2.3.1. At a glance</h2>
|
||||
<img alt="../../_images/anatomy1.png" src="../../_images/anatomy1.png" style="height: 500pt;" />
|
||||
<img alt="../../_images/anatomy2.png" src="../../_images/anatomy2.png" style="height: 250pt;" />
|
||||
<img alt="../../_images/anatomy1_2.png" src="../../_images/anatomy1_2.png" style="width: 400pt;" />
|
||||
<img alt="../../_images/anatomy3_4.png" src="../../_images/anatomy3_4.png" style="width: 350pt;" />
|
||||
</div>
|
||||
<div class="section" id="headers">
|
||||
<h2>2.3.2. Headers</h2>
|
||||
@@ -75,7 +75,13 @@ in more details.</p>
|
||||
</div>
|
||||
<p>The header <tt class="docutils literal"><span class="pre">logging.h</span></tt> is needed for some logging facilities and some
|
||||
assert-like macros. The header <tt class="docutils literal"><span class="pre">constraint_solver.h</span></tt> is the main entry point
|
||||
to the CP solver and must be includedfootnote{Directly or indirectly when it is included in another header you include.} whenever you intend to use it.</p>
|
||||
to the CP solver and must be included<a class="footnote-reference" href="#including-headers" id="id1">[1]</a> whenever you intend to use it.</p>
|
||||
<table class="docutils footnote" frame="void" id="including-headers" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Directly or indirectly when it is included in another header you include.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section" id="the-namespace-operations-research">
|
||||
<span id="index-0"></span><h2>2.3.3. The namespace <tt class="docutils literal"><span class="pre">operations_research</span></tt></h2>
|
||||
@@ -95,7 +101,7 @@ the same convention in all our examples and code inside this namespace:</p>
|
||||
<p><tt class="docutils literal"><span class="pre">MakeBaseLine2</span></tt>, <tt class="docutils literal"><span class="pre">MakeBaseLine3</span></tt> and <tt class="docutils literal"><span class="pre">MakeBaseLine4</span></tt> are helper functions to create the model.</p>
|
||||
<p>We detail these functions later in <a class="reference internal" href="#constraints"><em>Constraints</em></a> but for the moment,
|
||||
let’s concentrate on <tt class="docutils literal"><span class="pre">CPIsFun()</span></tt> where all the magic happens.</p>
|
||||
<p>It is called from the main<a class="footnote-reference" href="#main-not-inside-namespace" id="id1">[1]</a>
|
||||
<p>It is called from the main<a class="footnote-reference" href="#main-not-inside-namespace" id="id2">[2]</a>
|
||||
function:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">operations_research</span><span class="o">::</span><span class="n">CPIsFun</span><span class="p">();</span>
|
||||
@@ -106,7 +112,7 @@ function:</p>
|
||||
<table class="docutils footnote" frame="void" id="main-not-inside-namespace" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>The main function does not lie inside the namespace
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>The main function does not lie inside the namespace
|
||||
<tt class="docutils literal"><span class="pre">operations_research</span></tt>, hence the use of the <tt class="docutils literal"><span class="pre">operations_research</span></tt> identifier to call
|
||||
the function <tt class="docutils literal"><span class="pre">CPIsFun()</span></tt>.</td></tr>
|
||||
</tbody>
|
||||
@@ -135,11 +141,11 @@ functionalities.</p>
|
||||
<span class="n">IntVar</span><span class="o">*</span> <span class="k">const</span> <span class="n">e</span> <span class="o">=</span> <span class="n">solver</span><span class="p">.</span><span class="n">MakeIntVar</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">kBase</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="s">"E"</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p id="index-3">For each letter, we create an integer variable <tt class="docutils literal"><span class="pre">IntVar</span></tt> whose domain is <img class="math" src="../../_images/math/eec74ab2ca83865096af94ada03733d24295a2f2.png" alt="[0,\mathtt{kBase} - 1]"/>
|
||||
<p id="index-3">For each letter, we create an integer variable <tt class="docutils literal"><span class="pre">IntVar</span></tt> whose domain is <img class="math" src="../../_images/math/eec74ab2ca83865096af94ada03733d24295a2f2.png" alt="[0,\mathtt{kBase} - 1]" style="vertical-align: -5px"/>
|
||||
except for the variables <tt class="docutils literal"><span class="pre">c</span></tt>, <tt class="docutils literal"><span class="pre">i</span></tt>, <tt class="docutils literal"><span class="pre">f</span></tt> and <tt class="docutils literal"><span class="pre">t</span></tt> that cannot take the value <tt class="docutils literal"><span class="pre">0</span></tt>.
|
||||
The <tt class="docutils literal"><span class="pre">MakeIntVar(i,</span> <span class="pre">j,</span> <span class="pre">name)</span></tt> method is a <em>factory method</em> that creates an
|
||||
integer variable whose domain is <img class="math" src="../../_images/math/8f76a4c9b2e1d0a7eb2016aefa4a26a464143d12.png" alt="[i,j]=\{i, i+1, \dotsc
|
||||
, j-1, j\}"/> and has a name <tt class="docutils literal"><span class="pre">name</span></tt>. It returns a pointer to an <tt class="docutils literal"><span class="pre">IntVar</span></tt>. The declaration <tt class="docutils literal"><span class="pre">IntVar*</span> <span class="pre">const</span> <span class="pre">c</span></tt>
|
||||
, j-1, j\}" style="vertical-align: -5px"/> and has a name <tt class="docutils literal"><span class="pre">name</span></tt>. It returns a pointer to an <tt class="docutils literal"><span class="pre">IntVar</span></tt>. The declaration <tt class="docutils literal"><span class="pre">IntVar*</span> <span class="pre">const</span> <span class="pre">c</span></tt>
|
||||
may seem a little be complicated at first. It is easier to understand if read from right to left: <tt class="docutils literal"><span class="pre">c</span></tt> is a constant pointer to an
|
||||
<tt class="docutils literal"><span class="pre">IntVar</span></tt>. We can modify the object pointed by <tt class="docutils literal"><span class="pre">c</span></tt> but this pointer, because it is constant, always refers to the same object.</p>
|
||||
<div class="topic" id="index-4">
|
||||
@@ -154,12 +160,12 @@ them appropriately.</p>
|
||||
<p class="first admonition-title">Warning</p>
|
||||
<p class="last">Never delete explicitly an object created by
|
||||
a factory method! First, the solver deletes all the objects for you.
|
||||
Second, deleting a pointer twice in C++ gives undefined behaviour<a class="footnote-reference" href="#dont-delete-pointers" id="id2">[2]</a>!</p>
|
||||
Second, deleting a pointer twice in C++ gives undefined behaviour<a class="footnote-reference" href="#dont-delete-pointers" id="id3">[3]</a>!</p>
|
||||
</div>
|
||||
<table class="docutils footnote" frame="void" id="dont-delete-pointers" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>It is possible to bypass the undefined behaviour but you don’t know what the solver needs to do, so keep your hands off of the object pointers! ;-)</td></tr>
|
||||
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>It is possible to bypass the undefined behaviour but you don’t know what the solver needs to do, so keep your hands off of the object pointers! ;-)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Beside integer variables, the solver provides factory methods to create
|
||||
@@ -184,13 +190,14 @@ Aborted</pre>
|
||||
<p>In <a class="reference internal" href="../utilities/asserting.html#asserting"><em>Asserting</em></a>, we cover assert-like macros in more details.</p>
|
||||
</div>
|
||||
<div class="section" id="constraints">
|
||||
<span id="index-5"></span><span id="id3"></span><h2>2.3.7. Constraints</h2>
|
||||
<p>To create a integer linear constraint, we need to know how to multiply an integer variable
|
||||
<span id="index-5"></span><span id="id4"></span><h2>2.3.7. Constraints</h2>
|
||||
<p>To create an integer linear constraint, we need to know how to multiply an integer variable
|
||||
with an integer constant and how to add two integer variables. We have seen that
|
||||
the solver creates a variable and only provides a pointer to that variable.
|
||||
The solver also provides factory methods to multiply an integer coefficient by
|
||||
an <tt class="docutils literal"><span class="pre">IntVar</span></tt> given by a pointer:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="n">IntVar</span><span class="o">*</span> <span class="k">const</span> <span class="n">var1</span> <span class="o">=</span> <span class="n">solver</span><span class="p">.</span><span class="n">MakeIntVar</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s">"Var1"</span><span class="p">);</span>
|
||||
<span class="c1">// var2 = var1 * 36</span>
|
||||
<span class="n">IntVar</span><span class="o">*</span> <span class="k">const</span> <span class="n">var2</span> <span class="o">=</span> <span class="n">solver</span><span class="p">.</span><span class="n">MakeProd</span><span class="p">(</span><span class="n">var1</span><span class="p">,</span><span class="mi">36</span><span class="p">)</span><span class="o">-></span><span class="n">Var</span><span class="p">();</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
@@ -202,7 +209,8 @@ any integer expression.</p>
|
||||
to an <tt class="docutils literal"><span class="pre">IntVar</span></tt> and then the integer constant.</p>
|
||||
<p>To add two <tt class="docutils literal"><span class="pre">IntVar</span></tt> given by their respective pointers, the solver provides
|
||||
again a factory method:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="n">IntVar</span><span class="o">*</span> <span class="k">const</span> <span class="n">var3</span> <span class="o">=</span> <span class="n">solver</span><span class="p">.</span><span class="n">MakeSum</span><span class="p">(</span><span class="n">var1</span><span class="p">,</span><span class="n">var2</span><span class="p">)</span><span class="o">-></span><span class="n">Var</span><span class="p">();</span>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="c1">//var3 = var1 + var2</span>
|
||||
<span class="n">IntVar</span><span class="o">*</span> <span class="k">const</span> <span class="n">var3</span> <span class="o">=</span> <span class="n">solver</span><span class="p">.</span><span class="n">MakeSum</span><span class="p">(</span><span class="n">var1</span><span class="p">,</span><span class="n">var2</span><span class="p">)</span><span class="o">-></span><span class="n">Var</span><span class="p">();</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="topic">
|
||||
|
||||
@@ -110,7 +110,7 @@ have different values in a feasible solution. Second, it is implicit that the fi
|
||||
digit of a number can not be 0. Letters <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> can thus
|
||||
not represent 0. Third, there are 10 letters, so we need at least 10
|
||||
different digits. The traditional decimal base is sufficient but let’s be more general
|
||||
and allow for a bigger base. We will use a constant <tt class="docutils literal"><span class="pre">kBase</span></tt>. This last constraint is not a CP constraint.
|
||||
and allow for a bigger base. We will use a constant <tt class="docutils literal"><span class="pre">kBase</span></tt>. The fact that we need at least 10 digits is not really a CP constraint.
|
||||
After all, the base is not a variable but a given integer that is chosen once
|
||||
and for all for the whole program<a class="footnote-reference" href="#base-not-var" id="id2">[2]</a>.</p>
|
||||
<table class="docutils footnote" frame="void" id="base-not-var" rules="none">
|
||||
@@ -127,17 +127,20 @@ puzzle has less than <tt class="docutils literal"><span class="pre">x</span></tt
|
||||
<p>For each letter, we have a decision variable (we keep the same letters to name the variables).
|
||||
Given a base <tt class="docutils literal"><span class="pre">b</span></tt>, digits range from 0 to <tt class="docutils literal"><span class="pre">b</span></tt>-1.
|
||||
Remember that variables corresponding to <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> should be different
|
||||
from 0. Thus <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> have <img class="math" src="../../_images/math/22b701bc2dd899be5eb627e42bb246b79917eadb.png" alt="[1,\mathtt{b}-1]"/> as domain and <tt class="docutils literal"><span class="pre">P</span></tt>, <tt class="docutils literal"><span class="pre">S</span></tt>, <tt class="docutils literal"><span class="pre">U</span></tt>, <tt class="docutils literal"><span class="pre">N</span></tt>, <tt class="docutils literal"><span class="pre">R</span></tt> and <tt class="docutils literal"><span class="pre">E</span></tt>
|
||||
have <img class="math" src="../../_images/math/02a1f06ac5198ee9c1210aaf6cda82150d29c04c.png" alt="[0,\mathtt{b}-1]"/> as domain. Another possibility is to keep the same domain <img class="math" src="../../_images/math/02a1f06ac5198ee9c1210aaf6cda82150d29c04c.png" alt="[0,\mathtt{b}-1]"/> for all
|
||||
variables and force <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> to be different from 0 by adding inequalities. However, restraining the domain to <img class="math" src="../../_images/math/22b701bc2dd899be5eb627e42bb246b79917eadb.png" alt="[1,\mathtt{b}-1]"/> is more efficient.</p>
|
||||
from 0. Thus <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> have <img class="math" src="../../_images/math/22b701bc2dd899be5eb627e42bb246b79917eadb.png" alt="[1,\mathtt{b}-1]" style="vertical-align: -5px"/> as domain and <tt class="docutils literal"><span class="pre">P</span></tt>, <tt class="docutils literal"><span class="pre">S</span></tt>, <tt class="docutils literal"><span class="pre">U</span></tt>, <tt class="docutils literal"><span class="pre">N</span></tt>, <tt class="docutils literal"><span class="pre">R</span></tt> and <tt class="docutils literal"><span class="pre">E</span></tt>
|
||||
have <img class="math" src="../../_images/math/02a1f06ac5198ee9c1210aaf6cda82150d29c04c.png" alt="[0,\mathtt{b}-1]" style="vertical-align: -5px"/> as domain. Another possibility is to keep the same domain <img class="math" src="../../_images/math/02a1f06ac5198ee9c1210aaf6cda82150d29c04c.png" alt="[0,\mathtt{b}-1]" style="vertical-align: -5px"/> for all
|
||||
variables and force <tt class="docutils literal"><span class="pre">C</span></tt>, <tt class="docutils literal"><span class="pre">I</span></tt>, <tt class="docutils literal"><span class="pre">F</span></tt> and <tt class="docutils literal"><span class="pre">T</span></tt> to be different from 0 by adding inequalities. However, restraining the domain to <img class="math" src="../../_images/math/22b701bc2dd899be5eb627e42bb246b79917eadb.png" alt="[1,\mathtt{b}-1]" style="vertical-align: -5px"/> is more efficient.</p>
|
||||
<p>To model the sum constraint in any base <tt class="docutils literal"><span class="pre">b</span></tt>, we add the linear equation:</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/af653c84a8859ae2494c58e015ad9e94231eb505.png" alt="\begin{align*}
|
||||
& & & & & {\color{blue}{\mathtt{C}}} \cdot \mathtt{b} & + & {\color{blue}{\mathtt{P}}}\\
|
||||
+ & & & & & {\color{blue}{\mathtt{I}}} \cdot \mathtt{b} & + & {\color{blue}{\mathtt{S}}}\\
|
||||
+ & & & {\color{blue}{\mathtt{F}}} \cdot \mathtt{b}^2 & + & {\color{blue}{\mathtt{U}}} \cdot \mathtt{b} & + & {\color{blue}{\mathtt{N}}}\\
|
||||
= & {\color{blue}{\mathtt{T}}} \cdot \mathtt{b}^3 & + & {\color{blue}{\mathtt{R}}} \cdot \mathtt{b}^2 & + & {\color{blue}{\mathtt{U}}} \cdot \mathtt{b} & + & {\color{blue}{\mathtt{E}}}.
|
||||
\end{align*}"/></p>
|
||||
<p><img src="../../_images/math/0d9f85ba90d8b2b497781f983ddd845cec6a2df2.png" alt="\begin{center}
|
||||
\begin{tabular}{cccccccc}
|
||||
& & & & + & ${\color{blue}{\mathtt{C}}} \cdot b$ & + & ${\color{blue}{\mathtt{P}}}$\\
|
||||
& & & & + & ${\color{blue}{\mathtt{I}}} \cdot b$ & + & ${\color{blue}{\mathtt{S}}}$\\
|
||||
& & + & ${\color{blue}{\mathtt{F}}} \cdot b^2$ & + & ${\color{blue}{\mathtt{U}}} \cdot b$ & + & ${\color{blue}{\mathtt{N}}}$\BStrut\\
|
||||
\hline
|
||||
= & ${\color{blue}{\mathtt{T}}} \cdot b^3$ & + & ${\color{blue}{\mathtt{R}}} \cdot b^2$ & + & ${\color{blue}{\mathtt{U}}} \cdot b$ & + & ${\color{blue}{\mathtt{E}}}\TStrut$
|
||||
\end{tabular}
|
||||
\end{center}"/></p>
|
||||
</div><p>The global constraint <tt class="docutils literal"><span class="pre">AllDifferent</span></tt> springs to mind to model that variables must all have different values:</p>
|
||||
<div class="highlight-cpp"><div class="highlight"><pre><span class="n">AllDifferent</span><span class="p">(</span><span class="n">C</span><span class="p">,</span><span class="n">P</span><span class="p">,</span><span class="n">I</span><span class="p">,</span><span class="n">S</span><span class="p">,</span><span class="n">F</span><span class="p">,</span><span class="n">U</span><span class="p">,</span><span class="n">N</span><span class="p">,</span><span class="n">T</span><span class="p">,</span><span class="n">R</span><span class="p">,</span><span class="n">E</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
@@ -200,8 +200,8 @@ also additional information. You can also act on some of the variables for insta
|
||||
<span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span> <span class="o"><<</span> <span class="s">"Number of solutions: "</span> <span class="o"><<</span> <span class="n">number_solutions</span> <span class="o"><<</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
|
||||
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">index</span> <span class="o"><</span> <span class="n">number_solutions</span><span class="p">;</span> <span class="o">++</span><span class="n">index</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">Assignment</span><span class="o">*</span> <span class="k">const</span> <span class="n">solution</span> <span class="o">=</span> <span class="n">all_solutions</span><span class="o">-></span><span class="n">solution</span><span class="p">(</span><span class="n">index</span><span class="p">);</span>
|
||||
<span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span> <span class="o"><<</span> <span class="s">"Solution found:"</span><span class="p">;</span>
|
||||
<span class="hll"> <span class="n">Assignment</span><span class="o">*</span> <span class="k">const</span> <span class="n">solution</span> <span class="o">=</span> <span class="n">all_solutions</span><span class="o">-></span><span class="n">solution</span><span class="p">(</span><span class="n">index</span><span class="p">);</span>
|
||||
</span> <span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span> <span class="o"><<</span> <span class="s">"Solution found:"</span><span class="p">;</span>
|
||||
<span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span> <span class="o"><<</span> <span class="s">"v1="</span> <span class="o"><<</span> <span class="n">solution</span><span class="o">-></span><span class="n">Value</span><span class="p">(</span><span class="n">v1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
|
||||
@@ -89,11 +89,11 @@ In fact, you can completely skip them if you wish. The basic ideas behind these
|
||||
<p>You can find the code in the directory <tt class="docutils literal"><span class="pre">documentation/tutorials/C++/chap3</span></tt>.</p>
|
||||
<p>The files inside this directory are:</p>
|
||||
<ul class="simple">
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb1.cc</span></tt>: A first implementation. We show how to tell the solver to optimize an objective function. We use the <img class="math" src="../_images/math/53404ad4af12519f95b03c74a1c7af0d609baa8e.png" alt="\frac{n(n-1)}{2}"/> differences as variables.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb1.cc</span></tt>: A first implementation. We show how to tell the solver to optimize an objective function. We use the <img class="math" src="../_images/math/53404ad4af12519f95b03c74a1c7af0d609baa8e.png" alt="\frac{n(n-1)}{2}" style="vertical-align: -6px"/> differences as variables.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb2.cc</span></tt>: Same file as <tt class="file docutils literal"><span class="pre">golomb1.cc</span></tt> but with some global statistics about the search added so we can see how well or bad
|
||||
a model behave.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb3.cc</span></tt>: A second implementation. This time, we only use the marks as variables and introduce the quaternary inequality constraints.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb4.cc</span></tt>: We improve the second implementation by reintroducing the <img class="math" src="../_images/math/53404ad4af12519f95b03c74a1c7af0d609baa8e.png" alt="\frac{n(n-1)}{2}"/> differences variables.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb4.cc</span></tt>: We improve the second implementation by reintroducing the <img class="math" src="../_images/math/53404ad4af12519f95b03c74a1c7af0d609baa8e.png" alt="\frac{n(n-1)}{2}" style="vertical-align: -6px"/> differences variables.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb5.cc</span></tt>: In this third implementation, we replace the inequality constraints by the more powerful globlal <tt class="docutils literal"><span class="pre">AllDifferent</span></tt> constraint.</li>
|
||||
<li><tt class="file docutils literal"><span class="pre">golomb6.cc</span></tt>: The last implementation is a tightening of the model used in the third implementation. We add better upper and lower bounds and break a symmetry in the search tree.</li>
|
||||
</ul>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<p>Most of the mathematical classes in or-tools inherit from the <tt class="docutils literal"><span class="pre">BaseObject</span></tt> class. Its only
|
||||
public method is a <tt class="docutils literal"><span class="pre">virtual</span> <span class="pre">DebugString()</span></tt>. If you are curious or just in doubt about
|
||||
the object you just constructed, <tt class="docutils literal"><span class="pre">DebugString()</span></tt> is for you.</p>
|
||||
<p>Let’s have a closer look at the constraints that model the inner structure of the Golomb ruler of order <img class="math" src="../../_images/math/79069377f91364c2f87a64e5f9f562a091c8a6c1.png" alt="5"/>:</p>
|
||||
<p>Let’s have a closer look at the constraints that model the inner structure of the Golomb ruler of order <img class="math" src="../../_images/math/79069377f91364c2f87a64e5f9f562a091c8a6c1.png" alt="5" style="vertical-align: 0px"/>:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="k">const</span> <span class="kt">int</span> <span class="n">n</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
|
||||
<span class="p">...</span>
|
||||
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
|
||||
@@ -136,7 +136,7 @@ the object you just constructed, <tt class="docutils literal"><span class="pre">
|
||||
<span class="o">(</span>2..48<span class="o">))</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The cast to transform the sum <img class="math" src="../../_images/math/80184e4cfaf5d02abb6c882519ae7ce64e8d8587.png" alt="Y_1 + Y_0"/> into an <tt class="docutils literal"><span class="pre">IntVar</span></tt>.</p>
|
||||
<p>The cast to transform the sum <img class="math" src="../../_images/math/80184e4cfaf5d02abb6c882519ae7ce64e8d8587.png" alt="Y_1 + Y_0" style="vertical-align: -4px"/> into an <tt class="docutils literal"><span class="pre">IntVar</span></tt>.</p>
|
||||
<p>And then:</p>
|
||||
<div class="highlight-bash"><div class="highlight"><pre>...: Y_4<span class="o">(</span>1..24<span class="o">)</span> <span class="o">==</span> Var<<span class="o">(</span>Y_1<span class="o">(</span>1..24<span class="o">)</span> + Y_0<span class="o">(</span>1..24<span class="o">))</span>><span class="o">(</span>2..48<span class="o">)</span>
|
||||
...: Y_5<span class="o">(</span>1..24<span class="o">)</span> <span class="o">==</span> Var<<span class="o">(</span>Y_2<span class="o">(</span>1..24<span class="o">)</span> + Y_1<span class="o">(</span>1..24<span class="o">))</span>><span class="o">(</span>2..48<span class="o">)</span>
|
||||
|
||||
@@ -80,7 +80,7 @@ library offers a basic but portable timer. This timer starts to measure the time
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>As its name implies, the time measured is the wall time, i.e. ... TO BE COMPLETED.</p>
|
||||
<p>For instance, on my computer, the program in <tt class="file docutils literal"><span class="pre">golomb1.cc</span></tt> for <img class="math" src="../../_images/math/1819f547a53f667e1a44a49ba2bec08c28d7f222.png" alt="n = 9"/> takes</p>
|
||||
<p>For instance, on my computer, the program in <tt class="file docutils literal"><span class="pre">golomb1.cc</span></tt> for <img class="math" src="../../_images/math/1819f547a53f667e1a44a49ba2bec08c28d7f222.png" alt="n = 9" style="vertical-align: 0px"/> takes</p>
|
||||
<div class="highlight-bash"><div class="highlight"><pre>Time: 4,773 seconds
|
||||
</pre></div>
|
||||
</div>
|
||||
|
||||
@@ -65,18 +65,18 @@
|
||||
<div class="section" id="an-upper-bound">
|
||||
<h2>3.3.1. An upper bound</h2>
|
||||
<p>Several upper bounds exist on Golomb rulers.
|
||||
For instance, we could take <img class="math" src="../../_images/math/6322338c6a88c2c42320ad37bef583ffeb23b0bb.png" alt="n^3 - 2n^2+ 2n -1"/>. Indeed, it can be
|
||||
For instance, we could take <img class="math" src="../../_images/math/6322338c6a88c2c42320ad37bef583ffeb23b0bb.png" alt="n^3 - 2n^2+ 2n -1" style="vertical-align: -1px"/>. Indeed, it can be
|
||||
shown that the sequence</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/a2008d79b75cc529cf35323b1a166a899f7dc312.png" alt="\Phi(a) = na^2 + a \qquad 0 \leqslant a < n."/></p>
|
||||
</div><p>forms a Golomb ruler. As its largest member is <img class="math" src="../../_images/math/6322338c6a88c2c42320ad37bef583ffeb23b0bb.png" alt="n^3 - 2n^2+ 2n -1"/> (when <img class="math" src="../../_images/math/70b2051e92267b47e16baf8a4805f448e79b8f98.png" alt="a = n - 1"/>), we have
|
||||
an upper bound on the length of a Golomb ruler of order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/>:</p>
|
||||
</div><p>forms a Golomb ruler. As its largest member is <img class="math" src="../../_images/math/6322338c6a88c2c42320ad37bef583ffeb23b0bb.png" alt="n^3 - 2n^2+ 2n -1" style="vertical-align: -1px"/> (when <img class="math" src="../../_images/math/70b2051e92267b47e16baf8a4805f448e79b8f98.png" alt="a = n - 1" style="vertical-align: -1px"/>), we have
|
||||
an upper bound on the length of a Golomb ruler of order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/>:</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/907352b70265a69f82789ffe38e58913c04dced6.png" alt="G(n) \leqslant n^3 - 2n^2+ 2n -1."/></p>
|
||||
</div><p>Most bounds are really bad and this one isn’t an exception. The great mathematician Paul Erdös conjectured that</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/26e627f0930e19476169f5e4c5c18251e33668b3.png" alt="G(n) < n^2."/></p>
|
||||
</div><p>This conjecture hasn’t been proved yet but computational evidence has shown that the conjecture holds for <img class="math" src="../../_images/math/fc53204fb8443e399c9cdd4a4d1008c574c1d87a.png" alt="n < 65000"/> (see <a class="reference internal" href="#dimitromanolakis2002">[Dimitromanolakis2002]</a>).</p>
|
||||
</div><p>This conjecture hasn’t been proved yet but computational evidence has shown that the conjecture holds for <img class="math" src="../../_images/math/fc53204fb8443e399c9cdd4a4d1008c574c1d87a.png" alt="n < 65000" style="vertical-align: 0px"/> (see <a class="reference internal" href="#dimitromanolakis2002">[Dimitromanolakis2002]</a>).</p>
|
||||
<table class="docutils citation" frame="void" id="dimitromanolakis2002" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
|
||||
@@ -73,21 +73,21 @@ illustrates a Golomb ruler of order 4 and all its - distinct - differences.</p>
|
||||
<img alt="A non optimal Golomb ruler of order 4." src="../../_images/golomb_4_non_optimal.png" />
|
||||
<p class="caption">A non optimal Golomb ruler of order 4.</p>
|
||||
</div>
|
||||
<p>The Golomb ruler is <img class="math" src="../../_images/math/656f4355e5c978684a86169e5444aed14fd00735.png" alt="\{0, 2, 7, 11\}"/> and its <em>length</em> is <img class="math" src="../../_images/math/c6878713578626763c38433b3f4c8c2205ad0c15.png" alt="11"/>. Because
|
||||
we are interested in Golomb rulers with minimal length, we can fix the first mark to <img class="math" src="../../_images/math/bc1f9d9bf8a1b606a4188b5ce9a2af1809e27a89.png" alt="0"/>.</p>
|
||||
<p>The Golomb ruler is <img class="math" src="../../_images/math/656f4355e5c978684a86169e5444aed14fd00735.png" alt="\{0, 2, 7, 11\}" style="vertical-align: -5px"/> and its <em>length</em> is <img class="math" src="../../_images/math/c6878713578626763c38433b3f4c8c2205ad0c15.png" alt="11" style="vertical-align: -1px"/>. Because
|
||||
we are interested in Golomb rulers with minimal length, we can fix the first mark to <img class="math" src="../../_images/math/bc1f9d9bf8a1b606a4188b5ce9a2af1809e27a89.png" alt="0" style="vertical-align: 0px"/>.</p>
|
||||
<p>Figure <a class="reference internal" href="#golomb-4-optimal"><em>An optimal Golomb ruler of order 4.</em></a>
|
||||
illustrates an optimal Golomb ruler of order 4 and all its - distinct - differences.</p>
|
||||
<div class="figure align-center" id="golomb-4-optimal">
|
||||
<img alt="An optimal Golomb ruler of order 4." src="../../_images/golomb_4_optimal.png" />
|
||||
<p class="caption">An optimal Golomb ruler of order 4.</p>
|
||||
</div>
|
||||
<p>Its length, <img class="math" src="../../_images/math/601a7806cbfad68196c43a4665871f8c3186802e.png" alt="6"/>, is optimal: it is not possible to construct a Golomb ruler with <img class="math" src="../../_images/math/c7cab1a05e1e0c1d51a6a219d96577a16b7abf9d.png" alt="4"/> marks with
|
||||
a length smaller than <img class="math" src="../../_images/math/601a7806cbfad68196c43a4665871f8c3186802e.png" alt="6"/>. We denote this optimal value by <img class="math" src="../../_images/math/d021efbf1bdc3991bcae725ecf641e473a84ad6a.png" alt="G(4) = 6"/>. More generally, for a
|
||||
Golomb ruler of order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/>, we denote by <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)"/> its optimal value. The <em>Golomb Ruler Problem (GRP)</em> is to find, for a given
|
||||
order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/>, the smallest Golomb ruler with <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/> marks.</p>
|
||||
<p>Its length, <img class="math" src="../../_images/math/601a7806cbfad68196c43a4665871f8c3186802e.png" alt="6" style="vertical-align: 0px"/>, is optimal: it is not possible to construct a Golomb ruler with <img class="math" src="../../_images/math/c7cab1a05e1e0c1d51a6a219d96577a16b7abf9d.png" alt="4" style="vertical-align: -1px"/> marks with
|
||||
a length smaller than <img class="math" src="../../_images/math/601a7806cbfad68196c43a4665871f8c3186802e.png" alt="6" style="vertical-align: 0px"/>. We denote this optimal value by <img class="math" src="../../_images/math/d021efbf1bdc3991bcae725ecf641e473a84ad6a.png" alt="G(4) = 6" style="vertical-align: -4px"/>. More generally, for a
|
||||
Golomb ruler of order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/>, we denote by <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)" style="vertical-align: -4px"/> its optimal value. The <em>Golomb Ruler Problem (GRP)</em> is to find, for a given
|
||||
order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/>, the smallest Golomb ruler with <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/> marks.</p>
|
||||
<p>You might be surprised to learn that
|
||||
the largest order for which the experts have found an optimal Golomb ruler so far is... <img class="math" src="../../_images/math/bda00d9a38a0c6bd9aac2512c6d065581882d43c.png" alt="26"/>. And it was a huge hunt involving hundreds of people!
|
||||
The next table compares the number of days, the number of participants on the Internet and the number of visited nodes in the search tree to find and prove <img class="math" src="../../_images/math/91b57f317a08928150981174b55863495f6b6d67.png" alt="G(24)"/>, <img class="math" src="../../_images/math/73cd37e4a19d777de33d09845672bf7430b7f2c9.png" alt="G(25)"/> and <img class="math" src="../../_images/math/e4654b3881c9f67ba35785b1027bc4e5f11de0a9.png" alt="G(26)"/><a class="footnote-reference" href="#ogr24" id="id1">[2]</a><a class="footnote-reference" href="#ogr25" id="id2">[3]</a><a class="footnote-reference" href="#ogr26" id="id3">[4]</a>.</p>
|
||||
the largest order for which the experts have found an optimal Golomb ruler so far is... <img class="math" src="../../_images/math/bda00d9a38a0c6bd9aac2512c6d065581882d43c.png" alt="26" style="vertical-align: 0px"/>. And it was a huge hunt involving hundreds of people!
|
||||
The next table compares the number of days, the number of participants on the Internet and the number of visited nodes in the search tree to find and prove <img class="math" src="../../_images/math/91b57f317a08928150981174b55863495f6b6d67.png" alt="G(24)" style="vertical-align: -4px"/>, <img class="math" src="../../_images/math/73cd37e4a19d777de33d09845672bf7430b7f2c9.png" alt="G(25)" style="vertical-align: -4px"/> and <img class="math" src="../../_images/math/e4654b3881c9f67ba35785b1027bc4e5f11de0a9.png" alt="G(26)" style="vertical-align: -4px"/><a class="footnote-reference" href="#ogr24" id="id1">[2]</a><a class="footnote-reference" href="#ogr25" id="id2">[3]</a><a class="footnote-reference" href="#ogr26" id="id3">[4]</a>.</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="13%" />
|
||||
@@ -120,7 +120,7 @@ The next table compares the number of days, the number of participants on the In
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>The search for <img class="math" src="../../_images/math/bf6fccb6e87ec7d41e0a872e346bc93e18b1f192.png" alt="G(27)"/> started on February 24, 2009 and at that time was expected to take... 7 years!
|
||||
<p>The search for <img class="math" src="../../_images/math/bf6fccb6e87ec7d41e0a872e346bc93e18b1f192.png" alt="G(27)" style="vertical-align: -4px"/> started on February 24, 2009 and at that time was expected to take... 7 years!
|
||||
Still think it is an easy<a class="footnote-reference" href="#gr-complexity" id="id4">[1]</a> problem? You too can participate: <a class="reference external" href="http://www.distributed.net/OGR">The OGR Project</a>.</p>
|
||||
<p>You can find all the known optimal Golomb rulers and more information on <a class="reference external" href="http://en.wikipedia.org/wiki/Golomb_ruler">Wikipedia</a>.</p>
|
||||
<table class="docutils footnote" frame="void" id="gr-complexity" rules="none">
|
||||
@@ -168,35 +168,35 @@ of a Golomb ruler. In information theory, Golomb rulers are used for error detec
|
||||
<div class="section" id="describe">
|
||||
<h3>3.2.2.1. Describe</h3>
|
||||
<p>What is the <strong>goal</strong> of the Golomb Ruler Problem? To find a minimal Golomb ruler for a given
|
||||
order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/>. Our objective function is the length of the ruler or the largest
|
||||
order <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/>. Our objective function is the length of the ruler or the largest
|
||||
integer in the Golomb ruler sequence.</p>
|
||||
<p>What are the <strong>decision variables</strong> (unknowns)? We have at least two choices. We can either view the unknowns
|
||||
as the marks of the ruler (and retrieve all the differences from these variables) or choose the unknowns to be the differences (and retrieve the marks).
|
||||
Let’s try this second approach and use the efficient <cite>AllDifferent</cite> constraint.
|
||||
There are <img class="math" src="../../_images/math/eb643c8ee8f3686fbaa86cf68eb7e8d4b281db6e.png" alt="\frac{n (n-1)}{2}"/> such differences.</p>
|
||||
There are <img class="math" src="../../_images/math/eb643c8ee8f3686fbaa86cf68eb7e8d4b281db6e.png" alt="\frac{n (n-1)}{2}" style="vertical-align: -6px"/> such differences.</p>
|
||||
<p>What are the <strong>constraints</strong>? Using the differences as variables, we need to construct a Golomb
|
||||
ruler, i.e. the structure of the Golomb ruler has to be respected (see next section).</p>
|
||||
</div>
|
||||
<div class="section" id="model">
|
||||
<h3>3.2.2.2. Model</h3>
|
||||
<p>For each positive difference, we have a decision variable. We collect them in
|
||||
an array <img class="math" src="../../_images/math/3667c72efcf1abf0a7359a5c297d4affd54b3ed2.png" alt="Y\hspace{-0.1cm}."/> Let’s order the differences so that we know which difference is represented by <img class="math" src="../../_images/math/50ae01c5c3fe117c6009a8784cd517f8036e6639.png" alt="Y[i]"/>.</p>
|
||||
an array <img class="math" src="../../_images/math/3667c72efcf1abf0a7359a5c297d4affd54b3ed2.png" alt="Y\hspace{-0.1cm}." style="vertical-align: 0px"/> Let’s order the differences so that we know which difference is represented by <img class="math" src="../../_images/math/50ae01c5c3fe117c6009a8784cd517f8036e6639.png" alt="Y[i]" style="vertical-align: -5px"/>.</p>
|
||||
<p>Figure <a class="reference internal" href="#gr-order1"><em>An ordered sequence of differences for the Golomb ruler of order 4.</em></a>
|
||||
illustrates an ordered sequence of differences for a Golomb ruler of order 4.</p>
|
||||
<div class="figure align-center" id="gr-order1">
|
||||
<img alt="An ordered sequence of differences for the Golomb ruler of order 4." src="../../_images/GR_order1.png" />
|
||||
<p class="caption">An ordered sequence of differences for the Golomb ruler of order 4.</p>
|
||||
</div>
|
||||
<p>We want to minimize the last difference in <img class="math" src="../../_images/math/ce58e4af225c93d08606c26554caaa5ae32edeba.png" alt="Y"/> i.e. <img class="math" src="../../_images/math/9cecbbeba63daadf452b55fc1c51e38e31c10ac0.png" alt="Y[\frac{n (n-1)}{2}-1]"/> since the first index of an array is <img class="math" src="../../_images/math/bc1f9d9bf8a1b606a4188b5ce9a2af1809e27a89.png" alt="0"/>.
|
||||
When the order is <img class="math" src="../../_images/math/5218af40079081e694d8b82eeac2d368ef6ea76a.png" alt="n = 4"/>, we want to optimize <img class="math" src="../../_images/math/8f6f6f3b9065e970e7d5f9b684f7022229dcbd91.png" alt="Y[\frac{4 (4-1)}{2}-1] = Y[5]"/> which represents the <img class="math" src="../../_images/math/811408a46dd1a6f44fbc9f58c8b41b5f0f40f2df.png" alt="6^\textrm{th}"/> difference. Instead of writing <img class="math" src="../../_images/math/50ae01c5c3fe117c6009a8784cd517f8036e6639.png" alt="Y[i]"/>, we will also use the more convenient notation <img class="math" src="../../_images/math/d1e635eb590829b488cf300af12cf0bdda6dae03.png" alt="Y_i"/>.</p>
|
||||
<p>We want to minimize the last difference in <img class="math" src="../../_images/math/ce58e4af225c93d08606c26554caaa5ae32edeba.png" alt="Y" style="vertical-align: 0px"/> i.e. <img class="math" src="../../_images/math/9cecbbeba63daadf452b55fc1c51e38e31c10ac0.png" alt="Y[\frac{n (n-1)}{2}-1]" style="vertical-align: -6px"/> since the first index of an array is <img class="math" src="../../_images/math/bc1f9d9bf8a1b606a4188b5ce9a2af1809e27a89.png" alt="0" style="vertical-align: 0px"/>.
|
||||
When the order is <img class="math" src="../../_images/math/5218af40079081e694d8b82eeac2d368ef6ea76a.png" alt="n = 4" style="vertical-align: -1px"/>, we want to optimize <img class="math" src="../../_images/math/8f6f6f3b9065e970e7d5f9b684f7022229dcbd91.png" alt="Y[\frac{4 (4-1)}{2}-1] = Y[5]" style="vertical-align: -6px"/> which represents the <img class="math" src="../../_images/math/811408a46dd1a6f44fbc9f58c8b41b5f0f40f2df.png" alt="6^\textrm{th}" style="vertical-align: 0px"/> difference. Instead of writing <img class="math" src="../../_images/math/50ae01c5c3fe117c6009a8784cd517f8036e6639.png" alt="Y[i]" style="vertical-align: -5px"/>, we will also use the more convenient notation <img class="math" src="../../_images/math/d1e635eb590829b488cf300af12cf0bdda6dae03.png" alt="Y_i" style="vertical-align: -3px"/>.</p>
|
||||
<p>Figure <a class="reference internal" href="#gr-first-sum"><em>The inner structure of a Golomb ruler of order 5.</em></a>
|
||||
illustrates the structure than must be respected for a Golomb ruler of order 5. To impose the inner structure of the Golomb Ruler,
|
||||
we force <img class="math" src="../../_images/math/90fb0c8e5c45e248d9a1f8b1d1e76022f55307d2.png" alt="Y_4 = Y_0 + Y_1"/>, <img class="math" src="../../_images/math/2d3b9cf7c6dea44441c0051389430ee8280f4fa7.png" alt="Y_5 = Y_1 + Y_2"/> and so on as illustrated in Figure <a class="reference internal" href="#gr-first-sum"><em>The inner structure of a Golomb ruler of order 5.</em></a>.</p>
|
||||
we force <img class="math" src="../../_images/math/90fb0c8e5c45e248d9a1f8b1d1e76022f55307d2.png" alt="Y_4 = Y_0 + Y_1" style="vertical-align: -4px"/>, <img class="math" src="../../_images/math/2d3b9cf7c6dea44441c0051389430ee8280f4fa7.png" alt="Y_5 = Y_1 + Y_2" style="vertical-align: -4px"/> and so on as illustrated in Figure <a class="reference internal" href="#gr-first-sum"><em>The inner structure of a Golomb ruler of order 5.</em></a>.</p>
|
||||
<div class="figure align-center" id="gr-first-sum">
|
||||
<img alt="The inner structure of a Golomb ruler of order 5." src="../../_images/GR_first_sum.png" />
|
||||
<p class="caption">The inner structure of a Golomb ruler of order 5.</p>
|
||||
</div>
|
||||
<p>An easy way to construct these equality constraints is to use an index <cite>index</cite> going from <img class="math" src="../../_images/math/c7cab1a05e1e0c1d51a6a219d96577a16b7abf9d.png" alt="4"/> to <img class="math" src="../../_images/math/bf2c9074b396e3af0dea52d792660eea1c77f10f.png" alt="9"/><a class="footnote-reference" href="#explanation-index-4-to-9" id="id6">[5]</a>, an
|
||||
<p>An easy way to construct these equality constraints is to use an index <cite>index</cite> going from <img class="math" src="../../_images/math/c7cab1a05e1e0c1d51a6a219d96577a16b7abf9d.png" alt="4" style="vertical-align: -1px"/> to <img class="math" src="../../_images/math/bf2c9074b396e3af0dea52d792660eea1c77f10f.png" alt="9" style="vertical-align: 0px"/><a class="footnote-reference" href="#explanation-index-4-to-9" id="id6">[5]</a>, an
|
||||
index <cite>i</cite> to count the number of terms in a given equality and an index <cite>j</cite> to indicate the rank of the starting term in each
|
||||
equality:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">index</span> <span class="o">=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">;</span>
|
||||
@@ -212,7 +212,7 @@ equality:</p>
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id6">[5]</a></td><td>Or more generally from the index of the first difference that is the sum of two differences in our sequence
|
||||
<img class="math" src="../../_images/math/7955459cf8b75c3ac12c23c393024177d7d56412.png" alt="(n-1)"/> to the index of the last difference <img class="math" src="../../_images/math/4eb116b498702e1fcf175d2b1e5641edfe5d0221.png" alt="\left( \frac{n(n-1)}{2} - 1 \right)"/>.</td></tr>
|
||||
<img class="math" src="../../_images/math/7955459cf8b75c3ac12c23c393024177d7d56412.png" alt="(n-1)" style="vertical-align: -4px"/> to the index of the last difference <img class="math" src="../../_images/math/4eb116b498702e1fcf175d2b1e5641edfe5d0221.png" alt="\left( \frac{n(n-1)}{2} - 1 \right)" style="vertical-align: -13px"/>.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -56,8 +56,8 @@
|
||||
|
||||
<div class="section" id="a-second-model-and-its-implementation">
|
||||
<span id="golomb-ruler-second-implementation"></span><h1>3.6. A second model and its implementation</h1>
|
||||
<p>Our first model is really bad. One of the reasons is that we use too many variables: <img class="math" src="../../_images/math/eb643c8ee8f3686fbaa86cf68eb7e8d4b281db6e.png" alt="\frac{n (n-1)}{2}"/> differences.
|
||||
What happens if we only consider the <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n"/> marks as variables instead of the differences?</p>
|
||||
<p>Our first model is really bad. One of the reasons is that we use too many variables: <img class="math" src="../../_images/math/eb643c8ee8f3686fbaa86cf68eb7e8d4b281db6e.png" alt="\frac{n (n-1)}{2}" style="vertical-align: -6px"/> differences.
|
||||
What happens if we only consider the <img class="math" src="../../_images/math/174fadd07fd54c9afe288e96558c92e0c1da733a.png" alt="n" style="vertical-align: 0px"/> marks as variables instead of the differences?</p>
|
||||
<div class="section" id="variables">
|
||||
<h2>3.6.1. Variables</h2>
|
||||
<p>You can find the code in the file <a class="reference external" href="../../../tutorials/C++/chap3/golomb3.cc">tutorials/C++/chap3/golomb3.cc</a></p>
|
||||
@@ -70,7 +70,7 @@ In the same vain, we redefine the array <tt class="docutils literal"><span class
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>We use an <tt class="docutils literal"><span class="pre">std::vector</span></tt> slightly bigger (by one more element) than absolutely necessary. Because the solver doesn’t allow NULL pointers, we have
|
||||
to assign a value to <tt class="docutils literal"><span class="pre">X[0]</span></tt>. The first mark <tt class="docutils literal"><span class="pre">X[1]</span></tt> is <tt class="docutils literal"><span class="pre">0</span></tt>. We use again <img class="math" src="../../_images/math/884c12c8169b77e2bb8f0b522112c34aa5c41ac4.png" alt="n^2 - 1"/> as an upper bound for the marks:</p>
|
||||
to assign a value to <tt class="docutils literal"><span class="pre">X[0]</span></tt>. The first mark <tt class="docutils literal"><span class="pre">X[1]</span></tt> is <tt class="docutils literal"><span class="pre">0</span></tt>. We use again <img class="math" src="../../_images/math/884c12c8169b77e2bb8f0b522112c34aa5c41ac4.png" alt="n^2 - 1" style="vertical-align: -1px"/> as an upper bound for the marks:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// Upper bound on G(n), only valid for n <= 65 000</span>
|
||||
<span class="n">CHECK_LE</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">65000</span><span class="p">);</span>
|
||||
<span class="k">const</span> <span class="n">int64</span> <span class="n">max</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
|
||||
@@ -93,15 +93,15 @@ to assign a value to <tt class="docutils literal"><span class="pre">X[0]</span><
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td><em>Quaternary constraints</em> is just a fancy way to say that the constraints each involves four variables.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>We don’t need all combinations of <img class="math" src="../../_images/math/1802156f8c045c22ccbfaead68d03f8bb45d2659.png" alt="(i,j,k,l)"/> with <img class="math" src="../../_images/math/cdb5a7c36506631cce673e83f91f85c5ae55c604.png" alt="i \neq k"/> and <img class="math" src="../../_images/math/7a03116e0235065914fdb54d1b30c5d6383cdf43.png" alt="j \neq l"/>. For instance, combination <img class="math" src="../../_images/math/21ef0b34f891eda9d44a9ec8f96fb7f860d55925.png" alt="(3,2,6,4)"/>
|
||||
and combination <img class="math" src="../../_images/math/6c3eabdda7802e47a6fb72984f523bf152ef5dfd.png" alt="(2,3,4,6)"/> would both give the same constraint. One way to avoid such redundancy is to impose an order on unique positive differences<a class="footnote-reference" href="#avoid-redundancy-unique-difference" id="id2">[2]</a>.</p>
|
||||
<p>We don’t need all combinations of <img class="math" src="../../_images/math/1802156f8c045c22ccbfaead68d03f8bb45d2659.png" alt="(i,j,k,l)" style="vertical-align: -4px"/> with <img class="math" src="../../_images/math/cdb5a7c36506631cce673e83f91f85c5ae55c604.png" alt="i \neq k" style="vertical-align: -4px"/> and <img class="math" src="../../_images/math/7a03116e0235065914fdb54d1b30c5d6383cdf43.png" alt="j \neq l" style="vertical-align: -4px"/>. For instance, combination <img class="math" src="../../_images/math/21ef0b34f891eda9d44a9ec8f96fb7f860d55925.png" alt="(3,2,6,4)" style="vertical-align: -4px"/>
|
||||
and combination <img class="math" src="../../_images/math/6c3eabdda7802e47a6fb72984f523bf152ef5dfd.png" alt="(2,3,4,6)" style="vertical-align: -4px"/> would both give the same constraint. One way to avoid such redundancy is to impose an order on unique positive differences<a class="footnote-reference" href="#avoid-redundancy-unique-difference" id="id2">[2]</a>.</p>
|
||||
<table class="docutils footnote" frame="void" id="avoid-redundancy-unique-difference" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>In section <a class="reference internal" href="tighten_model.html#breaking-symmetries"><em>Breaking symmetries</em></a> we’ll use another trick.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Take again <img class="math" src="../../_images/math/39cf3e35a4981583288d2a7c4b34989916fb7360.png" alt="n=4"/> and define the sequence of differences as in Figure <a class="reference internal" href="#gr-order2"><em>Another ordered sequence of differences for the Golomb ruler of order 4.</em></a>.</p>
|
||||
<p>Take again <img class="math" src="../../_images/math/39cf3e35a4981583288d2a7c4b34989916fb7360.png" alt="n=4" style="vertical-align: -1px"/> and define the sequence of differences as in Figure <a class="reference internal" href="#gr-order2"><em>Another ordered sequence of differences for the Golomb ruler of order 4.</em></a>.</p>
|
||||
<div class="figure align-center" id="gr-order2">
|
||||
<img alt="Another ordered sequence of differences for the Golomb ruler of order 4." src="../../_images/GR_order2.png" />
|
||||
<p class="caption">Another ordered sequence of differences for the Golomb ruler of order 4.</p>
|
||||
@@ -119,7 +119,7 @@ and so on as suggested in Figure <a class="reference internal" href="#gr-quatern
|
||||
<img alt="How to generate the quaternary constraints, part II." src="../../_images/GR_quaternary_generation2.png" />
|
||||
<p class="caption">How to generate the quaternary constraints, part II.</p>
|
||||
</div>
|
||||
<p>We define a helper function that, given a difference <img class="math" src="../../_images/math/887919dfbc86eebc29e0373f98f97dbf23a0ae23.png" alt="(i,j)"/> corresponding to an interval <img class="math" src="../../_images/math/de3d6be914b10a36aa1a46bdc0d2b7587b58ebf0.png" alt="X[j] - X[i]"/> computes the next difference in the sequence:</p>
|
||||
<p>We define a helper function that, given a difference <img class="math" src="../../_images/math/887919dfbc86eebc29e0373f98f97dbf23a0ae23.png" alt="(i,j)" style="vertical-align: -4px"/> corresponding to an interval <img class="math" src="../../_images/math/de3d6be914b10a36aa1a46bdc0d2b7587b58ebf0.png" alt="X[j] - X[i]" style="vertical-align: -5px"/> computes the next difference in the sequence:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">next_interval</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="k">const</span> <span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="k">const</span> <span class="kt">int</span> <span class="n">j</span><span class="p">,</span> <span class="kt">int</span><span class="o">*</span> <span class="n">next_i</span><span class="p">,</span>
|
||||
<span class="kt">int</span><span class="o">*</span> <span class="n">next_j</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">CHECK_LT</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">);</span>
|
||||
@@ -171,10 +171,10 @@ and so on as suggested in Figure <a class="reference internal" href="#gr-quatern
|
||||
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>Remember again the remark at the beginning of this chapter about the tricky sums.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Note that we set the minimum value of the difference to <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">diff1->SetMin(1)</span></tt>, to ensure that the differences are positive and <img class="math" src="../../_images/math/a972d7535636c34ce7a0b44e80109d15288a72f6.png" alt="\geqslant 1"/>. Note also that the method
|
||||
<p>Note that we set the minimum value of the difference to <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">diff1->SetMin(1)</span></tt>, to ensure that the differences are positive and <img class="math" src="../../_images/math/a972d7535636c34ce7a0b44e80109d15288a72f6.png" alt="\geqslant 1" style="vertical-align: -3px"/>. Note also that the method
|
||||
<tt class="docutils literal"><span class="pre">MakeDifference()</span></tt> doesn’t allow us to give a name to the new variable, which is normal as this new variable is the difference of two
|
||||
existing variables. Its name is simply <tt class="docutils literal"><span class="pre">name1</span> <span class="pre">-</span> <span class="pre">name2</span></tt>.</p>
|
||||
<p>Let’s compare the first and second implementation. The next table compares some global indicators about the search for <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)"/>.</p>
|
||||
<p>Let’s compare the first and second implementation. The next table compares some global indicators about the search for <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)" style="vertical-align: -4px"/>.</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="37%" />
|
||||
@@ -236,7 +236,7 @@ existing variables. Its name is simply <tt class="docutils literal"><span class=
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>and compare this improved version with the two others, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)"/>:</p>
|
||||
<p>and compare this improved version with the two others, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)" style="vertical-align: -4px"/>:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="28%" />
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
<div class="section" id="summary">
|
||||
<span id="golomb-ruler-summary"></span><h1>3.10. Summary</h1>
|
||||
<p>Not a good approach. For example with our tightened implementation 3 we need <tt class="docutils literal"><span class="pre">35.679</span></tt> seconds to solve <img class="math" src="../../_images/math/7f3c0d03225cdc3cc82b59a8f511bfdd34dcadcc.png" alt="G(11)"/>.</p>
|
||||
<p>Not a good approach. For example with our tightened implementation 3 we need <tt class="docutils literal"><span class="pre">35.679</span></tt> seconds to solve <img class="math" src="../../_images/math/7f3c0d03225cdc3cc82b59a8f511bfdd34dcadcc.png" alt="G(11)" style="vertical-align: -4px"/>.</p>
|
||||
<p>Further reading: see <a class="reference internal" href="#smithetal">[SmithEtAl]</a></p>
|
||||
<table class="docutils citation" frame="void" id="smithetal" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
|
||||
@@ -71,7 +71,7 @@ propagations of the “quaternary constraints”. But these constraints
|
||||
<span class="n">s</span><span class="p">.</span><span class="n">AddConstraint</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">MakeAllDifferent</span><span class="p">(</span><span class="n">Y</span><span class="p">));</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>and compare our three implementations, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)"/>:</p>
|
||||
<p>and compare our three implementations, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)" style="vertical-align: -4px"/>:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="22%" />
|
||||
|
||||
@@ -117,8 +117,8 @@ representing the marks of a Golomb ruler, we implicitly took for granted that <t
|
||||
<tr><td class="label"><a class="fn-backref" href="#id4">[3]</a></td><td>Declaring variables in an <tt class="docutils literal"><span class="pre">std::vector</span></tt> doesn’t tell anything about their respective values!</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Thanks to <tt class="docutils literal"><span class="pre">diff1->SetMin(1)</span></tt> and <tt class="docutils literal"><span class="pre">diff2->SetMin(1)</span></tt> and the two <tt class="docutils literal"><span class="pre">for</span></tt> loops, the ordered variables <img class="math" src="../../_images/math/65b572143ef64e24707414197ab3ff0acaf95aa3.png" alt="X[1], X[2], X[3], X[4]"/>
|
||||
have only increasing values, i.e. if <img class="math" src="../../_images/math/c1d952598000cf900d21f6e5054c1fc4237d2282.png" alt="i \leqslant j"/> then <img class="math" src="../../_images/math/29679f51e9632ea0ee4845b2e4b3ec86ae837bec.png" alt="X[i] \leqslant X[j]"/>. Solutions <a href="#equation-solution1">(1)</a> and <a href="#equation-solution2">(2)</a> are said to be symmetric and avoiding the second one while accepting the first one is called <em>breaking symmetry</em>.</p>
|
||||
<p>Thanks to <tt class="docutils literal"><span class="pre">diff1->SetMin(1)</span></tt> and <tt class="docutils literal"><span class="pre">diff2->SetMin(1)</span></tt> and the two <tt class="docutils literal"><span class="pre">for</span></tt> loops, the ordered variables <img class="math" src="../../_images/math/65b572143ef64e24707414197ab3ff0acaf95aa3.png" alt="X[1], X[2], X[3], X[4]" style="vertical-align: -5px"/>
|
||||
have only increasing values, i.e. if <img class="math" src="../../_images/math/c1d952598000cf900d21f6e5054c1fc4237d2282.png" alt="i \leqslant j" style="vertical-align: -4px"/> then <img class="math" src="../../_images/math/29679f51e9632ea0ee4845b2e4b3ec86ae837bec.png" alt="X[i] \leqslant X[j]" style="vertical-align: -5px"/>. Solutions <a href="#equation-solution1">(1)</a> and <a href="#equation-solution2">(2)</a> are said to be symmetric and avoiding the second one while accepting the first one is called <em>breaking symmetry</em>.</p>
|
||||
<p>There is a well-known symmetry in the Golomb Ruler Problem that we didn’t break. Whenever you have a Golomb ruler, there exist another Golomb
|
||||
ruler with the same length that is called the <em>mirror ruler</em>.</p>
|
||||
<p>Figure <a class="reference internal" href="#golomb-4-mirror"><em>Two mirror Golomb rulers of order 4.</em></a>
|
||||
@@ -127,7 +127,7 @@ illustrates two mirror Golomb rulers of order 4.</p>
|
||||
<img alt="Two mirror Golomb rulers of order 4." src="../../_images/golomb_4_mirror.png" />
|
||||
<p class="caption">Two mirror Golomb rulers of order 4.</p>
|
||||
</div>
|
||||
<p id="index-0">Golomb ruler <img class="math" src="../../_images/math/c33e393c537ec80d03521b53644847c12de37c66.png" alt="\{0,1,4,6\}"/> has <img class="math" src="../../_images/math/c0ee9fc05714a1e6c25908878d9b33acffbbb2c1.png" alt="\{0,2,5,6\}"/> as mirror Golomb ruler. Both have exactly the same length and can be considered symmetric solutions. To break this symmetry and allow the search for the first one but not the second one, just add <tt class="docutils literal"><span class="pre">X[2]-X[1]</span> <span class="pre"><</span> <span class="pre">X[n]</span> <span class="pre">-</span> <span class="pre">X[n-1]</span></tt>:</p>
|
||||
<p id="index-0">Golomb ruler <img class="math" src="../../_images/math/c33e393c537ec80d03521b53644847c12de37c66.png" alt="\{0,1,4,6\}" style="vertical-align: -5px"/> has <img class="math" src="../../_images/math/c0ee9fc05714a1e6c25908878d9b33acffbbb2c1.png" alt="\{0,2,5,6\}" style="vertical-align: -5px"/> as mirror Golomb ruler. Both have exactly the same length and can be considered symmetric solutions. To break this symmetry and allow the search for the first one but not the second one, just add <tt class="docutils literal"><span class="pre">X[2]-X[1]</span> <span class="pre"><</span> <span class="pre">X[n]</span> <span class="pre">-</span> <span class="pre">X[n-1]</span></tt>:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="n">s</span><span class="p">.</span><span class="n">AddConstraint</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">MakeLess</span><span class="p">(</span><span class="n">s</span><span class="p">.</span><span class="n">MakeDifference</span><span class="p">(</span><span class="n">X</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">X</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">-></span><span class="n">Var</span><span class="p">(),</span>
|
||||
<span class="n">s</span><span class="p">.</span><span class="n">MakeDifference</span><span class="p">(</span><span class="n">X</span><span class="p">[</span><span class="n">n</span><span class="p">],</span><span class="n">X</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">-></span><span class="n">Var</span><span class="p">()));</span>
|
||||
</pre></div>
|
||||
@@ -135,7 +135,7 @@ illustrates two mirror Golomb rulers of order 4.</p>
|
||||
</div>
|
||||
<div class="section" id="better-bounds-helps">
|
||||
<h2>3.8.2. Better bounds helps</h2>
|
||||
<p>In all implementations, we used <img class="math" src="../../_images/math/884c12c8169b77e2bb8f0b522112c34aa5c41ac4.png" alt="n^2 - 1"/> as an upper bound on <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)"/>. In the case of the Golomb Ruler Problem, finding good upper bounds is a false problem. Very efficient techniques exist to find optimal or near optimal upper bounds. If we use those bounds, we reduce dramatically the domains of the variables. We can actually use <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)"/> as an upper bound for <img class="math" src="../../_images/math/7ca098493594079f39bf0a7b50d859d1d8a7decc.png" alt="n \leqslant 25"/> as these bounds can be obtained by projective and affine projections in the plane<a class="footnote-reference" href="#projective-affine-transformation-golomb" id="id5">[4]</a>.</p>
|
||||
<p>In all implementations, we used <img class="math" src="../../_images/math/884c12c8169b77e2bb8f0b522112c34aa5c41ac4.png" alt="n^2 - 1" style="vertical-align: -1px"/> as an upper bound on <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)" style="vertical-align: -4px"/>. In the case of the Golomb Ruler Problem, finding good upper bounds is a false problem. Very efficient techniques exist to find optimal or near optimal upper bounds. If we use those bounds, we reduce dramatically the domains of the variables. We can actually use <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)" style="vertical-align: -4px"/> as an upper bound for <img class="math" src="../../_images/math/7ca098493594079f39bf0a7b50d859d1d8a7decc.png" alt="n \leqslant 25" style="vertical-align: -3px"/> as these bounds can be obtained by projective and affine projections in the plane<a class="footnote-reference" href="#projective-affine-transformation-golomb" id="id5">[4]</a>.</p>
|
||||
<table class="docutils footnote" frame="void" id="projective-affine-transformation-golomb" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
@@ -159,7 +159,7 @@ See <a class="reference external" href="http://www.research.ibm.com/people/s/she
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>where <tt class="docutils literal"><span class="pre">kG[n]</span></tt> is <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)"/>.</p>
|
||||
<p>where <tt class="docutils literal"><span class="pre">kG[n]</span></tt> is <img class="math" src="../../_images/math/cb446ee2b5cf82811436022be4db770e5b32ca1c.png" alt="G(n)" style="vertical-align: -4px"/>.</p>
|
||||
<p>The <tt class="docutils literal"><span class="pre">AllDifferent</span></tt> constraint doesn’t take a 2-dimensional array as parameter but it is easy to create one by flattening the array:</p>
|
||||
<div class="highlight-c++"><div class="highlight"><pre><span class="n">Constraint</span> <span class="o">*</span> <span class="n">AllDifferent</span><span class="p">(</span><span class="n">Solver</span><span class="o">*</span> <span class="n">s</span><span class="p">,</span>
|
||||
<span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="n">IntVar</span> <span class="o">*></span> <span class="o">></span> <span class="o">&</span> <span class="n">vars</span><span class="p">)</span> <span class="p">{</span>
|
||||
@@ -182,8 +182,8 @@ See <a class="reference external" href="http://www.research.ibm.com/people/s/she
|
||||
</div><p>so</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/443ce50b2e8d8a56d1051f51a2ead55eb19e8591.png" alt="Y[i][j] = X[n] - \left\{ Y[1][2] + Y[2][3] + ... + Y[i-1][i] + Y[j][j+1] + ... + Y[n-1][n] \right\}"/></p>
|
||||
</div><p>The differences on the right hand side of this expression are a set of different integers and there are <img class="math" src="../../_images/math/b859ee6fa1ef60123e1bbaa50dfc6e982077ea87.png" alt="n-1-j+i"/> of them.
|
||||
If we minimize the sum of these consecutive differences, we actually maximize the right hand side, i.e. we bound <img class="math" src="../../_images/math/3831ee0b9c15616fc1a764b6bd148fda9de9dc70.png" alt="Y[i][j]"/> from above:</p>
|
||||
</div><p>The differences on the right hand side of this expression are a set of different integers and there are <img class="math" src="../../_images/math/b859ee6fa1ef60123e1bbaa50dfc6e982077ea87.png" alt="n-1-j+i" style="vertical-align: -4px"/> of them.
|
||||
If we minimize the sum of these consecutive differences, we actually maximize the right hand side, i.e. we bound <img class="math" src="../../_images/math/3831ee0b9c15616fc1a764b6bd148fda9de9dc70.png" alt="Y[i][j]" style="vertical-align: -5px"/> from above:</p>
|
||||
<div class="math">
|
||||
<p><img src="../../_images/math/3e8c243f94f4e13ca158395f188c47b288c31ebf.png" alt="Y[i][j] \leqslant X[n] - (n-1-j+i)(n-j+i)/2"/></p>
|
||||
</div><p>We can add:</p>
|
||||
@@ -195,7 +195,7 @@ If we minimize the sum of these consecutive differences, we actually maximize th
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Let’s compare our tightened third implementation with the rest, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)"/>:</p>
|
||||
<p>Let’s compare our tightened third implementation with the rest, again to compute <img class="math" src="../../_images/math/67c4555c837d711a45a3e1af64caafc004600eee.png" alt="G(9)" style="vertical-align: -4px"/>:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="16%" />
|
||||
|
||||