Files
ortools-clone/docs/cpp_algorithms/knapsack__solver_8h_source.html
Mizux Seiha 17edcf0e25 Update doc
2021-09-30 01:28:18 +02:00

724 lines
160 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"/>-->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="styleSheet.tmp.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="banner-container">
<div id="banner">
<span id="sfml">Google OR-Tools 9.1</span>
</div>
</div>
<div id="content" style="width: 100%; overflow: hidden;">
<div style="margin-left: 15px; margin-top: 5px; float: left; color: #145A32;">
<h2>C++ Reference</h2>
<ul>
<li><a href="../cpp_algorithms/annotated.html">Algorithms</a></li>
<li><a href="../cpp_sat/annotated.html">CP-SAT</a></li>
<li><a href="../cpp_graph/annotated.html">Graph</a></li>
<li><a href="../cpp_routing/annotated.html">Routing</a></li>
<li><a href="../cpp_linear/annotated.html">Linear solver</a></li>
</ul>
</div>
<div id="content">
<div align="center">
<h1 style="color: #145A32;">C++ Reference: Algorithms</h1>
</div>
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('knapsack__solver_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle"><div class="title">knapsack_solver.h</div></div>
</div><!--header-->
<div class="contents">
<a href="knapsack__solver_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="comment">// Copyright 2010-2021 Google LLC</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="comment">// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div>
<div class="line"><a id="l00003" 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 id="l00004" 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 id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="comment">//</span></div>
<div class="line"><a id="l00006" 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 id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="comment">//</span></div>
<div class="line"><a id="l00008" 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 id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="comment">// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div>
<div class="line"><a id="l00010" 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 id="l00011" 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 id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="comment">// limitations under the License.</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span> </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="preprocessor">#ifndef OR_TOOLS_ALGORITHMS_KNAPSACK_SOLVER_H_</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="preprocessor">#define OR_TOOLS_ALGORITHMS_KNAPSACK_SOLVER_H_</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="preprocessor">#include &lt;math.h&gt;</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span> </div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span><span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> </div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span><span class="preprocessor">#include &quot;absl/memory/memory.h&quot;</span></div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span><span class="preprocessor">#include &quot;ortools/base/basictypes.h&quot;</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="preprocessor">#include &quot;ortools/base/integral_types.h&quot;</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="preprocessor">#include &quot;ortools/base/logging.h&quot;</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span><span class="preprocessor">#include &quot;ortools/base/macros.h&quot;</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span><span class="preprocessor">#include &quot;ortools/util/time_limit.h&quot;</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> </div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespaceoperations__research.html">operations_research</a> {</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> </div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span><span class="keyword">class </span>BaseKnapsackSolver;</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html"> 117</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_solver.html">KnapsackSolver</a> {</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ec"> 124</a></span> <span class="keyword">enum</span> <a class="code hl_enumeration" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ec">SolverType</a> {</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecac43056d6d2f96cee37fcb8a752b0ff45"> 131</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecac43056d6d2f96cee37fcb8a752b0ff45">KNAPSACK_BRUTE_FORCE_SOLVER</a> = 0,</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> </div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecaa020f211a1ff184e712aa4f372d6ea34"> 139</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecaa020f211a1ff184e712aa4f372d6ea34">KNAPSACK_64ITEMS_SOLVER</a> = 1,</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> </div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca793d998526508cfcc2bfc89fe25b3edd"> 147</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca793d998526508cfcc2bfc89fe25b3edd">KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER</a> = 2,</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span><span class="preprocessor">#if defined(USE_CBC)</span></div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecae2ce6e36a247621de398e875d5feb575"> 155</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecae2ce6e36a247621de398e875d5feb575">KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER</a> = 3,</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno"> 156</span><span class="preprocessor">#endif </span><span class="comment">// USE_CBC</span></div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno"> 157</span> </div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca2a4e77eec4f386d17001e7285e812a0b"> 163</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca2a4e77eec4f386d17001e7285e812a0b">KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER</a> = 5,</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"> 164</span> </div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno"> 165</span><span class="preprocessor">#if defined(USE_SCIP)</span></div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca1f4e1e2f80ab9c7d4fc1b14d9f5da959"> 171</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca1f4e1e2f80ab9c7d4fc1b14d9f5da959">KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER</a> = 6,</div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno"> 172</span><span class="preprocessor">#endif </span><span class="comment">// USE_SCIP</span></div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno"> 173</span> </div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno"> 174</span><span class="preprocessor">#if defined(USE_XPRESS)</span></div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span> KNAPSACK_MULTIDIMENSION_XPRESS_MIP_SOLVER = 7,</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno"> 181</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno"> 182</span> </div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno"> 183</span><span class="preprocessor">#if defined(USE_CPLEX)</span></div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno"> 189</span> KNAPSACK_MULTIDIMENSION_CPLEX_MIP_SOLVER = 8,</div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno"> 190</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca9d4c4118c9e4dc258e5052c0a457098d"> 198</a></span> <a class="code hl_enumvalue" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca9d4c4118c9e4dc258e5052c0a457098d">KNAPSACK_DIVIDE_AND_CONQUER_SOLVER</a> = 9,</div>
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno"> 199</span> };</div>
<div class="line"><a id="l00200" name="l00200"></a><span class="lineno"> 200</span> </div>
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a6b46c35c8977efde66ae7ad97423bdf2"> 201</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a6b46c35c8977efde66ae7ad97423bdf2">KnapsackSolver</a>(<span class="keyword">const</span> std::string&amp; solver_name);</div>
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a09627cf25401a9880d2e94551ecbf993"> 202</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a09627cf25401a9880d2e94551ecbf993">KnapsackSolver</a>(<a class="code hl_enumeration" href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ec">SolverType</a> solver_type, <span class="keyword">const</span> std::string&amp; solver_name);</div>
<div class="line"><a id="l00203" name="l00203"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#adecc1cf1fe064b843459dd1f8aec12ff"> 203</a></span> <span class="keyword">virtual</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#adecc1cf1fe064b843459dd1f8aec12ff">~KnapsackSolver</a>();</div>
<div class="line"><a id="l00204" name="l00204"></a><span class="lineno"> 204</span> </div>
<div class="line"><a id="l00208" name="l00208"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#ae5982edf1a2974495d20201775a765e2"> 208</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#ae5982edf1a2974495d20201775a765e2">Init</a>(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits,</div>
<div class="line"><a id="l00209" name="l00209"></a><span class="lineno"> 209</span> <span class="keyword">const</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;&amp; weights,</div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno"> 210</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; capacities);</div>
<div class="line"><a id="l00211" name="l00211"></a><span class="lineno"> 211</span> </div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a7f5467b49f2cba3d8804e44ed76e12a2"> 215</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a7f5467b49f2cba3d8804e44ed76e12a2">Solve</a>();</div>
<div class="line"><a id="l00216" name="l00216"></a><span class="lineno"> 216</span> </div>
<div class="line"><a id="l00220" name="l00220"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a57d88f584d14b161580550918c8fbf3b"> 220</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a57d88f584d14b161580550918c8fbf3b">BestSolutionContains</a>(<span class="keywordtype">int</span> item_id) <span class="keyword">const</span>;</div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a9647a5f765048e8662e5efa54c7d8687"> 224</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a9647a5f765048e8662e5efa54c7d8687">IsSolutionOptimal</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> is_solution_optimal_; }</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a9a98946a64f3893b085f650932c9dfee"> 225</a></span> std::string <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a9a98946a64f3893b085f650932c9dfee">GetName</a>() <span class="keyword">const</span>;</div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"> 226</span> </div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#ac7d0a3efa2aabe6a3e667b0724f63688"> 227</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#ac7d0a3efa2aabe6a3e667b0724f63688">use_reduction</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> use_reduction_; }</div>
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#aa5b8e0a03c593bfc3cef0ba8d178844f"> 228</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#aa5b8e0a03c593bfc3cef0ba8d178844f">set_use_reduction</a>(<span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#ac7d0a3efa2aabe6a3e667b0724f63688">use_reduction</a>) { use_reduction_ = <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#ac7d0a3efa2aabe6a3e667b0724f63688">use_reduction</a>; }</div>
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno"> 229</span> </div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_solver.html#a6b4f6cbb00a64b0e9745938f9b99d0c8"> 235</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_solver.html#a6b4f6cbb00a64b0e9745938f9b99d0c8">set_time_limit</a>(<span class="keywordtype">double</span> time_limit_seconds) {</div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno"> 236</span> time_limit_seconds_ = time_limit_seconds;</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno"> 237</span> time_limit_ = absl::make_unique&lt;TimeLimit&gt;(time_limit_seconds_);</div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno"> 238</span> }</div>
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno"> 239</span> </div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno"> 240</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno"> 241</span> <span class="comment">// Trivial reduction of capacity constraints when the capacity is higher than</span></div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno"> 242</span> <span class="comment">// the sum of the weights of the items. Returns the number of reduced items.</span></div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno"> 243</span> <span class="keywordtype">int</span> ReduceCapacities(<span class="keywordtype">int</span> num_items,</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno"> 244</span> <span class="keyword">const</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;&amp; weights,</div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno"> 245</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; capacities,</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno"> 246</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;* reduced_weights,</div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span> std::vector&lt;int64_t&gt;* reduced_capacities);</div>
<div class="line"><a id="l00248" name="l00248"></a><span class="lineno"> 248</span> <span class="keywordtype">int</span> ReduceProblem(<span class="keywordtype">int</span> num_items);</div>
<div class="line"><a id="l00249" name="l00249"></a><span class="lineno"> 249</span> <span class="keywordtype">void</span> ComputeAdditionalProfit(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits);</div>
<div class="line"><a id="l00250" name="l00250"></a><span class="lineno"> 250</span> <span class="keywordtype">void</span> InitReducedProblem(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits,</div>
<div class="line"><a id="l00251" name="l00251"></a><span class="lineno"> 251</span> <span class="keyword">const</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;&amp; weights,</div>
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno"> 252</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; capacities);</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno"> 253</span> </div>
<div class="line"><a id="l00254" name="l00254"></a><span class="lineno"> 254</span> std::unique_ptr&lt;BaseKnapsackSolver&gt; solver_;</div>
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno"> 255</span> std::vector&lt;bool&gt; known_value_;</div>
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno"> 256</span> std::vector&lt;bool&gt; best_solution_;</div>
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno"> 257</span> <span class="keywordtype">bool</span> is_solution_optimal_ = <span class="keyword">false</span>;</div>
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno"> 258</span> std::vector&lt;int&gt; mapping_reduced_item_id_;</div>
<div class="line"><a id="l00259" name="l00259"></a><span class="lineno"> 259</span> <span class="keywordtype">bool</span> is_problem_solved_;</div>
<div class="line"><a id="l00260" name="l00260"></a><span class="lineno"> 260</span> int64_t additional_profit_;</div>
<div class="line"><a id="l00261" name="l00261"></a><span class="lineno"> 261</span> <span class="keywordtype">bool</span> use_reduction_;</div>
<div class="line"><a id="l00262" name="l00262"></a><span class="lineno"> 262</span> <span class="keywordtype">double</span> time_limit_seconds_;</div>
<div class="line"><a id="l00263" name="l00263"></a><span class="lineno"> 263</span> std::unique_ptr&lt;TimeLimit&gt; time_limit_;</div>
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno"> 264</span> </div>
<div class="line"><a id="l00265" name="l00265"></a><span class="lineno"> 265</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_solver.html">KnapsackSolver</a>);</div>
<div class="line"><a id="l00266" name="l00266"></a><span class="lineno"> 266</span>};</div>
<div class="line"><a id="l00267" name="l00267"></a><span class="lineno"> 267</span> </div>
<div class="line"><a id="l00268" name="l00268"></a><span class="lineno"> 268</span><span class="preprocessor">#if !defined(SWIG)</span></div>
<div class="line"><a id="l00269" name="l00269"></a><span class="lineno"> 269</span><span class="comment">// The following code defines needed classes for the KnapsackGenericSolver</span></div>
<div class="line"><a id="l00270" name="l00270"></a><span class="lineno"> 270</span><span class="comment">// class which is the entry point to extend knapsack with new constraints such</span></div>
<div class="line"><a id="l00271" name="l00271"></a><span class="lineno"> 271</span><span class="comment">// as conflicts between items.</span></div>
<div class="line"><a id="l00272" name="l00272"></a><span class="lineno"> 272</span><span class="comment">//</span></div>
<div class="line"><a id="l00273" name="l00273"></a><span class="lineno"> 273</span><span class="comment">// Constraints are enforced using KnapsackPropagator objects, in the current</span></div>
<div class="line"><a id="l00274" name="l00274"></a><span class="lineno"> 274</span><span class="comment">// code there is one propagator per dimension (KnapsackCapacityPropagator).</span></div>
<div class="line"><a id="l00275" name="l00275"></a><span class="lineno"> 275</span><span class="comment">// One of those propagators, named master propagator, is used to guide the</span></div>
<div class="line"><a id="l00276" name="l00276"></a><span class="lineno"> 276</span><span class="comment">// search, i.e. decides which item should be assigned next.</span></div>
<div class="line"><a id="l00277" name="l00277"></a><span class="lineno"> 277</span><span class="comment">// Roughly speaking the search algorithm is:</span></div>
<div class="line"><a id="l00278" name="l00278"></a><span class="lineno"> 278</span><span class="comment">// - While not optimal</span></div>
<div class="line"><a id="l00279" name="l00279"></a><span class="lineno"> 279</span><span class="comment">// - Select next search node to expand</span></div>
<div class="line"><a id="l00280" name="l00280"></a><span class="lineno"> 280</span><span class="comment">// - Select next item_i to assign (using master propagator)</span></div>
<div class="line"><a id="l00281" name="l00281"></a><span class="lineno"> 281</span><span class="comment">// - Generate a new search node where item_i is in the knapsack</span></div>
<div class="line"><a id="l00282" name="l00282"></a><span class="lineno"> 282</span><span class="comment">// - Check validity of this new partial solution (using propagators)</span></div>
<div class="line"><a id="l00283" name="l00283"></a><span class="lineno"> 283</span><span class="comment">// - If valid, add this new search node to the search</span></div>
<div class="line"><a id="l00284" name="l00284"></a><span class="lineno"> 284</span><span class="comment">// - Generate a new search node where item_i is not in the knapsack</span></div>
<div class="line"><a id="l00285" name="l00285"></a><span class="lineno"> 285</span><span class="comment">// - Check validity of this new partial solution (using propagators)</span></div>
<div class="line"><a id="l00286" name="l00286"></a><span class="lineno"> 286</span><span class="comment">// - If valid, add this new search node to the search</span></div>
<div class="line"><a id="l00287" name="l00287"></a><span class="lineno"> 287</span><span class="comment">//</span></div>
<div class="line"><a id="l00288" name="l00288"></a><span class="lineno"> 288</span><span class="comment">// TODO(user): Add a new propagator class for conflict constraint.</span></div>
<div class="line"><a id="l00289" name="l00289"></a><span class="lineno"> 289</span><span class="comment">// TODO(user): Add a new propagator class used as a guide when the problem has</span></div>
<div class="line"><a id="l00290" name="l00290"></a><span class="lineno"> 290</span><span class="comment">// several dimensions.</span></div>
<div class="line"><a id="l00291" name="l00291"></a><span class="lineno"> 291</span> </div>
<div class="line"><a id="l00292" name="l00292"></a><span class="lineno"> 292</span><span class="comment">// ----- KnapsackAssignement -----</span></div>
<div class="line"><a id="l00293" name="l00293"></a><span class="lineno"> 293</span><span class="comment">// KnapsackAssignement is a small struct used to pair an item with its</span></div>
<div class="line"><a id="l00294" name="l00294"></a><span class="lineno"> 294</span><span class="comment">// assignment. It is mainly used for search nodes and updates.</span></div>
<div class="line"><a id="l00295" name="l00295"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_assignment.html"> 295</a></span><span class="keyword">struct </span><a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a> {</div>
<div class="line"><a id="l00296" name="l00296"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_assignment.html#a8f85eb172a4c6bed0d042f7d269fc457"> 296</a></span> <a class="code hl_function" href="structoperations__research_1_1_knapsack_assignment.html#a8f85eb172a4c6bed0d042f7d269fc457">KnapsackAssignment</a>(<span class="keywordtype">int</span> _item_id, <span class="keywordtype">bool</span> _is_in)</div>
<div class="line"><a id="l00297" name="l00297"></a><span class="lineno"> 297</span> : <a class="code hl_variable" href="structoperations__research_1_1_knapsack_assignment.html#a1c0c3c835f3c4363b650fba65c7ebf32">item_id</a>(_item_id), <a class="code hl_variable" href="structoperations__research_1_1_knapsack_assignment.html#a922620900c7a18d22de686d47e25d4ed">is_in</a>(_is_in) {}</div>
<div class="line"><a id="l00298" name="l00298"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_assignment.html#a1c0c3c835f3c4363b650fba65c7ebf32"> 298</a></span> <span class="keywordtype">int</span> <a class="code hl_variable" href="structoperations__research_1_1_knapsack_assignment.html#a1c0c3c835f3c4363b650fba65c7ebf32">item_id</a>;</div>
<div class="line"><a id="l00299" name="l00299"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_assignment.html#a922620900c7a18d22de686d47e25d4ed"> 299</a></span> <span class="keywordtype">bool</span> <a class="code hl_variable" href="structoperations__research_1_1_knapsack_assignment.html#a922620900c7a18d22de686d47e25d4ed">is_in</a>;</div>
<div class="line"><a id="l00300" name="l00300"></a><span class="lineno"> 300</span>};</div>
<div class="line"><a id="l00301" name="l00301"></a><span class="lineno"> 301</span> </div>
<div class="line"><a id="l00302" name="l00302"></a><span class="lineno"> 302</span><span class="comment">// ----- KnapsackItem -----</span></div>
<div class="line"><a id="l00303" name="l00303"></a><span class="lineno"> 303</span><span class="comment">// KnapsackItem is a small struct to pair an item weight with its</span></div>
<div class="line"><a id="l00304" name="l00304"></a><span class="lineno"> 304</span><span class="comment">// corresponding profit.</span></div>
<div class="line"><a id="l00305" name="l00305"></a><span class="lineno"> 305</span><span class="comment">// The aim of the knapsack problem is to pack as many valuable items as</span></div>
<div class="line"><a id="l00306" name="l00306"></a><span class="lineno"> 306</span><span class="comment">// possible. A straight forward heuristic is to take those with the greatest</span></div>
<div class="line"><a id="l00307" name="l00307"></a><span class="lineno"> 307</span><span class="comment">// profit-per-unit-weight. This ratio is called efficiency in this</span></div>
<div class="line"><a id="l00308" name="l00308"></a><span class="lineno"> 308</span><span class="comment">// implementation. So items will be grouped in vectors, and sorted by</span></div>
<div class="line"><a id="l00309" name="l00309"></a><span class="lineno"> 309</span><span class="comment">// decreasing efficiency.</span></div>
<div class="line"><a id="l00310" name="l00310"></a><span class="lineno"> 310</span><span class="comment">// Note that profits are duplicated for each dimension. This is done to</span></div>
<div class="line"><a id="l00311" name="l00311"></a><span class="lineno"> 311</span><span class="comment">// simplify the code, especially the GetEfficiency method and vector sorting.</span></div>
<div class="line"><a id="l00312" name="l00312"></a><span class="lineno"> 312</span><span class="comment">// As there usually are only few dimensions, the overhead should not be an</span></div>
<div class="line"><a id="l00313" name="l00313"></a><span class="lineno"> 313</span><span class="comment">// issue.</span></div>
<div class="line"><a id="l00314" name="l00314"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html"> 314</a></span><span class="keyword">struct </span><a class="code hl_struct" href="structoperations__research_1_1_knapsack_item.html">KnapsackItem</a> {</div>
<div class="line"><a id="l00315" name="l00315"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html#aefc8a61c2edd00c4daf37056b754e6a0"> 315</a></span> <a class="code hl_function" href="structoperations__research_1_1_knapsack_item.html#aefc8a61c2edd00c4daf37056b754e6a0">KnapsackItem</a>(<span class="keywordtype">int</span> _id, int64_t _weight, int64_t _profit)</div>
<div class="line"><a id="l00316" name="l00316"></a><span class="lineno"> 316</span> : <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a64ae40793ade89d800a8c5646d2980fc">id</a>(_id), <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee">weight</a>(_weight), <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a75dd99d0e31e3a347e5ebad01561e31d">profit</a>(_profit) {}</div>
<div class="line"><a id="l00317" name="l00317"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html#a7eb6bbc72ec605de6f50d0c90f609a85"> 317</a></span> <span class="keywordtype">double</span> <a class="code hl_function" href="structoperations__research_1_1_knapsack_item.html#a7eb6bbc72ec605de6f50d0c90f609a85">GetEfficiency</a>(int64_t profit_max)<span class="keyword"> const </span>{</div>
<div class="line"><a id="l00318" name="l00318"></a><span class="lineno"> 318</span> <span class="keywordflow">return</span> (<a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee">weight</a> &gt; 0)</div>
<div class="line"><a id="l00319" name="l00319"></a><span class="lineno"> 319</span> ? <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(<a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a75dd99d0e31e3a347e5ebad01561e31d">profit</a>) / <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(<a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee">weight</a>)</div>
<div class="line"><a id="l00320" name="l00320"></a><span class="lineno"> 320</span> : <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(profit_max);</div>
<div class="line"><a id="l00321" name="l00321"></a><span class="lineno"> 321</span> }</div>
<div class="line"><a id="l00322" name="l00322"></a><span class="lineno"> 322</span> </div>
<div class="line"><a id="l00323" name="l00323"></a><span class="lineno"> 323</span> <span class="comment">// The &#39;id&#39; field is used to retrieve the initial item in order to</span></div>
<div class="line"><a id="l00324" name="l00324"></a><span class="lineno"> 324</span> <span class="comment">// communicate with other propagators and state.</span></div>
<div class="line"><a id="l00325" name="l00325"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html#a64ae40793ade89d800a8c5646d2980fc"> 325</a></span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a64ae40793ade89d800a8c5646d2980fc">id</a>;</div>
<div class="line"><a id="l00326" name="l00326"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee"> 326</a></span> <span class="keyword">const</span> int64_t <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee">weight</a>;</div>
<div class="line"><a id="l00327" name="l00327"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_knapsack_item.html#a75dd99d0e31e3a347e5ebad01561e31d"> 327</a></span> <span class="keyword">const</span> int64_t <a class="code hl_variable" href="structoperations__research_1_1_knapsack_item.html#a75dd99d0e31e3a347e5ebad01561e31d">profit</a>;</div>
<div class="line"><a id="l00328" name="l00328"></a><span class="lineno"> 328</span>};</div>
<div class="line"><a id="l00329" name="l00329"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#ada7d9b46f657c6053a197273a85043a7"> 329</a></span><span class="keyword">typedef</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_item.html">KnapsackItem</a>* <a class="code hl_typedef" href="namespaceoperations__research.html#ada7d9b46f657c6053a197273a85043a7">KnapsackItemPtr</a>;</div>
<div class="line"><a id="l00330" name="l00330"></a><span class="lineno"> 330</span> </div>
<div class="line"><a id="l00331" name="l00331"></a><span class="lineno"> 331</span><span class="comment">// ----- KnapsackSearchNode -----</span></div>
<div class="line"><a id="l00332" name="l00332"></a><span class="lineno"> 332</span><span class="comment">// KnapsackSearchNode is a class used to describe a decision in the decision</span></div>
<div class="line"><a id="l00333" name="l00333"></a><span class="lineno"> 333</span><span class="comment">// search tree.</span></div>
<div class="line"><a id="l00334" name="l00334"></a><span class="lineno"> 334</span><span class="comment">// The node is defined by a pointer to the parent search node and an</span></div>
<div class="line"><a id="l00335" name="l00335"></a><span class="lineno"> 335</span><span class="comment">// assignment (see KnapsackAssignement).</span></div>
<div class="line"><a id="l00336" name="l00336"></a><span class="lineno"> 336</span><span class="comment">// As the current state is not explicitly stored in a search node, one should</span></div>
<div class="line"><a id="l00337" name="l00337"></a><span class="lineno"> 337</span><span class="comment">// go through the search tree to incrementally build a partial solution from</span></div>
<div class="line"><a id="l00338" name="l00338"></a><span class="lineno"> 338</span><span class="comment">// a previous search node.</span></div>
<div class="line"><a id="l00339" name="l00339"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html"> 339</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a> {</div>
<div class="line"><a id="l00340" name="l00340"></a><span class="lineno"> 340</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00341" name="l00341"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#ad17e46a2afcf393a4ec9159162c969f2"> 341</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#ad17e46a2afcf393a4ec9159162c969f2">KnapsackSearchNode</a>(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>* <span class="keyword">const</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a94edd193a3f600c604a314803f723d93">parent</a>,</div>
<div class="line"><a id="l00342" name="l00342"></a><span class="lineno"> 342</span> <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#af94db7bbd58faf999d63953ef12784fe">assignment</a>);</div>
<div class="line"><a id="l00343" name="l00343"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a6fdd73f8011695b97659f2bea29325cb"> 343</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a6fdd73f8011695b97659f2bea29325cb">depth</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> depth_; }</div>
<div class="line"><a id="l00344" name="l00344"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a94edd193a3f600c604a314803f723d93"> 344</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>* <span class="keyword">const</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a94edd193a3f600c604a314803f723d93">parent</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> parent_; }</div>
<div class="line"><a id="l00345" name="l00345"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#af94db7bbd58faf999d63953ef12784fe"> 345</a></span> <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#af94db7bbd58faf999d63953ef12784fe">assignment</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> assignment_; }</div>
<div class="line"><a id="l00346" name="l00346"></a><span class="lineno"> 346</span> </div>
<div class="line"><a id="l00347" name="l00347"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a08beea2d857241d99287935a91be5217"> 347</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a08beea2d857241d99287935a91be5217">current_profit</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> current_profit_; }</div>
<div class="line"><a id="l00348" name="l00348"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a48521e7b1a381bd3f3f452fa6e697bde"> 348</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a48521e7b1a381bd3f3f452fa6e697bde">set_current_profit</a>(int64_t profit) { current_profit_ = profit; }</div>
<div class="line"><a id="l00349" name="l00349"></a><span class="lineno"> 349</span> </div>
<div class="line"><a id="l00350" name="l00350"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#aa68069fd1180cb37fcdbc99d6230bc3e"> 350</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#aa68069fd1180cb37fcdbc99d6230bc3e">profit_upper_bound</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> profit_upper_bound_; }</div>
<div class="line"><a id="l00351" name="l00351"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#af991b29f273c53c8b35cb09bcccf3a5d"> 351</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#af991b29f273c53c8b35cb09bcccf3a5d">set_profit_upper_bound</a>(int64_t profit) { profit_upper_bound_ = profit; }</div>
<div class="line"><a id="l00352" name="l00352"></a><span class="lineno"> 352</span> </div>
<div class="line"><a id="l00353" name="l00353"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a94dca4e57f87ba2a9e3b995c267c0821"> 353</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a94dca4e57f87ba2a9e3b995c267c0821">next_item_id</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> next_item_id_; }</div>
<div class="line"><a id="l00354" name="l00354"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_node.html#a9962698a737cd21789c77ff32bef0d98"> 354</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_node.html#a9962698a737cd21789c77ff32bef0d98">set_next_item_id</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) { next_item_id_ = id; }</div>
<div class="line"><a id="l00355" name="l00355"></a><span class="lineno"> 355</span> </div>
<div class="line"><a id="l00356" name="l00356"></a><span class="lineno"> 356</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00357" name="l00357"></a><span class="lineno"> 357</span> <span class="comment">// &#39;depth&#39; field is used to navigate efficiently through the search tree</span></div>
<div class="line"><a id="l00358" name="l00358"></a><span class="lineno"> 358</span> <span class="comment">// (see KnapsackSearchPath).</span></div>
<div class="line"><a id="l00359" name="l00359"></a><span class="lineno"> 359</span> <span class="keywordtype">int</span> depth_;</div>
<div class="line"><a id="l00360" name="l00360"></a><span class="lineno"> 360</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>* <span class="keyword">const</span> parent_;</div>
<div class="line"><a id="l00361" name="l00361"></a><span class="lineno"> 361</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a> assignment_;</div>
<div class="line"><a id="l00362" name="l00362"></a><span class="lineno"> 362</span> </div>
<div class="line"><a id="l00363" name="l00363"></a><span class="lineno"> 363</span> <span class="comment">// &#39;current_profit&#39; and &#39;profit_upper_bound&#39; fields are used to sort search</span></div>
<div class="line"><a id="l00364" name="l00364"></a><span class="lineno"> 364</span> <span class="comment">// nodes using a priority queue. That allows to pop the node with the best</span></div>
<div class="line"><a id="l00365" name="l00365"></a><span class="lineno"> 365</span> <span class="comment">// upper bound, and more importantly to stop the search when optimality is</span></div>
<div class="line"><a id="l00366" name="l00366"></a><span class="lineno"> 366</span> <span class="comment">// proved.</span></div>
<div class="line"><a id="l00367" name="l00367"></a><span class="lineno"> 367</span> int64_t current_profit_;</div>
<div class="line"><a id="l00368" name="l00368"></a><span class="lineno"> 368</span> int64_t profit_upper_bound_;</div>
<div class="line"><a id="l00369" name="l00369"></a><span class="lineno"> 369</span> </div>
<div class="line"><a id="l00370" name="l00370"></a><span class="lineno"> 370</span> <span class="comment">// &#39;next_item_id&#39; field allows to avoid an O(number_of_items) scan to find</span></div>
<div class="line"><a id="l00371" name="l00371"></a><span class="lineno"> 371</span> <span class="comment">// next item to select. This is done for free by the upper bound computation.</span></div>
<div class="line"><a id="l00372" name="l00372"></a><span class="lineno"> 372</span> <span class="keywordtype">int</span> next_item_id_;</div>
<div class="line"><a id="l00373" name="l00373"></a><span class="lineno"> 373</span> </div>
<div class="line"><a id="l00374" name="l00374"></a><span class="lineno"> 374</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>);</div>
<div class="line"><a id="l00375" name="l00375"></a><span class="lineno"> 375</span>};</div>
<div class="line"><a id="l00376" name="l00376"></a><span class="lineno"> 376</span> </div>
<div class="line"><a id="l00377" name="l00377"></a><span class="lineno"> 377</span><span class="comment">// ----- KnapsackSearchPath -----</span></div>
<div class="line"><a id="l00378" name="l00378"></a><span class="lineno"> 378</span><span class="comment">// KnapsackSearchPath is a small class used to represent the path between a</span></div>
<div class="line"><a id="l00379" name="l00379"></a><span class="lineno"> 379</span><span class="comment">// node to another node in the search tree.</span></div>
<div class="line"><a id="l00380" name="l00380"></a><span class="lineno"> 380</span><span class="comment">// As the solution state is not stored for each search node, the state should</span></div>
<div class="line"><a id="l00381" name="l00381"></a><span class="lineno"> 381</span><span class="comment">// be rebuilt at each node. One simple solution is to apply all decisions</span></div>
<div class="line"><a id="l00382" name="l00382"></a><span class="lineno"> 382</span><span class="comment">// between the node &#39;to&#39; and the root. This can be computed in</span></div>
<div class="line"><a id="l00383" name="l00383"></a><span class="lineno"> 383</span><span class="comment">// O(number_of_items).</span></div>
<div class="line"><a id="l00384" name="l00384"></a><span class="lineno"> 384</span><span class="comment">//</span></div>
<div class="line"><a id="l00385" name="l00385"></a><span class="lineno"> 385</span><span class="comment">// However, it is possible to achieve better average complexity. Two</span></div>
<div class="line"><a id="l00386" name="l00386"></a><span class="lineno"> 386</span><span class="comment">// consecutively explored nodes are usually close enough (i.e., much less than</span></div>
<div class="line"><a id="l00387" name="l00387"></a><span class="lineno"> 387</span><span class="comment">// number_of_items) to benefit from an incremental update from the node</span></div>
<div class="line"><a id="l00388" name="l00388"></a><span class="lineno"> 388</span><span class="comment">// &#39;from&#39; to the node &#39;to&#39;.</span></div>
<div class="line"><a id="l00389" name="l00389"></a><span class="lineno"> 389</span><span class="comment">//</span></div>
<div class="line"><a id="l00390" name="l00390"></a><span class="lineno"> 390</span><span class="comment">// The &#39;via&#39; field is the common parent of &#39;from&#39; field and &#39;to&#39; field.</span></div>
<div class="line"><a id="l00391" name="l00391"></a><span class="lineno"> 391</span><span class="comment">// So the state can be built by reverting all decisions from &#39;from&#39; to &#39;via&#39;</span></div>
<div class="line"><a id="l00392" name="l00392"></a><span class="lineno"> 392</span><span class="comment">// and then applying all decisions from &#39;via&#39; to &#39;to&#39;.</span></div>
<div class="line"><a id="l00393" name="l00393"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html"> 393</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_search_path.html">KnapsackSearchPath</a> {</div>
<div class="line"><a id="l00394" name="l00394"></a><span class="lineno"> 394</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00395" name="l00395"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#a3dc3602e1a640bc986956e0ce5e88d04"> 395</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#a3dc3602e1a640bc986956e0ce5e88d04">KnapsackSearchPath</a>(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#a97db8ba091791787900dd812fefc10e5">from</a>,</div>
<div class="line"><a id="l00396" name="l00396"></a><span class="lineno"> 396</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#ad0e1cf5e8520cb7a59cad8d6aecdf8a6">to</a>);</div>
<div class="line"><a id="l00397" name="l00397"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#a1e3b6d38df0786ccf7f938d60e386aae"> 397</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#a1e3b6d38df0786ccf7f938d60e386aae">Init</a>();</div>
<div class="line"><a id="l00398" name="l00398"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#a97db8ba091791787900dd812fefc10e5"> 398</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#a97db8ba091791787900dd812fefc10e5">from</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> from_; }</div>
<div class="line"><a id="l00399" name="l00399"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#ab54cc176a72a1a03b18cb3f9649c773a"> 399</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#ab54cc176a72a1a03b18cb3f9649c773a">via</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *via_; }</div>
<div class="line"><a id="l00400" name="l00400"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#ad0e1cf5e8520cb7a59cad8d6aecdf8a6"> 400</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#ad0e1cf5e8520cb7a59cad8d6aecdf8a6">to</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> to_; }</div>
<div class="line"><a id="l00401" name="l00401"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_search_path.html#a09f219a2226f7c0de0f50b6f00c099e3"> 401</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>* <a class="code hl_function" href="classoperations__research_1_1_knapsack_search_path.html#a09f219a2226f7c0de0f50b6f00c099e3">MoveUpToDepth</a>(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; node,</div>
<div class="line"><a id="l00402" name="l00402"></a><span class="lineno"> 402</span> <span class="keywordtype">int</span> depth) <span class="keyword">const</span>;</div>
<div class="line"><a id="l00403" name="l00403"></a><span class="lineno"> 403</span> </div>
<div class="line"><a id="l00404" name="l00404"></a><span class="lineno"> 404</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00405" name="l00405"></a><span class="lineno"> 405</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; from_;</div>
<div class="line"><a id="l00406" name="l00406"></a><span class="lineno"> 406</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>* via_; <span class="comment">// Computed in &#39;Init&#39;.</span></div>
<div class="line"><a id="l00407" name="l00407"></a><span class="lineno"> 407</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; to_;</div>
<div class="line"><a id="l00408" name="l00408"></a><span class="lineno"> 408</span> </div>
<div class="line"><a id="l00409" name="l00409"></a><span class="lineno"> 409</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_search_path.html">KnapsackSearchPath</a>);</div>
<div class="line"><a id="l00410" name="l00410"></a><span class="lineno"> 410</span>};</div>
<div class="line"><a id="l00411" name="l00411"></a><span class="lineno"> 411</span> </div>
<div class="line"><a id="l00412" name="l00412"></a><span class="lineno"> 412</span><span class="comment">// ----- KnapsackState -----</span></div>
<div class="line"><a id="l00413" name="l00413"></a><span class="lineno"> 413</span><span class="comment">// KnapsackState represents a partial solution to the knapsack problem.</span></div>
<div class="line"><a id="l00414" name="l00414"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html"> 414</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a> {</div>
<div class="line"><a id="l00415" name="l00415"></a><span class="lineno"> 415</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00416" name="l00416"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#a41f9430cc0090383e7797a88c1dbacbc"> 416</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a41f9430cc0090383e7797a88c1dbacbc">KnapsackState</a>();</div>
<div class="line"><a id="l00417" name="l00417"></a><span class="lineno"> 417</span> </div>
<div class="line"><a id="l00418" name="l00418"></a><span class="lineno"> 418</span> <span class="comment">// Initializes vectors with number_of_items set to false (i.e. not bound yet).</span></div>
<div class="line"><a id="l00419" name="l00419"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#a6308c7a97200f84f6ebf5b2c487b0362"> 419</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a6308c7a97200f84f6ebf5b2c487b0362">Init</a>(<span class="keywordtype">int</span> number_of_items);</div>
<div class="line"><a id="l00420" name="l00420"></a><span class="lineno"> 420</span> <span class="comment">// Updates the state by applying or reverting a decision.</span></div>
<div class="line"><a id="l00421" name="l00421"></a><span class="lineno"> 421</span> <span class="comment">// Returns false if fails, i.e. trying to apply an inconsistent decision</span></div>
<div class="line"><a id="l00422" name="l00422"></a><span class="lineno"> 422</span> <span class="comment">// to an already assigned item.</span></div>
<div class="line"><a id="l00423" name="l00423"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#ab771ac0e538f991b73b011ee3ba11f05"> 423</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#ab771ac0e538f991b73b011ee3ba11f05">UpdateState</a>(<span class="keywordtype">bool</span> revert, <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; assignment);</div>
<div class="line"><a id="l00424" name="l00424"></a><span class="lineno"> 424</span> </div>
<div class="line"><a id="l00425" name="l00425"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#a5c677592ee5e7312c64475ebae949eab"> 425</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a5c677592ee5e7312c64475ebae949eab">GetNumberOfItems</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> is_bound_.size(); }</div>
<div class="line"><a id="l00426" name="l00426"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#a89aa280d2321c1316aa1305106f1bb49"> 426</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a89aa280d2321c1316aa1305106f1bb49">is_bound</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> is_bound_.at(<span class="keywordtype">id</span>); }</div>
<div class="line"><a id="l00427" name="l00427"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_state.html#a862bf4e908cd82ea44f72e98558016ad"> 427</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a862bf4e908cd82ea44f72e98558016ad">is_in</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> is_in_.at(<span class="keywordtype">id</span>); }</div>
<div class="line"><a id="l00428" name="l00428"></a><span class="lineno"> 428</span> </div>
<div class="line"><a id="l00429" name="l00429"></a><span class="lineno"> 429</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00430" name="l00430"></a><span class="lineno"> 430</span> <span class="comment">// Vectors &#39;is_bound_&#39; and &#39;is_in_&#39; contain a boolean value for each item.</span></div>
<div class="line"><a id="l00431" name="l00431"></a><span class="lineno"> 431</span> <span class="comment">// &#39;is_bound_(item_i)&#39; is false when there is no decision for item_i yet.</span></div>
<div class="line"><a id="l00432" name="l00432"></a><span class="lineno"> 432</span> <span class="comment">// When item_i is bound, &#39;is_in_(item_i)&#39; represents the presence (true) or</span></div>
<div class="line"><a id="l00433" name="l00433"></a><span class="lineno"> 433</span> <span class="comment">// the absence (false) of item_i in the current solution.</span></div>
<div class="line"><a id="l00434" name="l00434"></a><span class="lineno"> 434</span> std::vector&lt;bool&gt; is_bound_;</div>
<div class="line"><a id="l00435" name="l00435"></a><span class="lineno"> 435</span> std::vector&lt;bool&gt; is_in_;</div>
<div class="line"><a id="l00436" name="l00436"></a><span class="lineno"> 436</span> </div>
<div class="line"><a id="l00437" name="l00437"></a><span class="lineno"> 437</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a>);</div>
<div class="line"><a id="l00438" name="l00438"></a><span class="lineno"> 438</span>};</div>
<div class="line"><a id="l00439" name="l00439"></a><span class="lineno"> 439</span> </div>
<div class="line"><a id="l00440" name="l00440"></a><span class="lineno"> 440</span><span class="comment">// ----- KnapsackPropagator -----</span></div>
<div class="line"><a id="l00441" name="l00441"></a><span class="lineno"> 441</span><span class="comment">// KnapsackPropagator is the base class for modeling and propagating a</span></div>
<div class="line"><a id="l00442" name="l00442"></a><span class="lineno"> 442</span><span class="comment">// constraint given an assignment.</span></div>
<div class="line"><a id="l00443" name="l00443"></a><span class="lineno"> 443</span><span class="comment">//</span></div>
<div class="line"><a id="l00444" name="l00444"></a><span class="lineno"> 444</span><span class="comment">// When some work has to be done both by the base and the derived class,</span></div>
<div class="line"><a id="l00445" name="l00445"></a><span class="lineno"> 445</span><span class="comment">// a protected pure virtual method ending by &#39;Propagator&#39; is defined.</span></div>
<div class="line"><a id="l00446" name="l00446"></a><span class="lineno"> 446</span><span class="comment">// For instance, &#39;Init&#39; creates a vector of items, and then calls</span></div>
<div class="line"><a id="l00447" name="l00447"></a><span class="lineno"> 447</span><span class="comment">// &#39;InitPropagator&#39; to let the derived class perform its own initialization.</span></div>
<div class="line"><a id="l00448" name="l00448"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html"> 448</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_propagator.html">KnapsackPropagator</a> {</div>
<div class="line"><a id="l00449" name="l00449"></a><span class="lineno"> 449</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00450" name="l00450"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#af28391017c090a638200c57b4c8a2ac1"> 450</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#af28391017c090a638200c57b4c8a2ac1">KnapsackPropagator</a>(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#afebda22d5e2e068671aa4dbfbe9024df">state</a>);</div>
<div class="line"><a id="l00451" name="l00451"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#accafea74a5951ec85cd803541f3ab3fe"> 451</a></span> <span class="keyword">virtual</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#accafea74a5951ec85cd803541f3ab3fe">~KnapsackPropagator</a>();</div>
<div class="line"><a id="l00452" name="l00452"></a><span class="lineno"> 452</span> </div>
<div class="line"><a id="l00453" name="l00453"></a><span class="lineno"> 453</span> <span class="comment">// Initializes data structure and then calls InitPropagator.</span></div>
<div class="line"><a id="l00454" name="l00454"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a04d8883567a6e02787f2362e6543a21b"> 454</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a04d8883567a6e02787f2362e6543a21b">Init</a>(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits,</div>
<div class="line"><a id="l00455" name="l00455"></a><span class="lineno"> 455</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; weights);</div>
<div class="line"><a id="l00456" name="l00456"></a><span class="lineno"> 456</span> </div>
<div class="line"><a id="l00457" name="l00457"></a><span class="lineno"> 457</span> <span class="comment">// Updates data structure and then calls UpdatePropagator.</span></div>
<div class="line"><a id="l00458" name="l00458"></a><span class="lineno"> 458</span> <span class="comment">// Returns false when failure.</span></div>
<div class="line"><a id="l00459" name="l00459"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#af4b38123d3654471f0868774c5ff877d"> 459</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#af4b38123d3654471f0868774c5ff877d">Update</a>(<span class="keywordtype">bool</span> revert, <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; assignment);</div>
<div class="line"><a id="l00460" name="l00460"></a><span class="lineno"> 460</span> <span class="comment">// ComputeProfitBounds should set &#39;profit_lower_bound_&#39; and</span></div>
<div class="line"><a id="l00461" name="l00461"></a><span class="lineno"> 461</span> <span class="comment">// &#39;profit_upper_bound_&#39; which are constraint specific.</span></div>
<div class="line"><a id="l00462" name="l00462"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a8ae457a5297bac5ad83517ba54b819d1"> 462</a></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a8ae457a5297bac5ad83517ba54b819d1">ComputeProfitBounds</a>() = 0;</div>
<div class="line"><a id="l00463" name="l00463"></a><span class="lineno"> 463</span> <span class="comment">// Returns the id of next item to assign.</span></div>
<div class="line"><a id="l00464" name="l00464"></a><span class="lineno"> 464</span> <span class="comment">// Returns kNoSelection when all items are bound.</span></div>
<div class="line"><a id="l00465" name="l00465"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a9aea5e61ac71dca1139fda445cc2dfee"> 465</a></span> <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a9aea5e61ac71dca1139fda445cc2dfee">GetNextItemId</a>() <span class="keyword">const</span> = 0;</div>
<div class="line"><a id="l00466" name="l00466"></a><span class="lineno"> 466</span> </div>
<div class="line"><a id="l00467" name="l00467"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a08beea2d857241d99287935a91be5217"> 467</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a08beea2d857241d99287935a91be5217">current_profit</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> current_profit_; }</div>
<div class="line"><a id="l00468" name="l00468"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#ae04e419341e0b9772a057aff10ce63a0"> 468</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#ae04e419341e0b9772a057aff10ce63a0">profit_lower_bound</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> profit_lower_bound_; }</div>
<div class="line"><a id="l00469" name="l00469"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#aa68069fd1180cb37fcdbc99d6230bc3e"> 469</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#aa68069fd1180cb37fcdbc99d6230bc3e">profit_upper_bound</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> profit_upper_bound_; }</div>
<div class="line"><a id="l00470" name="l00470"></a><span class="lineno"> 470</span> </div>
<div class="line"><a id="l00471" name="l00471"></a><span class="lineno"> 471</span> <span class="comment">// Copies the current state into &#39;solution&#39;.</span></div>
<div class="line"><a id="l00472" name="l00472"></a><span class="lineno"> 472</span> <span class="comment">// All unbound items are set to false (i.e. not in the knapsack).</span></div>
<div class="line"><a id="l00473" name="l00473"></a><span class="lineno"> 473</span> <span class="comment">// When &#39;has_one_propagator&#39; is true, CopyCurrentSolutionPropagator is called</span></div>
<div class="line"><a id="l00474" name="l00474"></a><span class="lineno"> 474</span> <span class="comment">// to have a better solution. When there is only one propagator</span></div>
<div class="line"><a id="l00475" name="l00475"></a><span class="lineno"> 475</span> <span class="comment">// there is no need to check the solution with other propagators, so the</span></div>
<div class="line"><a id="l00476" name="l00476"></a><span class="lineno"> 476</span> <span class="comment">// partial solution can be smartly completed.</span></div>
<div class="line"><a id="l00477" name="l00477"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a1fa45af1bf0d6aa9d5f86e2ed9ae5323"> 477</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a1fa45af1bf0d6aa9d5f86e2ed9ae5323">CopyCurrentStateToSolution</a>(<span class="keywordtype">bool</span> has_one_propagator,</div>
<div class="line"><a id="l00478" name="l00478"></a><span class="lineno"> 478</span> std::vector&lt;bool&gt;* solution) <span class="keyword">const</span>;</div>
<div class="line"><a id="l00479" name="l00479"></a><span class="lineno"> 479</span> </div>
<div class="line"><a id="l00480" name="l00480"></a><span class="lineno"> 480</span> <span class="keyword">protected</span>:</div>
<div class="line"><a id="l00481" name="l00481"></a><span class="lineno"> 481</span> <span class="comment">// Initializes data structure. This method is called after initialization</span></div>
<div class="line"><a id="l00482" name="l00482"></a><span class="lineno"> 482</span> <span class="comment">// of KnapsackPropagator data structure.</span></div>
<div class="line"><a id="l00483" name="l00483"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a883cd053b1e7322727eb9e19940f69f6"> 483</a></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a883cd053b1e7322727eb9e19940f69f6">InitPropagator</a>() = 0;</div>
<div class="line"><a id="l00484" name="l00484"></a><span class="lineno"> 484</span> </div>
<div class="line"><a id="l00485" name="l00485"></a><span class="lineno"> 485</span> <span class="comment">// Updates internal data structure incrementally. This method is called</span></div>
<div class="line"><a id="l00486" name="l00486"></a><span class="lineno"> 486</span> <span class="comment">// after update of KnapsackPropagator data structure.</span></div>
<div class="line"><a id="l00487" name="l00487"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a5a0d11be6f0d5b521477226fb7573db8"> 487</a></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a5a0d11be6f0d5b521477226fb7573db8">UpdatePropagator</a>(<span class="keywordtype">bool</span> revert,</div>
<div class="line"><a id="l00488" name="l00488"></a><span class="lineno"> 488</span> <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; assignment) = 0;</div>
<div class="line"><a id="l00489" name="l00489"></a><span class="lineno"> 489</span> </div>
<div class="line"><a id="l00490" name="l00490"></a><span class="lineno"> 490</span> <span class="comment">// Copies the current state into &#39;solution&#39;.</span></div>
<div class="line"><a id="l00491" name="l00491"></a><span class="lineno"> 491</span> <span class="comment">// Only unbound items have to be copied as CopyCurrentSolution was already</span></div>
<div class="line"><a id="l00492" name="l00492"></a><span class="lineno"> 492</span> <span class="comment">// called with current state.</span></div>
<div class="line"><a id="l00493" name="l00493"></a><span class="lineno"> 493</span> <span class="comment">// This method is useful when a propagator is able to find a better solution</span></div>
<div class="line"><a id="l00494" name="l00494"></a><span class="lineno"> 494</span> <span class="comment">// than the blind instantiation to false of unbound items.</span></div>
<div class="line"><a id="l00495" name="l00495"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#ab803770e8e21bb448a2f3d940ab125f8"> 495</a></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#ab803770e8e21bb448a2f3d940ab125f8">CopyCurrentStateToSolutionPropagator</a>(</div>
<div class="line"><a id="l00496" name="l00496"></a><span class="lineno"> 496</span> std::vector&lt;bool&gt;* solution) <span class="keyword">const</span> = 0;</div>
<div class="line"><a id="l00497" name="l00497"></a><span class="lineno"> 497</span> </div>
<div class="line"><a id="l00498" name="l00498"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#afebda22d5e2e068671aa4dbfbe9024df"> 498</a></span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#afebda22d5e2e068671aa4dbfbe9024df">state</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> state_; }</div>
<div class="line"><a id="l00499" name="l00499"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#a701e8fc6dbf7ffeb4c48512ffa6d7501"> 499</a></span> <span class="keyword">const</span> std::vector&lt;KnapsackItemPtr&gt;&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#a701e8fc6dbf7ffeb4c48512ffa6d7501">items</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> items_; }</div>
<div class="line"><a id="l00500" name="l00500"></a><span class="lineno"> 500</span> </div>
<div class="line"><a id="l00501" name="l00501"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#ae29226a5be6204e26f1d563a6630ab9e"> 501</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#ae29226a5be6204e26f1d563a6630ab9e">set_profit_lower_bound</a>(int64_t profit) { profit_lower_bound_ = profit; }</div>
<div class="line"><a id="l00502" name="l00502"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_propagator.html#af991b29f273c53c8b35cb09bcccf3a5d"> 502</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#af991b29f273c53c8b35cb09bcccf3a5d">set_profit_upper_bound</a>(int64_t profit) { profit_upper_bound_ = profit; }</div>
<div class="line"><a id="l00503" name="l00503"></a><span class="lineno"> 503</span> </div>
<div class="line"><a id="l00504" name="l00504"></a><span class="lineno"> 504</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00505" name="l00505"></a><span class="lineno"> 505</span> std::vector&lt;KnapsackItemPtr&gt; items_;</div>
<div class="line"><a id="l00506" name="l00506"></a><span class="lineno"> 506</span> int64_t current_profit_;</div>
<div class="line"><a id="l00507" name="l00507"></a><span class="lineno"> 507</span> int64_t profit_lower_bound_;</div>
<div class="line"><a id="l00508" name="l00508"></a><span class="lineno"> 508</span> int64_t profit_upper_bound_;</div>
<div class="line"><a id="l00509" name="l00509"></a><span class="lineno"> 509</span> <span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a>&amp; state_;</div>
<div class="line"><a id="l00510" name="l00510"></a><span class="lineno"> 510</span> </div>
<div class="line"><a id="l00511" name="l00511"></a><span class="lineno"> 511</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_propagator.html">KnapsackPropagator</a>);</div>
<div class="line"><a id="l00512" name="l00512"></a><span class="lineno"> 512</span>};</div>
<div class="line"><a id="l00513" name="l00513"></a><span class="lineno"> 513</span> </div>
<div class="line"><a id="l00514" name="l00514"></a><span class="lineno"> 514</span><span class="comment">// ----- KnapsackCapacityPropagator -----</span></div>
<div class="line"><a id="l00515" name="l00515"></a><span class="lineno"> 515</span><span class="comment">// KnapsackCapacityPropagator is a KnapsackPropagator used to enforce</span></div>
<div class="line"><a id="l00516" name="l00516"></a><span class="lineno"> 516</span><span class="comment">// a capacity constraint.</span></div>
<div class="line"><a id="l00517" name="l00517"></a><span class="lineno"> 517</span><span class="comment">// As a KnapsackPropagator is supposed to compute profit lower and upper</span></div>
<div class="line"><a id="l00518" name="l00518"></a><span class="lineno"> 518</span><span class="comment">// bounds, and get the next item to select, it can be seen as a 0-1 Knapsack</span></div>
<div class="line"><a id="l00519" name="l00519"></a><span class="lineno"> 519</span><span class="comment">// solver. The most efficient way to compute the upper bound is to iterate on</span></div>
<div class="line"><a id="l00520" name="l00520"></a><span class="lineno"> 520</span><span class="comment">// items in profit-per-unit-weight decreasing order. The break item is</span></div>
<div class="line"><a id="l00521" name="l00521"></a><span class="lineno"> 521</span><span class="comment">// commonly defined as the first item for which there is not enough remaining</span></div>
<div class="line"><a id="l00522" name="l00522"></a><span class="lineno"> 522</span><span class="comment">// capacity. Selecting this break item as the next-item-to-assign usually</span></div>
<div class="line"><a id="l00523" name="l00523"></a><span class="lineno"> 523</span><span class="comment">// gives the best results (see Greenberg &amp; Hegerich).</span></div>
<div class="line"><a id="l00524" name="l00524"></a><span class="lineno"> 524</span><span class="comment">//</span></div>
<div class="line"><a id="l00525" name="l00525"></a><span class="lineno"> 525</span><span class="comment">// This is exactly what is implemented in this class.</span></div>
<div class="line"><a id="l00526" name="l00526"></a><span class="lineno"> 526</span><span class="comment">//</span></div>
<div class="line"><a id="l00527" name="l00527"></a><span class="lineno"> 527</span><span class="comment">// When there is only one propagator, it is possible to compute a better</span></div>
<div class="line"><a id="l00528" name="l00528"></a><span class="lineno"> 528</span><span class="comment">// profit lower bound almost for free. During the scan to find the</span></div>
<div class="line"><a id="l00529" name="l00529"></a><span class="lineno"> 529</span><span class="comment">// break element all unbound items are added just as if they were part of</span></div>
<div class="line"><a id="l00530" name="l00530"></a><span class="lineno"> 530</span><span class="comment">// the current solution. This is used in both ComputeProfitBounds and</span></div>
<div class="line"><a id="l00531" name="l00531"></a><span class="lineno"> 531</span><span class="comment">// CopyCurrentSolutionPropagator.</span></div>
<div class="line"><a id="l00532" name="l00532"></a><span class="lineno"> 532</span><span class="comment">// For incrementality reasons, the ith item should be accessible in O(1). That&#39;s</span></div>
<div class="line"><a id="l00533" name="l00533"></a><span class="lineno"> 533</span><span class="comment">// the reason why the item vector has to be duplicated &#39;sorted_items_&#39;.</span></div>
<div class="line"><a id="l00534" name="l00534"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html"> 534</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_capacity_propagator.html">KnapsackCapacityPropagator</a> : <span class="keyword">public</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_propagator.html">KnapsackPropagator</a> {</div>
<div class="line"><a id="l00535" name="l00535"></a><span class="lineno"> 535</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00536" name="l00536"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a2ce43dc07784f3d9634df0a5c0dc39b0"> 536</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a2ce43dc07784f3d9634df0a5c0dc39b0">KnapsackCapacityPropagator</a>(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_state.html">KnapsackState</a>&amp; <a class="code hl_function" href="classoperations__research_1_1_knapsack_propagator.html#afebda22d5e2e068671aa4dbfbe9024df">state</a>, int64_t capacity);</div>
<div class="line"><a id="l00537" name="l00537"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#aa14e63156675c18c06073ac1cb8aa170"> 537</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#aa14e63156675c18c06073ac1cb8aa170">~KnapsackCapacityPropagator</a>() <span class="keyword">override</span>;</div>
<div class="line"><a id="l00538" name="l00538"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a9921c39ed90a9cd32301ee0fee9491cb"> 538</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a9921c39ed90a9cd32301ee0fee9491cb">ComputeProfitBounds</a>() <span class="keyword">override</span>;</div>
<div class="line"><a id="l00539" name="l00539"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#afccfe4a5a27c2c805016d82886795da9"> 539</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#afccfe4a5a27c2c805016d82886795da9">GetNextItemId</a>()<span class="keyword"> const override </span>{ <span class="keywordflow">return</span> break_item_id_; }</div>
<div class="line"><a id="l00540" name="l00540"></a><span class="lineno"> 540</span> </div>
<div class="line"><a id="l00541" name="l00541"></a><span class="lineno"> 541</span> <span class="keyword">protected</span>:</div>
<div class="line"><a id="l00542" name="l00542"></a><span class="lineno"> 542</span> <span class="comment">// Initializes KnapsackCapacityPropagator (e.g., sort items in decreasing</span></div>
<div class="line"><a id="l00543" name="l00543"></a><span class="lineno"> 543</span> <span class="comment">// order).</span></div>
<div class="line"><a id="l00544" name="l00544"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#ae2545020be753ee6a66c277daac41784"> 544</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#ae2545020be753ee6a66c277daac41784">InitPropagator</a>() <span class="keyword">override</span>;</div>
<div class="line"><a id="l00545" name="l00545"></a><span class="lineno"> 545</span> <span class="comment">// Updates internal data structure incrementally (i.e., &#39;consumed_capacity_&#39;)</span></div>
<div class="line"><a id="l00546" name="l00546"></a><span class="lineno"> 546</span> <span class="comment">// to avoid a O(number_of_items) scan.</span></div>
<div class="line"><a id="l00547" name="l00547"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a3cde41b7fa0c9734783a562aadd9ef8c"> 547</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a3cde41b7fa0c9734783a562aadd9ef8c">UpdatePropagator</a>(<span class="keywordtype">bool</span> revert,</div>
<div class="line"><a id="l00548" name="l00548"></a><span class="lineno"> 548</span> <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; assignment) <span class="keyword">override</span>;</div>
<div class="line"><a id="l00549" name="l00549"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a706a3a7c9568016131afd718f347ec8d"> 549</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_capacity_propagator.html#a706a3a7c9568016131afd718f347ec8d">CopyCurrentStateToSolutionPropagator</a>(</div>
<div class="line"><a id="l00550" name="l00550"></a><span class="lineno"> 550</span> std::vector&lt;bool&gt;* solution) <span class="keyword">const override</span>;</div>
<div class="line"><a id="l00551" name="l00551"></a><span class="lineno"> 551</span> </div>
<div class="line"><a id="l00552" name="l00552"></a><span class="lineno"> 552</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00553" name="l00553"></a><span class="lineno"> 553</span> <span class="comment">// An obvious additional profit upper bound corresponds to the linear</span></div>
<div class="line"><a id="l00554" name="l00554"></a><span class="lineno"> 554</span> <span class="comment">// relaxation: remaining_capacity * efficiency of the break item.</span></div>
<div class="line"><a id="l00555" name="l00555"></a><span class="lineno"> 555</span> <span class="comment">// It is possible to do better in O(1), using Martello-Toth bound U2.</span></div>
<div class="line"><a id="l00556" name="l00556"></a><span class="lineno"> 556</span> <span class="comment">// The main idea is to enforce integrality constraint on the break item,</span></div>
<div class="line"><a id="l00557" name="l00557"></a><span class="lineno"> 557</span> <span class="comment">// ie. either the break item is part of the solution, either it is not.</span></div>
<div class="line"><a id="l00558" name="l00558"></a><span class="lineno"> 558</span> <span class="comment">// So basically the linear relaxation is done on the item before the break</span></div>
<div class="line"><a id="l00559" name="l00559"></a><span class="lineno"> 559</span> <span class="comment">// item, or the one after the break item.</span></div>
<div class="line"><a id="l00560" name="l00560"></a><span class="lineno"> 560</span> <span class="comment">// This is what GetAdditionalProfit method implements.</span></div>
<div class="line"><a id="l00561" name="l00561"></a><span class="lineno"> 561</span> int64_t GetAdditionalProfit(int64_t remaining_capacity,</div>
<div class="line"><a id="l00562" name="l00562"></a><span class="lineno"> 562</span> <span class="keywordtype">int</span> break_item_id) <span class="keyword">const</span>;</div>
<div class="line"><a id="l00563" name="l00563"></a><span class="lineno"> 563</span> </div>
<div class="line"><a id="l00564" name="l00564"></a><span class="lineno"> 564</span> <span class="keyword">const</span> int64_t capacity_;</div>
<div class="line"><a id="l00565" name="l00565"></a><span class="lineno"> 565</span> int64_t consumed_capacity_;</div>
<div class="line"><a id="l00566" name="l00566"></a><span class="lineno"> 566</span> <span class="keywordtype">int</span> break_item_id_;</div>
<div class="line"><a id="l00567" name="l00567"></a><span class="lineno"> 567</span> std::vector&lt;KnapsackItemPtr&gt; sorted_items_;</div>
<div class="line"><a id="l00568" name="l00568"></a><span class="lineno"> 568</span> int64_t profit_max_;</div>
<div class="line"><a id="l00569" name="l00569"></a><span class="lineno"> 569</span> </div>
<div class="line"><a id="l00570" name="l00570"></a><span class="lineno"> 570</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_class" href="classoperations__research_1_1_knapsack_capacity_propagator.html">KnapsackCapacityPropagator</a>);</div>
<div class="line"><a id="l00571" name="l00571"></a><span class="lineno"> 571</span>};</div>
<div class="line"><a id="l00572" name="l00572"></a><span class="lineno"> 572</span> </div>
<div class="line"><a id="l00573" name="l00573"></a><span class="lineno"> 573</span><span class="comment">// ----- BaseKnapsackSolver -----</span></div>
<div class="line"><a id="l00574" name="l00574"></a><span class="lineno"> 574</span><span class="comment">// This is the base class for knapsack solvers.</span></div>
<div class="line"><a id="l00575" name="l00575"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html"> 575</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_base_knapsack_solver.html">BaseKnapsackSolver</a> {</div>
<div class="line"><a id="l00576" name="l00576"></a><span class="lineno"> 576</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00577" name="l00577"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#ac6518fa5a6dd37173c7700bc2d9b6071"> 577</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#ac6518fa5a6dd37173c7700bc2d9b6071">BaseKnapsackSolver</a>(<span class="keyword">const</span> std::string&amp; solver_name)</div>
<div class="line"><a id="l00578" name="l00578"></a><span class="lineno"> 578</span> : solver_name_(solver_name) {}</div>
<div class="line"><a id="l00579" name="l00579"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#ab5b44517ac32ba76590129831a826096"> 579</a></span> <span class="keyword">virtual</span> <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#ab5b44517ac32ba76590129831a826096">~BaseKnapsackSolver</a>() {}</div>
<div class="line"><a id="l00580" name="l00580"></a><span class="lineno"> 580</span> </div>
<div class="line"><a id="l00581" name="l00581"></a><span class="lineno"> 581</span> <span class="comment">// Initializes the solver and enters the problem to be solved.</span></div>
<div class="line"><a id="l00582" name="l00582"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#abb1c2efb23ee210447502a9baab0812a"> 582</a></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#abb1c2efb23ee210447502a9baab0812a">Init</a>(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits,</div>
<div class="line"><a id="l00583" name="l00583"></a><span class="lineno"> 583</span> <span class="keyword">const</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;&amp; weights,</div>
<div class="line"><a id="l00584" name="l00584"></a><span class="lineno"> 584</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; capacities) = 0;</div>
<div class="line"><a id="l00585" name="l00585"></a><span class="lineno"> 585</span> </div>
<div class="line"><a id="l00586" name="l00586"></a><span class="lineno"> 586</span> <span class="comment">// Gets the lower and upper bound when the item is in or out of the knapsack.</span></div>
<div class="line"><a id="l00587" name="l00587"></a><span class="lineno"> 587</span> <span class="comment">// To ensure objects are correctly initialized, this method should not be</span></div>
<div class="line"><a id="l00588" name="l00588"></a><span class="lineno"> 588</span> <span class="comment">// called before ::Init.</span></div>
<div class="line"><a id="l00589" name="l00589"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#a89ae568099e8a8937bb049a1626e6d3a"> 589</a></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#a89ae568099e8a8937bb049a1626e6d3a">GetLowerAndUpperBoundWhenItem</a>(<span class="keywordtype">int</span> item_id, <span class="keywordtype">bool</span> is_item_in,</div>
<div class="line"><a id="l00590" name="l00590"></a><span class="lineno"> 590</span> int64_t* lower_bound,</div>
<div class="line"><a id="l00591" name="l00591"></a><span class="lineno"> 591</span> int64_t* upper_bound);</div>
<div class="line"><a id="l00592" name="l00592"></a><span class="lineno"> 592</span> </div>
<div class="line"><a id="l00593" name="l00593"></a><span class="lineno"> 593</span> <span class="comment">// Solves the problem and returns the profit of the optimal solution.</span></div>
<div class="line"><a id="l00594" name="l00594"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#aae09d1be6e3ce3d746c833f7da003de9"> 594</a></span> <span class="keyword">virtual</span> int64_t <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#aae09d1be6e3ce3d746c833f7da003de9">Solve</a>(TimeLimit* time_limit, <span class="keywordtype">bool</span>* is_solution_optimal) = 0;</div>
<div class="line"><a id="l00595" name="l00595"></a><span class="lineno"> 595</span> </div>
<div class="line"><a id="l00596" name="l00596"></a><span class="lineno"> 596</span> <span class="comment">// Returns true if the item &#39;item_id&#39; is packed in the optimal knapsack.</span></div>
<div class="line"><a id="l00597" name="l00597"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#af75968e8e76e35de6e7cdfaa0488b131"> 597</a></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#af75968e8e76e35de6e7cdfaa0488b131">best_solution</a>(<span class="keywordtype">int</span> item_id) <span class="keyword">const</span> = 0;</div>
<div class="line"><a id="l00598" name="l00598"></a><span class="lineno"> 598</span> </div>
<div class="line"><a id="l00599" name="l00599"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_base_knapsack_solver.html#ae194e7bee4a383e5ee6c8ed341b49b7e"> 599</a></span> <span class="keyword">virtual</span> std::string <a class="code hl_function" href="classoperations__research_1_1_base_knapsack_solver.html#ae194e7bee4a383e5ee6c8ed341b49b7e">GetName</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> solver_name_; }</div>
<div class="line"><a id="l00600" name="l00600"></a><span class="lineno"> 600</span> </div>
<div class="line"><a id="l00601" name="l00601"></a><span class="lineno"> 601</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00602" name="l00602"></a><span class="lineno"> 602</span> <span class="keyword">const</span> std::string solver_name_;</div>
<div class="line"><a id="l00603" name="l00603"></a><span class="lineno"> 603</span>};</div>
<div class="line"><a id="l00604" name="l00604"></a><span class="lineno"> 604</span> </div>
<div class="line"><a id="l00605" name="l00605"></a><span class="lineno"> 605</span><span class="comment">// ----- KnapsackGenericSolver -----</span></div>
<div class="line"><a id="l00606" name="l00606"></a><span class="lineno"> 606</span><span class="comment">// KnapsackGenericSolver is the multi-dimensional knapsack solver class.</span></div>
<div class="line"><a id="l00607" name="l00607"></a><span class="lineno"> 607</span><span class="comment">// In the current implementation, the next item to assign is given by the</span></div>
<div class="line"><a id="l00608" name="l00608"></a><span class="lineno"> 608</span><span class="comment">// master propagator. Using SetMasterPropagator allows changing the default</span></div>
<div class="line"><a id="l00609" name="l00609"></a><span class="lineno"> 609</span><span class="comment">// (propagator of the first dimension), and selecting another dimension when</span></div>
<div class="line"><a id="l00610" name="l00610"></a><span class="lineno"> 610</span><span class="comment">// more constrained.</span></div>
<div class="line"><a id="l00611" name="l00611"></a><span class="lineno"> 611</span><span class="comment">// TODO(user): In the case of a multi-dimensional knapsack problem, implement</span></div>
<div class="line"><a id="l00612" name="l00612"></a><span class="lineno"> 612</span><span class="comment">// an aggregated propagator to combine all dimensions and give a better guide</span></div>
<div class="line"><a id="l00613" name="l00613"></a><span class="lineno"> 613</span><span class="comment">// to select the next item (see, for instance, Dobson&#39;s aggregated efficiency).</span></div>
<div class="line"><a id="l00614" name="l00614"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html"> 614</a></span><span class="keyword">class </span><a class="code hl_class" href="classoperations__research_1_1_knapsack_generic_solver.html">KnapsackGenericSolver</a> : <span class="keyword">public</span> <a class="code hl_class" href="classoperations__research_1_1_base_knapsack_solver.html">BaseKnapsackSolver</a> {</div>
<div class="line"><a id="l00615" name="l00615"></a><span class="lineno"> 615</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00616" name="l00616"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a2a7bff5cf8a51192eadec54eb0499064"> 616</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a2a7bff5cf8a51192eadec54eb0499064">KnapsackGenericSolver</a>(<span class="keyword">const</span> std::string&amp; solver_name);</div>
<div class="line"><a id="l00617" name="l00617"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a2a25594d97a0a532f9d814bdc6dea380"> 617</a></span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a2a25594d97a0a532f9d814bdc6dea380">~KnapsackGenericSolver</a>() <span class="keyword">override</span>;</div>
<div class="line"><a id="l00618" name="l00618"></a><span class="lineno"> 618</span> </div>
<div class="line"><a id="l00619" name="l00619"></a><span class="lineno"> 619</span> <span class="comment">// Initializes the solver and enters the problem to be solved.</span></div>
<div class="line"><a id="l00620" name="l00620"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a734b6464309adbbdeb63ef759f690ff1"> 620</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a734b6464309adbbdeb63ef759f690ff1">Init</a>(<span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; profits,</div>
<div class="line"><a id="l00621" name="l00621"></a><span class="lineno"> 621</span> <span class="keyword">const</span> std::vector&lt;std::vector&lt;int64_t&gt; &gt;&amp; weights,</div>
<div class="line"><a id="l00622" name="l00622"></a><span class="lineno"> 622</span> <span class="keyword">const</span> std::vector&lt;int64_t&gt;&amp; capacities) <span class="keyword">override</span>;</div>
<div class="line"><a id="l00623" name="l00623"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a5c677592ee5e7312c64475ebae949eab"> 623</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a5c677592ee5e7312c64475ebae949eab">GetNumberOfItems</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> state_.<a class="code hl_function" href="classoperations__research_1_1_knapsack_state.html#a5c677592ee5e7312c64475ebae949eab">GetNumberOfItems</a>(); }</div>
<div class="line"><a id="l00624" name="l00624"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#ac9849a7043959c65033fa6f4a63bb10e"> 624</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#ac9849a7043959c65033fa6f4a63bb10e">GetLowerAndUpperBoundWhenItem</a>(<span class="keywordtype">int</span> item_id, <span class="keywordtype">bool</span> is_item_in,</div>
<div class="line"><a id="l00625" name="l00625"></a><span class="lineno"> 625</span> int64_t* lower_bound,</div>
<div class="line"><a id="l00626" name="l00626"></a><span class="lineno"> 626</span> int64_t* upper_bound) <span class="keyword">override</span>;</div>
<div class="line"><a id="l00627" name="l00627"></a><span class="lineno"> 627</span> </div>
<div class="line"><a id="l00628" name="l00628"></a><span class="lineno"> 628</span> <span class="comment">// Sets which propagator should be used to guide the search.</span></div>
<div class="line"><a id="l00629" name="l00629"></a><span class="lineno"> 629</span> <span class="comment">// &#39;master_propagator_id&#39; should be in 0..p-1 with p the number of</span></div>
<div class="line"><a id="l00630" name="l00630"></a><span class="lineno"> 630</span> <span class="comment">// propagators.</span></div>
<div class="line"><a id="l00631" name="l00631"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a3df2fc3d96fbcac78a632d7dbf3b8550"> 631</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a3df2fc3d96fbcac78a632d7dbf3b8550">set_master_propagator_id</a>(<span class="keywordtype">int</span> master_propagator_id) {</div>
<div class="line"><a id="l00632" name="l00632"></a><span class="lineno"> 632</span> master_propagator_id_ = master_propagator_id;</div>
<div class="line"><a id="l00633" name="l00633"></a><span class="lineno"> 633</span> }</div>
<div class="line"><a id="l00634" name="l00634"></a><span class="lineno"> 634</span> </div>
<div class="line"><a id="l00635" name="l00635"></a><span class="lineno"> 635</span> <span class="comment">// Solves the problem and returns the profit of the optimal solution.</span></div>
<div class="line"><a id="l00636" name="l00636"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#a788a597dac89a082d3ed4994d654dec1"> 636</a></span> int64_t <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a788a597dac89a082d3ed4994d654dec1">Solve</a>(TimeLimit* time_limit, <span class="keywordtype">bool</span>* is_solution_optimal) <span class="keyword">override</span>;</div>
<div class="line"><a id="l00637" name="l00637"></a><span class="lineno"> 637</span> <span class="comment">// Returns true if the item &#39;item_id&#39; is packed in the optimal knapsack.</span></div>
<div class="line"><a id="l00638" name="l00638"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_knapsack_generic_solver.html#abfd4cb3faa2f1d6840b8123765fa2fc4"> 638</a></span> <span class="keywordtype">bool</span> <a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#abfd4cb3faa2f1d6840b8123765fa2fc4">best_solution</a>(<span class="keywordtype">int</span> item_id)<span class="keyword"> const override </span>{</div>
<div class="line"><a id="l00639" name="l00639"></a><span class="lineno"> 639</span> <span class="keywordflow">return</span> best_solution_.at(item_id);</div>
<div class="line"><a id="l00640" name="l00640"></a><span class="lineno"> 640</span> }</div>
<div class="line"><a id="l00641" name="l00641"></a><span class="lineno"> 641</span> </div>
<div class="line"><a id="l00642" name="l00642"></a><span class="lineno"> 642</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00643" name="l00643"></a><span class="lineno"> 643</span> <span class="comment">// Clears internal data structure.</span></div>
<div class="line"><a id="l00644" name="l00644"></a><span class="lineno"> 644</span> <span class="keywordtype">void</span> Clear();</div>
<div class="line"><a id="l00645" name="l00645"></a><span class="lineno"> 645</span> </div>
<div class="line"><a id="l00646" name="l00646"></a><span class="lineno"> 646</span> <span class="comment">// Updates all propagators reverting/applying all decision on the path.</span></div>
<div class="line"><a id="l00647" name="l00647"></a><span class="lineno"> 647</span> <span class="comment">// Returns true if fails. Note that, even if fails, all propagators should</span></div>
<div class="line"><a id="l00648" name="l00648"></a><span class="lineno"> 648</span> <span class="comment">// be updated to be in a stable state in order to stay incremental.</span></div>
<div class="line"><a id="l00649" name="l00649"></a><span class="lineno"> 649</span> <span class="keywordtype">bool</span> UpdatePropagators(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_path.html">KnapsackSearchPath</a>&amp; path);</div>
<div class="line"><a id="l00650" name="l00650"></a><span class="lineno"> 650</span> <span class="comment">// Updates all propagators reverting/applying one decision.</span></div>
<div class="line"><a id="l00651" name="l00651"></a><span class="lineno"> 651</span> <span class="comment">// Return true if fails. Note that, even if fails, all propagators should</span></div>
<div class="line"><a id="l00652" name="l00652"></a><span class="lineno"> 652</span> <span class="comment">// be updated to be in a stable state in order to stay incremental.</span></div>
<div class="line"><a id="l00653" name="l00653"></a><span class="lineno"> 653</span> <span class="keywordtype">bool</span> IncrementalUpdate(<span class="keywordtype">bool</span> revert, <span class="keyword">const</span> <a class="code hl_struct" href="structoperations__research_1_1_knapsack_assignment.html">KnapsackAssignment</a>&amp; assignment);</div>
<div class="line"><a id="l00654" name="l00654"></a><span class="lineno"> 654</span> <span class="comment">// Updates the best solution if the current solution has a better profit.</span></div>
<div class="line"><a id="l00655" name="l00655"></a><span class="lineno"> 655</span> <span class="keywordtype">void</span> UpdateBestSolution();</div>
<div class="line"><a id="l00656" name="l00656"></a><span class="lineno"> 656</span> </div>
<div class="line"><a id="l00657" name="l00657"></a><span class="lineno"> 657</span> <span class="comment">// Returns true if new relevant search node was added to the nodes array, that</span></div>
<div class="line"><a id="l00658" name="l00658"></a><span class="lineno"> 658</span> <span class="comment">// means this node should be added to the search queue too.</span></div>
<div class="line"><a id="l00659" name="l00659"></a><span class="lineno"> 659</span> <span class="keywordtype">bool</span> MakeNewNode(<span class="keyword">const</span> <a class="code hl_class" href="classoperations__research_1_1_knapsack_search_node.html">KnapsackSearchNode</a>&amp; node, <span class="keywordtype">bool</span> is_in);</div>
<div class="line"><a id="l00660" name="l00660"></a><span class="lineno"> 660</span> </div>
<div class="line"><a id="l00661" name="l00661"></a><span class="lineno"> 661</span> <span class="comment">// Gets the aggregated (min) profit upper bound among all propagators.</span></div>
<div class="line"><a id="l00662" name="l00662"></a><span class="lineno"> 662</span> int64_t GetAggregatedProfitUpperBound() <span class="keyword">const</span>;</div>
<div class="line"><a id="l00663" name="l00663"></a><span class="lineno"> 663</span> <span class="keywordtype">bool</span> HasOnePropagator()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> propagators_.size() == 1; }</div>
<div class="line"><a id="l00664" name="l00664"></a><span class="lineno"> 664</span> int64_t GetCurrentProfit()<span class="keyword"> const </span>{</div>
<div class="line"><a id="l00665" name="l00665"></a><span class="lineno"> 665</span> <span class="keywordflow">return</span> propagators_.at(master_propagator_id_)-&gt;current_profit();</div>
<div class="line"><a id="l00666" name="l00666"></a><span class="lineno"> 666</span> }</div>
<div class="line"><a id="l00667" name="l00667"></a><span class="lineno"> 667</span> int64_t GetNextItemId()<span class="keyword"> const </span>{</div>
<div class="line"><a id="l00668" name="l00668"></a><span class="lineno"> 668</span> <span class="keywordflow">return</span> propagators_.at(master_propagator_id_)-&gt;GetNextItemId();</div>
<div class="line"><a id="l00669" name="l00669"></a><span class="lineno"> 669</span> }</div>
<div class="line"><a id="l00670" name="l00670"></a><span class="lineno"> 670</span> </div>
<div class="line"><a id="l00671" name="l00671"></a><span class="lineno"> 671</span> std::vector&lt;KnapsackPropagator*&gt; propagators_;</div>
<div class="line"><a id="l00672" name="l00672"></a><span class="lineno"> 672</span> <span class="keywordtype">int</span> master_propagator_id_;</div>
<div class="line"><a id="l00673" name="l00673"></a><span class="lineno"> 673</span> std::vector&lt;KnapsackSearchNode*&gt; search_nodes_;</div>
<div class="line"><a id="l00674" name="l00674"></a><span class="lineno"> 674</span> KnapsackState state_;</div>
<div class="line"><a id="l00675" name="l00675"></a><span class="lineno"> 675</span> int64_t best_solution_profit_;</div>
<div class="line"><a id="l00676" name="l00676"></a><span class="lineno"> 676</span> std::vector&lt;bool&gt; best_solution_;</div>
<div class="line"><a id="l00677" name="l00677"></a><span class="lineno"> 677</span> </div>
<div class="line"><a id="l00678" name="l00678"></a><span class="lineno"> 678</span> DISALLOW_COPY_AND_ASSIGN(<a class="code hl_function" href="classoperations__research_1_1_knapsack_generic_solver.html#a2a7bff5cf8a51192eadec54eb0499064">KnapsackGenericSolver</a>);</div>
<div class="line"><a id="l00679" name="l00679"></a><span class="lineno"> 679</span>};</div>
<div class="line"><a id="l00680" name="l00680"></a><span class="lineno"> 680</span><span class="preprocessor">#endif </span><span class="comment">// SWIG</span></div>
<div class="line"><a id="l00681" name="l00681"></a><span class="lineno"> 681</span>} <span class="comment">// namespace operations_research</span></div>
<div class="line"><a id="l00682" name="l00682"></a><span class="lineno"> 682</span> </div>
<div class="line"><a id="l00683" name="l00683"></a><span class="lineno"> 683</span><span class="preprocessor">#endif </span><span class="comment">// OR_TOOLS_ALGORITHMS_KNAPSACK_SOLVER_H_</span></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html">operations_research::BaseKnapsackSolver</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00575">knapsack_solver.h:575</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_a89ae568099e8a8937bb049a1626e6d3a"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#a89ae568099e8a8937bb049a1626e6d3a">operations_research::BaseKnapsackSolver::GetLowerAndUpperBoundWhenItem</a></div><div class="ttdeci">virtual void GetLowerAndUpperBoundWhenItem(int item_id, bool is_item_in, int64_t *lower_bound, int64_t *upper_bound)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_aae09d1be6e3ce3d746c833f7da003de9"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#aae09d1be6e3ce3d746c833f7da003de9">operations_research::BaseKnapsackSolver::Solve</a></div><div class="ttdeci">virtual int64_t Solve(TimeLimit *time_limit, bool *is_solution_optimal)=0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_ab5b44517ac32ba76590129831a826096"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#ab5b44517ac32ba76590129831a826096">operations_research::BaseKnapsackSolver::~BaseKnapsackSolver</a></div><div class="ttdeci">virtual ~BaseKnapsackSolver()</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00579">knapsack_solver.h:579</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_abb1c2efb23ee210447502a9baab0812a"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#abb1c2efb23ee210447502a9baab0812a">operations_research::BaseKnapsackSolver::Init</a></div><div class="ttdeci">virtual void Init(const std::vector&lt; int64_t &gt; &amp;profits, const std::vector&lt; std::vector&lt; int64_t &gt; &gt; &amp;weights, const std::vector&lt; int64_t &gt; &amp;capacities)=0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_ac6518fa5a6dd37173c7700bc2d9b6071"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#ac6518fa5a6dd37173c7700bc2d9b6071">operations_research::BaseKnapsackSolver::BaseKnapsackSolver</a></div><div class="ttdeci">BaseKnapsackSolver(const std::string &amp;solver_name)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00577">knapsack_solver.h:577</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_ae194e7bee4a383e5ee6c8ed341b49b7e"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#ae194e7bee4a383e5ee6c8ed341b49b7e">operations_research::BaseKnapsackSolver::GetName</a></div><div class="ttdeci">virtual std::string GetName() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00599">knapsack_solver.h:599</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_base_knapsack_solver_html_af75968e8e76e35de6e7cdfaa0488b131"><div class="ttname"><a href="classoperations__research_1_1_base_knapsack_solver.html#af75968e8e76e35de6e7cdfaa0488b131">operations_research::BaseKnapsackSolver::best_solution</a></div><div class="ttdeci">virtual bool best_solution(int item_id) const =0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html">operations_research::KnapsackCapacityPropagator</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00534">knapsack_solver.h:534</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_a2ce43dc07784f3d9634df0a5c0dc39b0"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#a2ce43dc07784f3d9634df0a5c0dc39b0">operations_research::KnapsackCapacityPropagator::KnapsackCapacityPropagator</a></div><div class="ttdeci">KnapsackCapacityPropagator(const KnapsackState &amp;state, int64_t capacity)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_a3cde41b7fa0c9734783a562aadd9ef8c"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#a3cde41b7fa0c9734783a562aadd9ef8c">operations_research::KnapsackCapacityPropagator::UpdatePropagator</a></div><div class="ttdeci">bool UpdatePropagator(bool revert, const KnapsackAssignment &amp;assignment) override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_a706a3a7c9568016131afd718f347ec8d"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#a706a3a7c9568016131afd718f347ec8d">operations_research::KnapsackCapacityPropagator::CopyCurrentStateToSolutionPropagator</a></div><div class="ttdeci">void CopyCurrentStateToSolutionPropagator(std::vector&lt; bool &gt; *solution) const override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_a9921c39ed90a9cd32301ee0fee9491cb"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#a9921c39ed90a9cd32301ee0fee9491cb">operations_research::KnapsackCapacityPropagator::ComputeProfitBounds</a></div><div class="ttdeci">void ComputeProfitBounds() override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_aa14e63156675c18c06073ac1cb8aa170"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#aa14e63156675c18c06073ac1cb8aa170">operations_research::KnapsackCapacityPropagator::~KnapsackCapacityPropagator</a></div><div class="ttdeci">~KnapsackCapacityPropagator() override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_ae2545020be753ee6a66c277daac41784"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#ae2545020be753ee6a66c277daac41784">operations_research::KnapsackCapacityPropagator::InitPropagator</a></div><div class="ttdeci">void InitPropagator() override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_capacity_propagator_html_afccfe4a5a27c2c805016d82886795da9"><div class="ttname"><a href="classoperations__research_1_1_knapsack_capacity_propagator.html#afccfe4a5a27c2c805016d82886795da9">operations_research::KnapsackCapacityPropagator::GetNextItemId</a></div><div class="ttdeci">int GetNextItemId() const override</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00539">knapsack_solver.h:539</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html">operations_research::KnapsackGenericSolver</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00614">knapsack_solver.h:614</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a2a25594d97a0a532f9d814bdc6dea380"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a2a25594d97a0a532f9d814bdc6dea380">operations_research::KnapsackGenericSolver::~KnapsackGenericSolver</a></div><div class="ttdeci">~KnapsackGenericSolver() override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a2a7bff5cf8a51192eadec54eb0499064"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a2a7bff5cf8a51192eadec54eb0499064">operations_research::KnapsackGenericSolver::KnapsackGenericSolver</a></div><div class="ttdeci">KnapsackGenericSolver(const std::string &amp;solver_name)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a3df2fc3d96fbcac78a632d7dbf3b8550"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a3df2fc3d96fbcac78a632d7dbf3b8550">operations_research::KnapsackGenericSolver::set_master_propagator_id</a></div><div class="ttdeci">void set_master_propagator_id(int master_propagator_id)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00631">knapsack_solver.h:631</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a5c677592ee5e7312c64475ebae949eab"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a5c677592ee5e7312c64475ebae949eab">operations_research::KnapsackGenericSolver::GetNumberOfItems</a></div><div class="ttdeci">int GetNumberOfItems() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00623">knapsack_solver.h:623</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a734b6464309adbbdeb63ef759f690ff1"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a734b6464309adbbdeb63ef759f690ff1">operations_research::KnapsackGenericSolver::Init</a></div><div class="ttdeci">void Init(const std::vector&lt; int64_t &gt; &amp;profits, const std::vector&lt; std::vector&lt; int64_t &gt; &gt; &amp;weights, const std::vector&lt; int64_t &gt; &amp;capacities) override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_a788a597dac89a082d3ed4994d654dec1"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#a788a597dac89a082d3ed4994d654dec1">operations_research::KnapsackGenericSolver::Solve</a></div><div class="ttdeci">int64_t Solve(TimeLimit *time_limit, bool *is_solution_optimal) override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_abfd4cb3faa2f1d6840b8123765fa2fc4"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#abfd4cb3faa2f1d6840b8123765fa2fc4">operations_research::KnapsackGenericSolver::best_solution</a></div><div class="ttdeci">bool best_solution(int item_id) const override</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00638">knapsack_solver.h:638</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_generic_solver_html_ac9849a7043959c65033fa6f4a63bb10e"><div class="ttname"><a href="classoperations__research_1_1_knapsack_generic_solver.html#ac9849a7043959c65033fa6f4a63bb10e">operations_research::KnapsackGenericSolver::GetLowerAndUpperBoundWhenItem</a></div><div class="ttdeci">void GetLowerAndUpperBoundWhenItem(int item_id, bool is_item_in, int64_t *lower_bound, int64_t *upper_bound) override</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html">operations_research::KnapsackPropagator</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00448">knapsack_solver.h:448</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a04d8883567a6e02787f2362e6543a21b"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a04d8883567a6e02787f2362e6543a21b">operations_research::KnapsackPropagator::Init</a></div><div class="ttdeci">void Init(const std::vector&lt; int64_t &gt; &amp;profits, const std::vector&lt; int64_t &gt; &amp;weights)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a08beea2d857241d99287935a91be5217"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a08beea2d857241d99287935a91be5217">operations_research::KnapsackPropagator::current_profit</a></div><div class="ttdeci">int64_t current_profit() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00467">knapsack_solver.h:467</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a1fa45af1bf0d6aa9d5f86e2ed9ae5323"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a1fa45af1bf0d6aa9d5f86e2ed9ae5323">operations_research::KnapsackPropagator::CopyCurrentStateToSolution</a></div><div class="ttdeci">void CopyCurrentStateToSolution(bool has_one_propagator, std::vector&lt; bool &gt; *solution) const</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a5a0d11be6f0d5b521477226fb7573db8"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a5a0d11be6f0d5b521477226fb7573db8">operations_research::KnapsackPropagator::UpdatePropagator</a></div><div class="ttdeci">virtual bool UpdatePropagator(bool revert, const KnapsackAssignment &amp;assignment)=0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a701e8fc6dbf7ffeb4c48512ffa6d7501"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a701e8fc6dbf7ffeb4c48512ffa6d7501">operations_research::KnapsackPropagator::items</a></div><div class="ttdeci">const std::vector&lt; KnapsackItemPtr &gt; &amp; items() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00499">knapsack_solver.h:499</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a883cd053b1e7322727eb9e19940f69f6"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a883cd053b1e7322727eb9e19940f69f6">operations_research::KnapsackPropagator::InitPropagator</a></div><div class="ttdeci">virtual void InitPropagator()=0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a8ae457a5297bac5ad83517ba54b819d1"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a8ae457a5297bac5ad83517ba54b819d1">operations_research::KnapsackPropagator::ComputeProfitBounds</a></div><div class="ttdeci">virtual void ComputeProfitBounds()=0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_a9aea5e61ac71dca1139fda445cc2dfee"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#a9aea5e61ac71dca1139fda445cc2dfee">operations_research::KnapsackPropagator::GetNextItemId</a></div><div class="ttdeci">virtual int GetNextItemId() const =0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_aa68069fd1180cb37fcdbc99d6230bc3e"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#aa68069fd1180cb37fcdbc99d6230bc3e">operations_research::KnapsackPropagator::profit_upper_bound</a></div><div class="ttdeci">int64_t profit_upper_bound() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00469">knapsack_solver.h:469</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_ab803770e8e21bb448a2f3d940ab125f8"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#ab803770e8e21bb448a2f3d940ab125f8">operations_research::KnapsackPropagator::CopyCurrentStateToSolutionPropagator</a></div><div class="ttdeci">virtual void CopyCurrentStateToSolutionPropagator(std::vector&lt; bool &gt; *solution) const =0</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_accafea74a5951ec85cd803541f3ab3fe"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#accafea74a5951ec85cd803541f3ab3fe">operations_research::KnapsackPropagator::~KnapsackPropagator</a></div><div class="ttdeci">virtual ~KnapsackPropagator()</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_ae04e419341e0b9772a057aff10ce63a0"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#ae04e419341e0b9772a057aff10ce63a0">operations_research::KnapsackPropagator::profit_lower_bound</a></div><div class="ttdeci">int64_t profit_lower_bound() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00468">knapsack_solver.h:468</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_ae29226a5be6204e26f1d563a6630ab9e"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#ae29226a5be6204e26f1d563a6630ab9e">operations_research::KnapsackPropagator::set_profit_lower_bound</a></div><div class="ttdeci">void set_profit_lower_bound(int64_t profit)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00501">knapsack_solver.h:501</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_af28391017c090a638200c57b4c8a2ac1"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#af28391017c090a638200c57b4c8a2ac1">operations_research::KnapsackPropagator::KnapsackPropagator</a></div><div class="ttdeci">KnapsackPropagator(const KnapsackState &amp;state)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_af4b38123d3654471f0868774c5ff877d"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#af4b38123d3654471f0868774c5ff877d">operations_research::KnapsackPropagator::Update</a></div><div class="ttdeci">bool Update(bool revert, const KnapsackAssignment &amp;assignment)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_af991b29f273c53c8b35cb09bcccf3a5d"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#af991b29f273c53c8b35cb09bcccf3a5d">operations_research::KnapsackPropagator::set_profit_upper_bound</a></div><div class="ttdeci">void set_profit_upper_bound(int64_t profit)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00502">knapsack_solver.h:502</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_propagator_html_afebda22d5e2e068671aa4dbfbe9024df"><div class="ttname"><a href="classoperations__research_1_1_knapsack_propagator.html#afebda22d5e2e068671aa4dbfbe9024df">operations_research::KnapsackPropagator::state</a></div><div class="ttdeci">const KnapsackState &amp; state() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00498">knapsack_solver.h:498</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html">operations_research::KnapsackSearchNode</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00339">knapsack_solver.h:339</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a08beea2d857241d99287935a91be5217"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a08beea2d857241d99287935a91be5217">operations_research::KnapsackSearchNode::current_profit</a></div><div class="ttdeci">int64_t current_profit() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00347">knapsack_solver.h:347</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a48521e7b1a381bd3f3f452fa6e697bde"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a48521e7b1a381bd3f3f452fa6e697bde">operations_research::KnapsackSearchNode::set_current_profit</a></div><div class="ttdeci">void set_current_profit(int64_t profit)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00348">knapsack_solver.h:348</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a6fdd73f8011695b97659f2bea29325cb"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a6fdd73f8011695b97659f2bea29325cb">operations_research::KnapsackSearchNode::depth</a></div><div class="ttdeci">int depth() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00343">knapsack_solver.h:343</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a94dca4e57f87ba2a9e3b995c267c0821"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a94dca4e57f87ba2a9e3b995c267c0821">operations_research::KnapsackSearchNode::next_item_id</a></div><div class="ttdeci">int next_item_id() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00353">knapsack_solver.h:353</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a94edd193a3f600c604a314803f723d93"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a94edd193a3f600c604a314803f723d93">operations_research::KnapsackSearchNode::parent</a></div><div class="ttdeci">const KnapsackSearchNode *const parent() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00344">knapsack_solver.h:344</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_a9962698a737cd21789c77ff32bef0d98"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#a9962698a737cd21789c77ff32bef0d98">operations_research::KnapsackSearchNode::set_next_item_id</a></div><div class="ttdeci">void set_next_item_id(int id)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00354">knapsack_solver.h:354</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_aa68069fd1180cb37fcdbc99d6230bc3e"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#aa68069fd1180cb37fcdbc99d6230bc3e">operations_research::KnapsackSearchNode::profit_upper_bound</a></div><div class="ttdeci">int64_t profit_upper_bound() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00350">knapsack_solver.h:350</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_ad17e46a2afcf393a4ec9159162c969f2"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#ad17e46a2afcf393a4ec9159162c969f2">operations_research::KnapsackSearchNode::KnapsackSearchNode</a></div><div class="ttdeci">KnapsackSearchNode(const KnapsackSearchNode *const parent, const KnapsackAssignment &amp;assignment)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_af94db7bbd58faf999d63953ef12784fe"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#af94db7bbd58faf999d63953ef12784fe">operations_research::KnapsackSearchNode::assignment</a></div><div class="ttdeci">const KnapsackAssignment &amp; assignment() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00345">knapsack_solver.h:345</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_node_html_af991b29f273c53c8b35cb09bcccf3a5d"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_node.html#af991b29f273c53c8b35cb09bcccf3a5d">operations_research::KnapsackSearchNode::set_profit_upper_bound</a></div><div class="ttdeci">void set_profit_upper_bound(int64_t profit)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00351">knapsack_solver.h:351</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html">operations_research::KnapsackSearchPath</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00393">knapsack_solver.h:393</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_a09f219a2226f7c0de0f50b6f00c099e3"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#a09f219a2226f7c0de0f50b6f00c099e3">operations_research::KnapsackSearchPath::MoveUpToDepth</a></div><div class="ttdeci">const KnapsackSearchNode * MoveUpToDepth(const KnapsackSearchNode &amp;node, int depth) const</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_a1e3b6d38df0786ccf7f938d60e386aae"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#a1e3b6d38df0786ccf7f938d60e386aae">operations_research::KnapsackSearchPath::Init</a></div><div class="ttdeci">void Init()</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_a3dc3602e1a640bc986956e0ce5e88d04"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#a3dc3602e1a640bc986956e0ce5e88d04">operations_research::KnapsackSearchPath::KnapsackSearchPath</a></div><div class="ttdeci">KnapsackSearchPath(const KnapsackSearchNode &amp;from, const KnapsackSearchNode &amp;to)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_a97db8ba091791787900dd812fefc10e5"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#a97db8ba091791787900dd812fefc10e5">operations_research::KnapsackSearchPath::from</a></div><div class="ttdeci">const KnapsackSearchNode &amp; from() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00398">knapsack_solver.h:398</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_ab54cc176a72a1a03b18cb3f9649c773a"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#ab54cc176a72a1a03b18cb3f9649c773a">operations_research::KnapsackSearchPath::via</a></div><div class="ttdeci">const KnapsackSearchNode &amp; via() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00399">knapsack_solver.h:399</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_search_path_html_ad0e1cf5e8520cb7a59cad8d6aecdf8a6"><div class="ttname"><a href="classoperations__research_1_1_knapsack_search_path.html#ad0e1cf5e8520cb7a59cad8d6aecdf8a6">operations_research::KnapsackSearchPath::to</a></div><div class="ttdeci">const KnapsackSearchNode &amp; to() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00400">knapsack_solver.h:400</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html">operations_research::KnapsackSolver</a></div><div class="ttdoc">This library solves knapsack problems.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00117">knapsack_solver.h:117</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a09627cf25401a9880d2e94551ecbf993"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a09627cf25401a9880d2e94551ecbf993">operations_research::KnapsackSolver::KnapsackSolver</a></div><div class="ttdeci">KnapsackSolver(SolverType solver_type, const std::string &amp;solver_name)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a57d88f584d14b161580550918c8fbf3b"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a57d88f584d14b161580550918c8fbf3b">operations_research::KnapsackSolver::BestSolutionContains</a></div><div class="ttdeci">bool BestSolutionContains(int item_id) const</div><div class="ttdoc">Returns true if the item 'item_id' is packed in the optimal knapsack.</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a6b46c35c8977efde66ae7ad97423bdf2"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a6b46c35c8977efde66ae7ad97423bdf2">operations_research::KnapsackSolver::KnapsackSolver</a></div><div class="ttdeci">KnapsackSolver(const std::string &amp;solver_name)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a6b4f6cbb00a64b0e9745938f9b99d0c8"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a6b4f6cbb00a64b0e9745938f9b99d0c8">operations_research::KnapsackSolver::set_time_limit</a></div><div class="ttdeci">void set_time_limit(double time_limit_seconds)</div><div class="ttdoc">Time limit in seconds.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00235">knapsack_solver.h:235</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a7f5467b49f2cba3d8804e44ed76e12a2"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a7f5467b49f2cba3d8804e44ed76e12a2">operations_research::KnapsackSolver::Solve</a></div><div class="ttdeci">int64_t Solve()</div><div class="ttdoc">Solves the problem and returns the profit of the optimal solution.</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306ec"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ec">operations_research::KnapsackSolver::SolverType</a></div><div class="ttdeci">SolverType</div><div class="ttdoc">Enum controlling which underlying algorithm is used.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00124">knapsack_solver.h:124</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306eca1f4e1e2f80ab9c7d4fc1b14d9f5da959"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca1f4e1e2f80ab9c7d4fc1b14d9f5da959">operations_research::KnapsackSolver::KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER</div><div class="ttdoc">SCIP based solver.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00171">knapsack_solver.h:171</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306eca2a4e77eec4f386d17001e7285e812a0b"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca2a4e77eec4f386d17001e7285e812a0b">operations_research::KnapsackSolver::KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER</div><div class="ttdoc">Generic Solver.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00163">knapsack_solver.h:163</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306eca793d998526508cfcc2bfc89fe25b3edd"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca793d998526508cfcc2bfc89fe25b3edd">operations_research::KnapsackSolver::KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER</div><div class="ttdoc">Dynamic Programming approach for single dimension problems.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00147">knapsack_solver.h:147</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306eca9d4c4118c9e4dc258e5052c0a457098d"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306eca9d4c4118c9e4dc258e5052c0a457098d">operations_research::KnapsackSolver::KNAPSACK_DIVIDE_AND_CONQUER_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_DIVIDE_AND_CONQUER_SOLVER</div><div class="ttdoc">Divide and Conquer approach for single dimension problems.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00198">knapsack_solver.h:198</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306ecaa020f211a1ff184e712aa4f372d6ea34"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecaa020f211a1ff184e712aa4f372d6ea34">operations_research::KnapsackSolver::KNAPSACK_64ITEMS_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_64ITEMS_SOLVER</div><div class="ttdoc">Optimized method for single dimension small problems.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00139">knapsack_solver.h:139</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306ecac43056d6d2f96cee37fcb8a752b0ff45"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecac43056d6d2f96cee37fcb8a752b0ff45">operations_research::KnapsackSolver::KNAPSACK_BRUTE_FORCE_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_BRUTE_FORCE_SOLVER</div><div class="ttdoc">Brute force method.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00131">knapsack_solver.h:131</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a8b06041d7c1fb05f379714f4312306ecae2ce6e36a247621de398e875d5feb575"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a8b06041d7c1fb05f379714f4312306ecae2ce6e36a247621de398e875d5feb575">operations_research::KnapsackSolver::KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER</a></div><div class="ttdeci">@ KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER</div><div class="ttdoc">CBC Based Solver.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00155">knapsack_solver.h:155</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a9647a5f765048e8662e5efa54c7d8687"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a9647a5f765048e8662e5efa54c7d8687">operations_research::KnapsackSolver::IsSolutionOptimal</a></div><div class="ttdeci">bool IsSolutionOptimal() const</div><div class="ttdoc">Returns true if the solution was proven optimal.</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00224">knapsack_solver.h:224</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_a9a98946a64f3893b085f650932c9dfee"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#a9a98946a64f3893b085f650932c9dfee">operations_research::KnapsackSolver::GetName</a></div><div class="ttdeci">std::string GetName() const</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_aa5b8e0a03c593bfc3cef0ba8d178844f"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#aa5b8e0a03c593bfc3cef0ba8d178844f">operations_research::KnapsackSolver::set_use_reduction</a></div><div class="ttdeci">void set_use_reduction(bool use_reduction)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00228">knapsack_solver.h:228</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_ac7d0a3efa2aabe6a3e667b0724f63688"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#ac7d0a3efa2aabe6a3e667b0724f63688">operations_research::KnapsackSolver::use_reduction</a></div><div class="ttdeci">bool use_reduction() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00227">knapsack_solver.h:227</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_adecc1cf1fe064b843459dd1f8aec12ff"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#adecc1cf1fe064b843459dd1f8aec12ff">operations_research::KnapsackSolver::~KnapsackSolver</a></div><div class="ttdeci">virtual ~KnapsackSolver()</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_solver_html_ae5982edf1a2974495d20201775a765e2"><div class="ttname"><a href="classoperations__research_1_1_knapsack_solver.html#ae5982edf1a2974495d20201775a765e2">operations_research::KnapsackSolver::Init</a></div><div class="ttdeci">void Init(const std::vector&lt; int64_t &gt; &amp;profits, const std::vector&lt; std::vector&lt; int64_t &gt; &gt; &amp;weights, const std::vector&lt; int64_t &gt; &amp;capacities)</div><div class="ttdoc">Initializes the solver and enters the problem to be solved.</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html">operations_research::KnapsackState</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00414">knapsack_solver.h:414</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_a41f9430cc0090383e7797a88c1dbacbc"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#a41f9430cc0090383e7797a88c1dbacbc">operations_research::KnapsackState::KnapsackState</a></div><div class="ttdeci">KnapsackState()</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_a5c677592ee5e7312c64475ebae949eab"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#a5c677592ee5e7312c64475ebae949eab">operations_research::KnapsackState::GetNumberOfItems</a></div><div class="ttdeci">int GetNumberOfItems() const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00425">knapsack_solver.h:425</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_a6308c7a97200f84f6ebf5b2c487b0362"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#a6308c7a97200f84f6ebf5b2c487b0362">operations_research::KnapsackState::Init</a></div><div class="ttdeci">void Init(int number_of_items)</div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_a862bf4e908cd82ea44f72e98558016ad"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#a862bf4e908cd82ea44f72e98558016ad">operations_research::KnapsackState::is_in</a></div><div class="ttdeci">bool is_in(int id) const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00427">knapsack_solver.h:427</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_a89aa280d2321c1316aa1305106f1bb49"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#a89aa280d2321c1316aa1305106f1bb49">operations_research::KnapsackState::is_bound</a></div><div class="ttdeci">bool is_bound(int id) const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00426">knapsack_solver.h:426</a></div></div>
<div class="ttc" id="aclassoperations__research_1_1_knapsack_state_html_ab771ac0e538f991b73b011ee3ba11f05"><div class="ttname"><a href="classoperations__research_1_1_knapsack_state.html#ab771ac0e538f991b73b011ee3ba11f05">operations_research::KnapsackState::UpdateState</a></div><div class="ttdeci">bool UpdateState(bool revert, const KnapsackAssignment &amp;assignment)</div></div>
<div class="ttc" id="anamespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdef"><b>Definition:</b> <a href="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>
<div class="ttc" id="anamespaceoperations__research_html_ada7d9b46f657c6053a197273a85043a7"><div class="ttname"><a href="namespaceoperations__research.html#ada7d9b46f657c6053a197273a85043a7">operations_research::KnapsackItemPtr</a></div><div class="ttdeci">KnapsackItem * KnapsackItemPtr</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00329">knapsack_solver.h:329</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_assignment_html"><div class="ttname"><a href="structoperations__research_1_1_knapsack_assignment.html">operations_research::KnapsackAssignment</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00295">knapsack_solver.h:295</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_assignment_html_a1c0c3c835f3c4363b650fba65c7ebf32"><div class="ttname"><a href="structoperations__research_1_1_knapsack_assignment.html#a1c0c3c835f3c4363b650fba65c7ebf32">operations_research::KnapsackAssignment::item_id</a></div><div class="ttdeci">int item_id</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00298">knapsack_solver.h:298</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_assignment_html_a8f85eb172a4c6bed0d042f7d269fc457"><div class="ttname"><a href="structoperations__research_1_1_knapsack_assignment.html#a8f85eb172a4c6bed0d042f7d269fc457">operations_research::KnapsackAssignment::KnapsackAssignment</a></div><div class="ttdeci">KnapsackAssignment(int _item_id, bool _is_in)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00296">knapsack_solver.h:296</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_assignment_html_a922620900c7a18d22de686d47e25d4ed"><div class="ttname"><a href="structoperations__research_1_1_knapsack_assignment.html#a922620900c7a18d22de686d47e25d4ed">operations_research::KnapsackAssignment::is_in</a></div><div class="ttdeci">bool is_in</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00299">knapsack_solver.h:299</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html">operations_research::KnapsackItem</a></div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00314">knapsack_solver.h:314</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html_a523234416a08d890505d4b34fb0513ee"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html#a523234416a08d890505d4b34fb0513ee">operations_research::KnapsackItem::weight</a></div><div class="ttdeci">const int64_t weight</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00326">knapsack_solver.h:326</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html_a64ae40793ade89d800a8c5646d2980fc"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html#a64ae40793ade89d800a8c5646d2980fc">operations_research::KnapsackItem::id</a></div><div class="ttdeci">const int id</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00325">knapsack_solver.h:325</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html_a75dd99d0e31e3a347e5ebad01561e31d"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html#a75dd99d0e31e3a347e5ebad01561e31d">operations_research::KnapsackItem::profit</a></div><div class="ttdeci">const int64_t profit</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00327">knapsack_solver.h:327</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html_a7eb6bbc72ec605de6f50d0c90f609a85"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html#a7eb6bbc72ec605de6f50d0c90f609a85">operations_research::KnapsackItem::GetEfficiency</a></div><div class="ttdeci">double GetEfficiency(int64_t profit_max) const</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00317">knapsack_solver.h:317</a></div></div>
<div class="ttc" id="astructoperations__research_1_1_knapsack_item_html_aefc8a61c2edd00c4daf37056b754e6a0"><div class="ttname"><a href="structoperations__research_1_1_knapsack_item.html#aefc8a61c2edd00c4daf37056b754e6a0">operations_research::KnapsackItem::KnapsackItem</a></div><div class="ttdeci">KnapsackItem(int _id, int64_t _weight, int64_t _profit)</div><div class="ttdef"><b>Definition:</b> <a href="knapsack__solver_8h_source.html#l00315">knapsack_solver.h:315</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
</div>
</div>
<div id="footer-container">
<div id="footer">
</div>
</div>
</body>
</html>