77 lines
35 KiB
HTML
77 lines
35 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>OR-Tools</title>
|
|
<meta http-equiv="Content-Type" content="text/html;"/>
|
|
<meta charset="utf-8"/>
|
|
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
|
<link rel="stylesheet" type="text/css" href="ortools.css" title="default" media="screen,print" />
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="banner-container">
|
|
<div id="banner">
|
|
<span id="sfml">OR-Tools 7.2</span>
|
|
</div>
|
|
</div>
|
|
<link rel="icon" href="https://developers.google.com/optimization/images/orLogo.png">
|
|
<div id="content">
|
|
<!-- Generated by Doxygen 1.8.15 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
<li><a href="globals.html"><span>File Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('model_8h_source.html','');});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">model.h</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="model_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright 2010-2018 Google LLC</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">//</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">//</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#ifndef OR_TOOLS_SAT_MODEL_H_</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#define OR_TOOLS_SAT_MODEL_H_</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="preprocessor">#include <cstddef></span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="preprocessor">#include <functional></span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="preprocessor">#include <map></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#include <memory></span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#include <vector></span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "ortools/base/logging.h"</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "ortools/base/macros.h"</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include "ortools/base/map_util.h"</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#include "ortools/base/typeid.h"</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> </div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="keyword">namespace </span><a class="code" href="namespaceoperations__research.html">operations_research</a> {</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="keyword">namespace </span>sat {</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> </div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">// Class that owns everything related to a particular optimization model.</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">//</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment">// This class is actually a fully generic wrapper that can hold any type of</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">// constraints, watchers, solvers and provide a mecanism to wire them together.</span></div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html"> 35</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1sat_1_1Model.html">Model</a> {</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a7d97534275c629f2917ed5a029e2e2c5"> 37</a></span>  <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a7d97534275c629f2917ed5a029e2e2c5">Model</a>() {}</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> </div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="comment">// This allows to have a nicer API on the client side, and it allows both of</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  <span class="comment">// these forms:</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="comment">// - ConstraintCreationFunction(contraint_args, &model);</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  <span class="comment">// - model.Add(ConstraintCreationFunction(contraint_args));</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="comment">//</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="comment">// The second form is a bit nicer for the client and it also allows to store</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  <span class="comment">// constraints and add them later. However, the function creating the</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="comment">// constraint is slighly more involved:</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <span class="comment">//</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <span class="comment">// std::function<void(Model*)> ConstraintCreationFunction(contraint_args) {</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="comment">// return [=] (Model* model) {</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="comment">// ... the same code ...</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <span class="comment">// };</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="comment">// }</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <span class="comment">//</span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  <span class="comment">// We also have a templated return value for the functions that need it like</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="comment">// const BooleanVariable b = model.Add(NewBooleanVariable());</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="comment">// const IntegerVariable i = model.Add(NewWeightedSum(weigths, variables));</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a059b9d223761f2b9cc82df4871ae36fa"> 58</a></span>  T <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a059b9d223761f2b9cc82df4871ae36fa">Add</a>(std::function<T(<a class="code" href="classoperations__research_1_1sat_1_1Model.html">Model</a>*)> f) {</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keywordflow">return</span> f(<span class="keyword">this</span>);</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  }</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> </div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <span class="comment">// Similar to Add() but this is const.</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00064"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a162bdd37a619fd04f9085005008951d9"> 64</a></span>  T <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a162bdd37a619fd04f9085005008951d9">Get</a>(std::function<T(<span class="keyword">const</span> <a class="code" href="classoperations__research_1_1sat_1_1Model.html">Model</a>&)> f)<span class="keyword"> const </span>{</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keywordflow">return</span> f(*<span class="keyword">this</span>);</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  }</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span> </div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="comment">// Returns an object of type T that is unique to this model (like a "local"</span></div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="comment">// singleton). This returns an already created instance or create a new one if</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="comment">// needed using the T(Model* model) constructor if it exist or T() otherwise.</span></div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="comment">//</span></div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="comment">// This works a bit like in a dependency injection framework and allows to</span></div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="comment">// really easily wire all the classes that make up a solver together. For</span></div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  <span class="comment">// instance a constraint can depends on the LiteralTrail, or the IntegerTrail</span></div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  <span class="comment">// or both, it can depend on a Watcher class to register itself in order to</span></div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="comment">// be called when needed and so on.</span></div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="comment">//</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="comment">// IMPORTANT: the Model* constructors function shouldn't form a cycle between</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="comment">// each other, otherwise this will crash the program.</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#af4eb422b7cfd963c58d65b18b4e47717"> 81</a></span>  T* <a class="code" href="classoperations__research_1_1sat_1_1Model.html#af4eb422b7cfd963c58d65b18b4e47717">GetOrCreate</a>() {</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> type_id = gtl::FastTypeId<T>();</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <span class="keywordflow">if</span> (!gtl::ContainsKey(singletons_, type_id)) {</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <span class="comment">// TODO(user): directly store std::unique_ptr<> in singletons_?</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  T* new_t = MyNew<T>(0);</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  singletons_[type_id] = new_t;</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a6411a892fd57781615c9edf80081026c">TakeOwnership</a>(new_t);</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keywordflow">return</span> new_t;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  }</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="keywordflow">return</span> static_cast<T*>(gtl::FindOrDie(singletons_, type_id));</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  }</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span> </div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <span class="comment">// Likes GetOrCreate() but do not create the object if it is non-existing.</span></div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="comment">// This returns a const version of the object.</span></div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a211cf867e9edd220616c0a8f6ba4b71d"> 96</a></span>  <span class="keyword">const</span> T* <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a211cf867e9edd220616c0a8f6ba4b71d">Get</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  <span class="keywordflow">return</span> static_cast<const T*>(</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  gtl::FindWithDefault(singletons_, gtl::FastTypeId<T>(), <span class="keyword">nullptr</span>));</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  }</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> </div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="comment">// Same as Get(), but returns a mutable version of the object.</span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00103"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a6226de9875c58b81f461c123577d1689"> 103</a></span>  T* <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a6226de9875c58b81f461c123577d1689">Mutable</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <span class="keywordflow">return</span> static_cast<T*>(</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  gtl::FindWithDefault(singletons_, gtl::FastTypeId<T>(), <span class="keyword">nullptr</span>));</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  }</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> </div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  <span class="comment">// Gives ownership of a pointer to this model.</span></div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="comment">// It will be destroyed when the model is.</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00111"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a6411a892fd57781615c9edf80081026c"> 111</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a6411a892fd57781615c9edf80081026c">TakeOwnership</a>(T* t) {</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  cleanup_list_.emplace_back(<span class="keyword">new</span> Delete<T>(t));</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  }</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span> </div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <span class="comment">// This returns a non-singleton object owned by the model and created with the</span></div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="comment">// T(Model* model) constructor if it exist or the T() constructor otherwise.</span></div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="comment">// It is just a shortcut to new + TakeOwnership().</span></div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00119"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a08f2ee3dc9fa03be18a4c38304e068d9"> 119</a></span>  T* <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a08f2ee3dc9fa03be18a4c38304e068d9">Create</a>() {</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  T* new_t = MyNew<T>(0);</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a6411a892fd57781615c9edf80081026c">TakeOwnership</a>(new_t);</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordflow">return</span> new_t;</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  }</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> </div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="comment">// Register a non-owned class that will be "singleton" in the model.</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  <span class="comment">// It is an error to call this on an already registered class.</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00128"></a><span class="lineno"><a class="line" href="classoperations__research_1_1sat_1_1Model.html#a78f476ca154e64d281ae07efd825a779"> 128</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1sat_1_1Model.html#a78f476ca154e64d281ae07efd825a779">Register</a>(T* non_owned_class) {</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> type_id = gtl::FastTypeId<T>();</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  CHECK(!gtl::ContainsKey(singletons_, type_id));</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  singletons_[type_id] = non_owned_class;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  }</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> </div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="comment">// We want to call the constructor T(model*) if it exists or just T() if</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <span class="comment">// it doesn't. For this we use some template "magic":</span></div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  <span class="comment">// - The first MyNew() will only be defined if the type in decltype() exist.</span></div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="comment">// - The second MyNew() will always be defined, but because of the ellipsis</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="comment">// it has lower priority that the first one.</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  decltype(T(static_cast<Model*>(<span class="keyword">nullptr</span>)))* MyNew(<span class="keywordtype">int</span>) {</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  <span class="keywordflow">return</span> <span class="keyword">new</span> T(<span class="keyword">this</span>);</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  }</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  T* MyNew(...) {</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="keywordflow">return</span> <span class="keyword">new</span> T();</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  }</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span> </div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="comment">// Map of FastTypeId<T> to a "singleton" of type T.</span></div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  std::map<<span class="comment">/*typeid*/</span> size_t, <span class="keywordtype">void</span>*> singletons_;</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> </div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keyword">struct </span>DeleteInterface {</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keyword">virtual</span> ~DeleteInterface() = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  };</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="keyword">class </span>Delete : <span class="keyword">public</span> DeleteInterface {</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  <span class="keyword">explicit</span> Delete(T* t) : to_delete_(t) {}</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  ~Delete() <span class="keyword">override</span> = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span> </div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  std::unique_ptr<T> to_delete_;</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  };</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span> </div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <span class="comment">// The list of items to delete.</span></div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  <span class="comment">//</span></div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  <span class="comment">// TODO(user): I don't think we need the two layers of unique_ptr, but we</span></div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  <span class="comment">// don't care too much about efficiency here and this was easier to get</span></div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  <span class="comment">// working.</span></div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  std::vector<std::unique_ptr<DeleteInterface>> cleanup_list_;</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span> </div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  DISALLOW_COPY_AND_ASSIGN(<a class="code" href="classoperations__research_1_1sat_1_1Model.html#a7d97534275c629f2917ed5a029e2e2c5">Model</a>);</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span> };</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span> </div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span> } <span class="comment">// namespace sat</span></div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span> } <span class="comment">// namespace operations_research</span></div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> </div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span> <span class="preprocessor">#endif // OR_TOOLS_SAT_MODEL_H_</span></div><div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a162bdd37a619fd04f9085005008951d9"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a162bdd37a619fd04f9085005008951d9">operations_research::sat::Model::Get</a></div><div class="ttdeci">T Get(std::function< T(const Model &)> f) const</div><div class="ttdoc">Similar to Add() but this is const.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00064">model.h:64</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a7d97534275c629f2917ed5a029e2e2c5"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a7d97534275c629f2917ed5a029e2e2c5">operations_research::sat::Model::Model</a></div><div class="ttdeci">Model()</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00037">model.h:37</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a6411a892fd57781615c9edf80081026c"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a6411a892fd57781615c9edf80081026c">operations_research::sat::Model::TakeOwnership</a></div><div class="ttdeci">void TakeOwnership(T *t)</div><div class="ttdoc">Gives ownership of a pointer to this model.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00111">model.h:111</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a78f476ca154e64d281ae07efd825a779"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a78f476ca154e64d281ae07efd825a779">operations_research::sat::Model::Register</a></div><div class="ttdeci">void Register(T *non_owned_class)</div><div class="ttdoc">Register a non-owned class that will be "singleton" in the model.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00128">model.h:128</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a08f2ee3dc9fa03be18a4c38304e068d9"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a08f2ee3dc9fa03be18a4c38304e068d9">operations_research::sat::Model::Create</a></div><div class="ttdeci">T * Create()</div><div class="ttdoc">This returns a non-singleton object owned by the model and created with the T(Model* model) construct...</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00119">model.h:119</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html">operations_research::sat::Model</a></div><div class="ttdoc">Class that owns everything related to a particular optimization model.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00035">model.h:35</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a211cf867e9edd220616c0a8f6ba4b71d"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a211cf867e9edd220616c0a8f6ba4b71d">operations_research::sat::Model::Get</a></div><div class="ttdeci">const T * Get() const</div><div class="ttdoc">Likes GetOrCreate() but do not create the object if it is non-existing.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00096">model.h:96</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_af4eb422b7cfd963c58d65b18b4e47717"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#af4eb422b7cfd963c58d65b18b4e47717">operations_research::sat::Model::GetOrCreate</a></div><div class="ttdeci">T * GetOrCreate()</div><div class="ttdoc">Returns an object of type T that is unique to this model (like a "local" singleton).</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00081">model.h:81</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a059b9d223761f2b9cc82df4871ae36fa"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a059b9d223761f2b9cc82df4871ae36fa">operations_research::sat::Model::Add</a></div><div class="ttdeci">T Add(std::function< T(Model *)> f)</div><div class="ttdoc">This allows to have a nicer API on the client side, and it allows both of these forms:</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00058">model.h:58</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1sat_1_1Model_html_a6226de9875c58b81f461c123577d1689"><div class="ttname"><a href="classoperations__research_1_1sat_1_1Model.html#a6226de9875c58b81f461c123577d1689">operations_research::sat::Model::Mutable</a></div><div class="ttdeci">T * Mutable() const</div><div class="ttdoc">Same as Get(), but returns a mutable version of the object.</div><div class="ttdef"><b>Definition:</b> <a href="model_8h_source.html#l00103">model.h:103</a></div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdoc">Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...</div><div class="ttdef"><b>Definition:</b> <a href="cp__model_8h_source.html#l00048">cp_model.h:48</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
</div>
|
|
<div id="footer-container">
|
|
<div id="footer">
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|