637 lines
108 KiB
HTML
637 lines
108 KiB
HTML
<!-- HTML header for doxygen 1.8.18-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.9.1"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>OR-Tools: one_tree_lower_bound.h Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtreedata.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.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="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectlogo"><img alt="Logo" src="orLogo.png"/></td>
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">OR-Tools
|
|
 <span id="projectnumber">8.2</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.1 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "search",false,'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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('one__tree__lower__bound_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">one_tree_lower_bound.h</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="one__tree__lower__bound_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright 2010-2018 Google LLC</span></div>
|
|
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div>
|
|
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div>
|
|
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// You may obtain a copy of the License at</span></div>
|
|
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div>
|
|
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div>
|
|
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div>
|
|
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
|
|
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// See the License for the specific language governing permissions and</span></div>
|
|
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// limitations under the License.</span></div>
|
|
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span>  </div>
|
|
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">// An implementation of the Held-Karp symmetric Traveling Salesman (TSP) lower</span></div>
|
|
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">// bound algorithm, inspired by "Estimating the Held-Karp lower bound for the</span></div>
|
|
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">// geometric TSP" by Christine L. Valenzuela and Antonia J. Jones, European</span></div>
|
|
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">// Journal of Operational Research, Volume 102, Issue 1, 1 October 1997,</span></div>
|
|
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">// Pages 157-175.</span></div>
|
|
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment">// The idea is to compute minimum 1-trees to evaluate a lower bound to the</span></div>
|
|
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">// corresponding TSP. A minimum 1-tree is a minimum spanning tree on all nodes</span></div>
|
|
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">// but one, to which are added the two shortest edges from the left-out node to</span></div>
|
|
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment">// the nodes of the spanning tree. The sum of the cost of the edges of the</span></div>
|
|
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">// minimum 1-tree is a lower bound to the cost of the TSP.</span></div>
|
|
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment">// In order to improve (increase) this lower bound, the idea is to add weights</span></div>
|
|
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment">// to each nodes, weights which are added to the cost function used when</span></div>
|
|
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">// computing the 1-tree. If weight[i] is the weight of node i, the cost function</span></div>
|
|
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">// therefore becomes weighed_cost(i,j) = cost(i,j) + weight[i] + weight[j]. One</span></div>
|
|
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment">// can see that w = weighed_cost(minimum 1-tree) - Sum(2 * weight[i])</span></div>
|
|
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">// = cost(minimum 1-tree) + Sum(weight[i] * (degree[i] - 2))</span></div>
|
|
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">// is a valid lower bound to the TSP:</span></div>
|
|
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">// 1) let T be the set of 1-trees on the nodes;</span></div>
|
|
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment">// 2) let U be the set of tours on the nodes; U is a subset of T (tours are</span></div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">// 1-trees with all degrees equal to 2), therefore:</span></div>
|
|
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment">// min(t in T) Cost(t) <= min(t in U) Cost(t)</span></div>
|
|
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="comment">// min(t in T) WeighedCost(t) <= min(t in U) WeighedCost(t)</span></div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment">// 3) weighed_cost(i,j) = cost(i,j) + weight[i] + weight[j], therefore:</span></div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment">// for all t in T, WeighedCost(t) = Cost(t) + Sum(weight[i] * degree[i])</span></div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="comment">// for all i in U, WeighedCost(t) = Cost(t) + Sum(weight[i] * 2)</span></div>
|
|
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">// 4) let t* in U s.t. WeighedCost(t*) = min(t in U) WeighedCost(t), therefore:</span></div>
|
|
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span> <span class="comment">// min(t in T) (Cost(t) + Sum(weight[i] * degree[i]))</span></div>
|
|
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="comment">// <= Cost(t*) + Sum(weight[i] * 2)</span></div>
|
|
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">// min(t in T) (Cost(t) + Sum(weight[i] * (degree[i] - 2))) <= Cost(t*)</span></div>
|
|
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="comment">// cost(minimum 1-tree) + Sum(weight[i] * (degree[i] - 2)) <= Cost(t*)</span></div>
|
|
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="comment">// w <= Cost(t*)</span></div>
|
|
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="comment">// 5) because t* is also the tour minimizing Cost(t) with t in U (weights do not</span></div>
|
|
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span> <span class="comment">// affect the optimality of a tour), Cost(t*) is the cost of the optimal</span></div>
|
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="comment">// solution to the TSP and w is a lower bound to this cost.</span></div>
|
|
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="comment">// The best lower bound is the one for which weights maximize w. Intuitively as</span></div>
|
|
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span> <span class="comment">// degrees get closer to 2 the minimum 1-trees gets closer to a tour.</span></div>
|
|
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment">// At each iteration m, weights are therefore updated as follows:</span></div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="comment">// weight(m+1)[i] = weight(m)[i] + step(m) * (degree(m)[i] - 2)</span></div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="comment">// where degree(m)[i] is the degree of node i in the 1-tree at iteration i,</span></div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="comment">// step(m) is a subgradient optimization step.</span></div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="comment">// This implementation uses two variants of Held-Karp's initial subgradient</span></div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="comment">// optimization iterative estimation approach described in "The</span></div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="comment">// traveling-salesman problem and minimum spanning trees: Part I and II", by</span></div>
|
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span> <span class="comment">// Michael Held and Richard M. Karp, Operations Research Vol. 18,</span></div>
|
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span> <span class="comment">// No. 6 (Nov. - Dec., 1970), pp. 1138-1162 and Mathematical Programming (1971).</span></div>
|
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span> <span class="comment">// The first variant comes from Volgenant, T., and Jonker, R. (1982), "A branch</span></div>
|
|
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span> <span class="comment">// and bound algorithm for the symmetric traveling salesman problem based on the</span></div>
|
|
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span> <span class="comment">// 1-tree relaxation", European Journal of Operational Research. 9:83-89.".</span></div>
|
|
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span> <span class="comment">// It suggests using</span></div>
|
|
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span> <span class="comment">// step(m) = (1.0 * (m - 1) * (2 * M - 5) / (2 * (M - 1))) * step1</span></div>
|
|
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span> <span class="comment">// - (m - 2) * step1</span></div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span> <span class="comment">// + (0.5 * (m - 1) * (m - 2) / ((M - 1) * (M - 2))) * step1</span></div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span> <span class="comment">// where M is the maximum number of iterations and step1 is initially set to</span></div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span> <span class="comment">// L / (2 * number of nodes), where L is the un-weighed cost of the 1-tree;</span></div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span> <span class="comment">// step1 is updated each time a better w is found. The intuition is to have a</span></div>
|
|
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span> <span class="comment">// positive decreasing step which is equal to 0 after M iterations; Volgenant</span></div>
|
|
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span> <span class="comment">// and Jonker suggest that:</span></div>
|
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span> <span class="comment">// step(m) - 2 * step(m-1) + t(m-2) = constant,</span></div>
|
|
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span> <span class="comment">// step(M) = 0</span></div>
|
|
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span> <span class="comment">// and</span></div>
|
|
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span> <span class="comment">// step(1) - step(2) = 3 * (step(M-1) - step(M)).</span></div>
|
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span> <span class="comment">// The step(m) formula above derives from this recursive formulation.</span></div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="comment">// This is the default algorithm used in this implementation.</span></div>
|
|
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span> <span class="comment">// The second variant comes from Held, M., Wolfe, P., and Crowder, H. P. (1974),</span></div>
|
|
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span> <span class="comment">// "Validation of subgradient optimization", Mathematical Programming 6:62-88.</span></div>
|
|
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span> <span class="comment">// It derives from the original Held-Karp formulation:</span></div>
|
|
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span> <span class="comment">// step(m) = lambda(m) * (wlb - w(m)) / Sum((degree[i] - 2)^2),</span></div>
|
|
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span> <span class="comment">// where wlb is a lower bound to max(w(m)) and lambda(m) in [0, 2].</span></div>
|
|
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span> <span class="comment">// Help-Karp prove that</span></div>
|
|
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span> <span class="comment">// if w(m') > w(m) and 0 < step < 2 * (w(m') - w(m))/norm(degree(m) - 2)^2,</span></div>
|
|
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span> <span class="comment">// then weight(m+1) is closer to w' than w from which they derive the above</span></div>
|
|
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span> <span class="comment">// formula.</span></div>
|
|
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span> <span class="comment">// Held-Wolfe-Crowder show that using an overestimate UB is as effective as</span></div>
|
|
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <span class="comment">// using the underestimate wlb while UB is easier to compute. The resulting</span></div>
|
|
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span> <span class="comment">// formula is:</span></div>
|
|
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span> <span class="comment">// step(m) = lambda(m) * (UB - w(m)) / Sum((degree[i] - 2)^2),</span></div>
|
|
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span> <span class="comment">// where UB is an upper bound to the TSP (here computed with the Christofides</span></div>
|
|
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span> <span class="comment">// algorithm), and lambda(m) in [0, 2] initially set to 2. Held-Wolfe-Crowder</span></div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span> <span class="comment">// suggest running the algorithm for M = 2 * number of nodes iterations, then</span></div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span> <span class="comment">// dividing lambda and M by 2 until M is small enough (less than 2 in this</span></div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span> <span class="comment">// implementation).</span></div>
|
|
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="comment">// To speed up the computation, minimum spanning trees are actually computed on</span></div>
|
|
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span> <span class="comment">// a graph limited to the nearest neighbors of each node. Valenzuela-Jones 1997</span></div>
|
|
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span> <span class="comment">// experiments have shown that this does not harm the lower bound computation</span></div>
|
|
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span> <span class="comment">// significantly. At the end of the algorithm a last iteration is run on the</span></div>
|
|
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span> <span class="comment">// complete graph to ensure the bound is correct (the cost of a minimum 1-tree</span></div>
|
|
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span> <span class="comment">// on a partial graph is an upper bound to the one on a complete graph).</span></div>
|
|
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span> <span class="comment">//</span></div>
|
|
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span> <span class="comment">// Usage:</span></div>
|
|
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span> <span class="comment">// std::function<int64(int,int)> cost_function =...;</span></div>
|
|
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span> <span class="comment">// const double lower_bound =</span></div>
|
|
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span> <span class="comment">// ComputeOneTreeLowerBound(number_of_nodes, cost_function);</span></div>
|
|
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span> <span class="comment">// where number_of_nodes is the number of nodes in the TSP and cost_function</span></div>
|
|
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span> <span class="comment">// is a function returning the cost between two nodes.</span></div>
|
|
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  </div>
|
|
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span> <span class="preprocessor">#ifndef OR_TOOLS_GRAPH_ONE_TREE_LOWER_BOUND_H_</span></div>
|
|
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span> <span class="preprocessor">#define OR_TOOLS_GRAPH_ONE_TREE_LOWER_BOUND_H_</span></div>
|
|
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  </div>
|
|
<div class="line"><a name="l00124"></a><span class="lineno"> 124</span> <span class="preprocessor">#include <math.h></span></div>
|
|
<div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  </div>
|
|
<div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="preprocessor">#include <limits></span></div>
|
|
<div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="preprocessor">#include <set></span></div>
|
|
<div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  </div>
|
|
<div class="line"><a name="l00129"></a><span class="lineno"> 129</span> <span class="preprocessor">#include "<a class="code" href="integral__types_8h.html">ortools/base/integral_types.h</a>"</span></div>
|
|
<div class="line"><a name="l00130"></a><span class="lineno"> 130</span> <span class="preprocessor">#include "<a class="code" href="christofides_8h.html">ortools/graph/christofides.h</a>"</span></div>
|
|
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span> <span class="preprocessor">#include "<a class="code" href="minimum__spanning__tree_8h.html">ortools/graph/minimum_spanning_tree.h</a>"</span></div>
|
|
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  </div>
|
|
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span> <span class="keyword">namespace </span><a class="code" href="namespaceoperations__research.html">operations_research</a> {</div>
|
|
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  </div>
|
|
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span> <span class="comment">// Implementation of algorithms computing Held-Karp bounds. They have to provide</span></div>
|
|
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span> <span class="comment">// the following methods:</span></div>
|
|
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span> <span class="comment">// - bool Next(): returns false when the algorithm must stop;</span></div>
|
|
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span> <span class="comment">// - double GetStep(): returns the current step computed by the algorithm;</span></div>
|
|
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span> <span class="comment">// - void OnOneTree(CostType one_tree_cost,</span></div>
|
|
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">// double w,</span></div>
|
|
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span> <span class="comment">// const std::vector<int>& degrees):</span></div>
|
|
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="comment">// called each time a new minimum 1-tree is computed;</span></div>
|
|
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span> <span class="comment">// - one_tree_cost: the un-weighed cost of the 1-tree,</span></div>
|
|
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span> <span class="comment">// - w the current value of w,</span></div>
|
|
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span> <span class="comment">// - degrees: the degree of nodes in the 1-tree.</span></div>
|
|
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span> <span class="comment">// - OnNewWMax(CostType one_tree_cost): called when a better value of w is</span></div>
|
|
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span> <span class="comment">// found, one_tree_cost being the un-weighed cost of the corresponding</span></div>
|
|
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span> <span class="comment">// minimum 1-tree.</span></div>
|
|
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  </div>
|
|
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span> <span class="comment">// Implementation of the Volgenant Jonker algorithm (see the comments at the</span></div>
|
|
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span> <span class="comment">// head of the file for explanations).</span></div>
|
|
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostType></div>
|
|
<div class="line"><a name="l00153"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html"> 153</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html">VolgenantJonkerEvaluator</a> {</div>
|
|
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <span class="keyword">public</span>:</div>
|
|
<div class="line"><a name="l00155"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a24cfa064cc97e776b361abdba5488673"> 155</a></span>  <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a24cfa064cc97e776b361abdba5488673">VolgenantJonkerEvaluator</a>(<span class="keywordtype">int</span> number_of_nodes, <span class="keywordtype">int</span> max_iterations)</div>
|
|
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  : step1_initialized_(false),</div>
|
|
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  step1_(0),</div>
|
|
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  iteration_(0),</div>
|
|
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  max_iterations_(max_iterations > 0 ? max_iterations</div>
|
|
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  : MaxIterations(number_of_nodes)),</div>
|
|
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  number_of_nodes_(number_of_nodes) {}</div>
|
|
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  </div>
|
|
<div class="line"><a name="l00163"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a3947d19ac087ef2cd68c2409920339c4"> 163</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a3947d19ac087ef2cd68c2409920339c4">Next</a>() { <span class="keywordflow">return</span> iteration_++ < max_iterations_; }</div>
|
|
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  </div>
|
|
<div class="line"><a name="l00165"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a61aed6a943277e531b904cfdc3616890"> 165</a></span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a61aed6a943277e531b904cfdc3616890">GetStep</a>()<span class="keyword"> const </span>{</div>
|
|
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  <span class="keywordflow">return</span> (1.0 * (iteration_ - 1) * (2 * max_iterations_ - 5) /</div>
|
|
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  (2 * (max_iterations_ - 1))) *</div>
|
|
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  step1_ -</div>
|
|
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  (iteration_ - 2) * step1_ +</div>
|
|
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  (0.5 * (iteration_ - 1) * (iteration_ - 2) /</div>
|
|
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  ((max_iterations_ - 1) * (max_iterations_ - 2))) *</div>
|
|
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  step1_;</div>
|
|
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  }</div>
|
|
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  </div>
|
|
<div class="line"><a name="l00175"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4"> 175</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4">OnOneTree</a>(CostType one_tree_cost, <span class="keywordtype">double</span> w,</div>
|
|
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  <span class="keyword">const</span> std::vector<int>& degrees) {</div>
|
|
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  <span class="keywordflow">if</span> (!step1_initialized_) {</div>
|
|
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  step1_initialized_ = <span class="keyword">true</span>;</div>
|
|
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  UpdateStep(one_tree_cost);</div>
|
|
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  }</div>
|
|
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  }</div>
|
|
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  </div>
|
|
<div class="line"><a name="l00183"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3"> 183</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3">OnNewWMax</a>(CostType one_tree_cost) { UpdateStep(one_tree_cost); }</div>
|
|
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  </div>
|
|
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  <span class="keyword">private</span>:</div>
|
|
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <span class="comment">// Automatic computation of the number of iterations based on empirical</span></div>
|
|
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="comment">// results given in Valenzuela-Jones 1997.</span></div>
|
|
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="keyword">static</span> <span class="keywordtype">int</span> MaxIterations(<span class="keywordtype">int</span> number_of_nodes) {</div>
|
|
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keywordflow">return</span> <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(28 * std::pow(number_of_nodes, 0.62));</div>
|
|
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  }</div>
|
|
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  </div>
|
|
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  <span class="keywordtype">void</span> UpdateStep(CostType one_tree_cost) {</div>
|
|
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  step1_ = one_tree_cost / (2 * number_of_nodes_);</div>
|
|
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  }</div>
|
|
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  </div>
|
|
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="keywordtype">bool</span> step1_initialized_;</div>
|
|
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="keywordtype">double</span> step1_;</div>
|
|
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordtype">int</span> iteration_;</div>
|
|
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> max_iterations_;</div>
|
|
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> number_of_nodes_;</div>
|
|
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span> };</div>
|
|
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  </div>
|
|
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span> <span class="comment">// Implementation of the Held-Wolfe-Crowder algorithm (see the comments at the</span></div>
|
|
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span> <span class="comment">// head of the file for explanations).</span></div>
|
|
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostType, <span class="keyword">typename</span> CostFunction></div>
|
|
<div class="line"><a name="l00206"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html"> 206</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html">HeldWolfeCrowderEvaluator</a> {</div>
|
|
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  <span class="keyword">public</span>:</div>
|
|
<div class="line"><a name="l00208"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#adb1dee05e699715da68918f6b19d3e6d"> 208</a></span>  <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#adb1dee05e699715da68918f6b19d3e6d">HeldWolfeCrowderEvaluator</a>(<span class="keywordtype">int</span> number_of_nodes, <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>)</div>
|
|
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  : iteration_(0),</div>
|
|
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  number_of_iterations_(2 * number_of_nodes),</div>
|
|
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  upper_bound_(0),</div>
|
|
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  lambda_(2.0),</div>
|
|
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  step_(0) {</div>
|
|
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  <span class="comment">// TODO(user): Improve upper bound with some local search; tighter upper</span></div>
|
|
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="comment">// bounds lead to faster convergence.</span></div>
|
|
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  <a class="code" href="classoperations__research_1_1_christofides_path_solver.html">ChristofidesPathSolver<CostType, int64, int, CostFunction></a> solver(</div>
|
|
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  number_of_nodes, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>);</div>
|
|
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  upper_bound_ = solver.<a class="code" href="classoperations__research_1_1_christofides_path_solver.html#ab558649a26fef3a74f0909ef5af45e90">TravelingSalesmanCost</a>();</div>
|
|
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  }</div>
|
|
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  </div>
|
|
<div class="line"><a name="l00221"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a3947d19ac087ef2cd68c2409920339c4"> 221</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a3947d19ac087ef2cd68c2409920339c4">Next</a>() {</div>
|
|
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> min_iterations = 2;</div>
|
|
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  <span class="keywordflow">if</span> (iteration_ >= number_of_iterations_) {</div>
|
|
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  number_of_iterations_ /= 2;</div>
|
|
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keywordflow">if</span> (number_of_iterations_ < min_iterations) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
|
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  iteration_ = 0;</div>
|
|
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  lambda_ /= 2;</div>
|
|
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>  } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>  ++iteration_;</div>
|
|
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>  }</div>
|
|
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
|
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  }</div>
|
|
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  </div>
|
|
<div class="line"><a name="l00234"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a61aed6a943277e531b904cfdc3616890"> 234</a></span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a61aed6a943277e531b904cfdc3616890">GetStep</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> step_; }</div>
|
|
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  </div>
|
|
<div class="line"><a name="l00236"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4"> 236</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4">OnOneTree</a>(CostType one_tree_cost, <span class="keywordtype">double</span> w,</div>
|
|
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  <span class="keyword">const</span> std::vector<int>& degrees) {</div>
|
|
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  <span class="keywordtype">double</span> norm = 0;</div>
|
|
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> degree : degrees) {</div>
|
|
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="resource_8cc.html#a73461c37822b6ebb75b54ba1a9ffb442">delta</a> = degree - 2;</div>
|
|
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  norm += <a class="code" href="resource_8cc.html#a73461c37822b6ebb75b54ba1a9ffb442">delta</a> * <a class="code" href="resource_8cc.html#a73461c37822b6ebb75b54ba1a9ffb442">delta</a>;</div>
|
|
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  }</div>
|
|
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  step_ = lambda_ * (upper_bound_ - w) / norm;</div>
|
|
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  }</div>
|
|
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  </div>
|
|
<div class="line"><a name="l00246"></a><span class="lineno"><a class="line" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3"> 246</a></span>  <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3">OnNewWMax</a>(CostType one_tree_cost) {}</div>
|
|
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  </div>
|
|
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  <span class="keyword">private</span>:</div>
|
|
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  <span class="keywordtype">int</span> iteration_;</div>
|
|
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  <span class="keywordtype">int</span> number_of_iterations_;</div>
|
|
<div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  CostType upper_bound_;</div>
|
|
<div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  <span class="keywordtype">double</span> lambda_;</div>
|
|
<div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  <span class="keywordtype">double</span> step_;</div>
|
|
<div class="line"><a name="l00254"></a><span class="lineno"> 254</span> };</div>
|
|
<div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  </div>
|
|
<div class="line"><a name="l00256"></a><span class="lineno"> 256</span> <span class="comment">// Computes the nearest neighbors of each node for the given cost function.</span></div>
|
|
<div class="line"><a name="l00257"></a><span class="lineno"> 257</span> <span class="comment">// The ith element of the returned vector contains the indices of the nearest</span></div>
|
|
<div class="line"><a name="l00258"></a><span class="lineno"> 258</span> <span class="comment">// nodes to node i. Note that these indices contain the number_of_neighbors</span></div>
|
|
<div class="line"><a name="l00259"></a><span class="lineno"> 259</span> <span class="comment">// nearest neighbors as well as all the nodes for which i is a nearest</span></div>
|
|
<div class="line"><a name="l00260"></a><span class="lineno"> 260</span> <span class="comment">// neighbor.</span></div>
|
|
<div class="line"><a name="l00261"></a><span class="lineno"> 261</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction></div>
|
|
<div class="line"><a name="l00262"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#a078701f3ce8570abe24e8157029c8abf"> 262</a></span> std::set<std::pair<int, int>> <a class="code" href="namespaceoperations__research.html#a078701f3ce8570abe24e8157029c8abf">NearestNeighbors</a>(<span class="keywordtype">int</span> number_of_nodes,</div>
|
|
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  <span class="keywordtype">int</span> number_of_neighbors,</div>
|
|
<div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>) {</div>
|
|
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  <span class="keyword">using</span> CostType = decltype(<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(0, 0));</div>
|
|
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  std::set<std::pair<int, int>> nearest;</div>
|
|
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < number_of_nodes; ++i) {</div>
|
|
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  std::vector<std::pair<CostType, int>> neighbors;</div>
|
|
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  neighbors.reserve(number_of_nodes - 1);</div>
|
|
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < number_of_nodes; ++j) {</div>
|
|
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  <span class="keywordflow">if</span> (i != j) {</div>
|
|
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  neighbors.emplace_back(<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(i, j), j);</div>
|
|
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  }</div>
|
|
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  }</div>
|
|
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  <span class="keywordtype">int</span> size = neighbors.size();</div>
|
|
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  <span class="keywordflow">if</span> (number_of_neighbors < size) {</div>
|
|
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  std::nth_element(neighbors.begin(),</div>
|
|
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  neighbors.begin() + number_of_neighbors - 1,</div>
|
|
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  neighbors.end());</div>
|
|
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  size = number_of_neighbors;</div>
|
|
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  }</div>
|
|
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < size; ++j) {</div>
|
|
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  nearest.insert({i, neighbors[j].second});</div>
|
|
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  nearest.insert({neighbors[j].second, i});</div>
|
|
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  }</div>
|
|
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  }</div>
|
|
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  <span class="keywordflow">return</span> nearest;</div>
|
|
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span> }</div>
|
|
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  </div>
|
|
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span> <span class="comment">// Let G be the complete graph on nodes in [0, number_of_nodes - 1]. Adds arcs</span></div>
|
|
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span> <span class="comment">// from the minimum spanning tree of G to the arcs set argument.</span></div>
|
|
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction></div>
|
|
<div class="line"><a name="l00293"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#adfc52ee652f25f3a2f249ffb830f2e8a"> 293</a></span> <span class="keywordtype">void</span> <a class="code" href="namespaceoperations__research.html#adfc52ee652f25f3a2f249ffb830f2e8a">AddArcsFromMinimumSpanningTree</a>(<span class="keywordtype">int</span> number_of_nodes,</div>
|
|
<div class="line"><a name="l00294"></a><span class="lineno"> 294</span>  <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00295"></a><span class="lineno"> 295</span>  std::set<std::pair<int, int>>* arcs) {</div>
|
|
<div class="line"><a name="l00296"></a><span class="lineno"> 296</span>  <a class="code" href="classutil_1_1_complete_graph.html">util::CompleteGraph<int, int></a> graph(number_of_nodes);</div>
|
|
<div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  <span class="keyword">const</span> std::vector<int> mst =</div>
|
|
<div class="line"><a name="l00298"></a><span class="lineno"> 298</span>  <a class="code" href="namespaceoperations__research.html#a33a2f4c26fd60cd0fa98257b571c974f">BuildPrimMinimumSpanningTree</a>(graph, [&<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, &graph](<span class="keywordtype">int</span> arc) {</div>
|
|
<div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <span class="keywordflow">return</span> <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(graph.<a class="code" href="classutil_1_1_complete_graph.html#a2eeae3a8497dc3942e3db3128a10d41c">Tail</a>(arc), graph.<a class="code" href="classutil_1_1_complete_graph.html#aceb0938bcb2e8e5f37986d4cf8e3a955">Head</a>(arc));</div>
|
|
<div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  });</div>
|
|
<div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> arc : mst) {</div>
|
|
<div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  arcs->insert({graph.<a class="code" href="classutil_1_1_complete_graph.html#a2eeae3a8497dc3942e3db3128a10d41c">Tail</a>(arc), graph.<a class="code" href="classutil_1_1_complete_graph.html#aceb0938bcb2e8e5f37986d4cf8e3a955">Head</a>(arc)});</div>
|
|
<div class="line"><a name="l00303"></a><span class="lineno"> 303</span>  arcs->insert({graph.<a class="code" href="classutil_1_1_complete_graph.html#aceb0938bcb2e8e5f37986d4cf8e3a955">Head</a>(arc), graph.<a class="code" href="classutil_1_1_complete_graph.html#a2eeae3a8497dc3942e3db3128a10d41c">Tail</a>(arc)});</div>
|
|
<div class="line"><a name="l00304"></a><span class="lineno"> 304</span>  }</div>
|
|
<div class="line"><a name="l00305"></a><span class="lineno"> 305</span> }</div>
|
|
<div class="line"><a name="l00306"></a><span class="lineno"> 306</span>  </div>
|
|
<div class="line"><a name="l00307"></a><span class="lineno"> 307</span> <span class="comment">// Returns the index of the node in graph which minimizes cost(node, source)</span></div>
|
|
<div class="line"><a name="l00308"></a><span class="lineno"> 308</span> <span class="comment">// with the constraint that accept(node) is true.</span></div>
|
|
<div class="line"><a name="l00309"></a><span class="lineno"> 309</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction, <span class="keyword">typename</span> GraphType, <span class="keyword">typename</span> AcceptFunction></div>
|
|
<div class="line"><a name="l00310"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#aeae6cf89ac4d73d2e95cffaa0edbd687"> 310</a></span> <span class="keywordtype">int</span> <a class="code" href="namespaceoperations__research.html#aeae6cf89ac4d73d2e95cffaa0edbd687">GetNodeMinimizingEdgeCostToSource</a>(<span class="keyword">const</span> GraphType& graph, <span class="keywordtype">int</span> source,</div>
|
|
<div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  AcceptFunction accept) {</div>
|
|
<div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  <span class="keywordtype">int</span> best_node = -1;</div>
|
|
<div class="line"><a name="l00314"></a><span class="lineno"> 314</span>  <span class="keywordtype">double</span> best_edge_cost = 0;</div>
|
|
<div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> node : graph.AllNodes()) {</div>
|
|
<div class="line"><a name="l00316"></a><span class="lineno"> 316</span>  <span class="keywordflow">if</span> (accept(node)) {</div>
|
|
<div class="line"><a name="l00317"></a><span class="lineno"> 317</span>  <span class="keyword">const</span> <span class="keywordtype">double</span> edge_cost = <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(node, source);</div>
|
|
<div class="line"><a name="l00318"></a><span class="lineno"> 318</span>  <span class="keywordflow">if</span> (best_node == -1 || edge_cost < best_edge_cost) {</div>
|
|
<div class="line"><a name="l00319"></a><span class="lineno"> 319</span>  best_node = node;</div>
|
|
<div class="line"><a name="l00320"></a><span class="lineno"> 320</span>  best_edge_cost = edge_cost;</div>
|
|
<div class="line"><a name="l00321"></a><span class="lineno"> 321</span>  }</div>
|
|
<div class="line"><a name="l00322"></a><span class="lineno"> 322</span>  }</div>
|
|
<div class="line"><a name="l00323"></a><span class="lineno"> 323</span>  }</div>
|
|
<div class="line"><a name="l00324"></a><span class="lineno"> 324</span>  <span class="keywordflow">return</span> best_node;</div>
|
|
<div class="line"><a name="l00325"></a><span class="lineno"> 325</span> }</div>
|
|
<div class="line"><a name="l00326"></a><span class="lineno"> 326</span>  </div>
|
|
<div class="line"><a name="l00327"></a><span class="lineno"> 327</span> <span class="comment">// Computes a 1-tree for the given graph, cost function and node weights.</span></div>
|
|
<div class="line"><a name="l00328"></a><span class="lineno"> 328</span> <span class="comment">// Returns the degree of each node in the 1-tree and the un-weighed cost of the</span></div>
|
|
<div class="line"><a name="l00329"></a><span class="lineno"> 329</span> <span class="comment">// 1-tree.</span></div>
|
|
<div class="line"><a name="l00330"></a><span class="lineno"> 330</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction, <span class="keyword">typename</span> GraphType, <span class="keyword">typename</span> CostType></div>
|
|
<div class="line"><a name="l00331"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#aa29730f0377a3408590f4e621af966eb"> 331</a></span> std::vector<int> <a class="code" href="namespaceoperations__research.html#aa29730f0377a3408590f4e621af966eb">ComputeOneTree</a>(<span class="keyword">const</span> GraphType& graph,</div>
|
|
<div class="line"><a name="l00332"></a><span class="lineno"> 332</span>  <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00333"></a><span class="lineno"> 333</span>  <span class="keyword">const</span> std::vector<double>& weights,</div>
|
|
<div class="line"><a name="l00334"></a><span class="lineno"> 334</span>  <span class="keyword">const</span> std::vector<int>& sorted_arcs,</div>
|
|
<div class="line"><a name="l00335"></a><span class="lineno"> 335</span>  CostType* one_tree_cost) {</div>
|
|
<div class="line"><a name="l00336"></a><span class="lineno"> 336</span>  <span class="keyword">const</span> <span class="keyword">auto</span> weighed_cost = [&<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, &weights](<span class="keywordtype">int</span> from, <span class="keywordtype">int</span> to) {</div>
|
|
<div class="line"><a name="l00337"></a><span class="lineno"> 337</span>  <span class="keywordflow">return</span> <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(from, to) + weights[from] + weights[to];</div>
|
|
<div class="line"><a name="l00338"></a><span class="lineno"> 338</span>  };</div>
|
|
<div class="line"><a name="l00339"></a><span class="lineno"> 339</span>  <span class="comment">// Compute MST on graph.</span></div>
|
|
<div class="line"><a name="l00340"></a><span class="lineno"> 340</span>  std::vector<int> mst;</div>
|
|
<div class="line"><a name="l00341"></a><span class="lineno"> 341</span>  <span class="keywordflow">if</span> (!sorted_arcs.empty()) {</div>
|
|
<div class="line"><a name="l00342"></a><span class="lineno"> 342</span>  mst = BuildKruskalMinimumSpanningTreeFromSortedArcs<GraphType>(graph,</div>
|
|
<div class="line"><a name="l00343"></a><span class="lineno"> 343</span>  sorted_arcs);</div>
|
|
<div class="line"><a name="l00344"></a><span class="lineno"> 344</span>  } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><a name="l00345"></a><span class="lineno"> 345</span>  mst = BuildPrimMinimumSpanningTree<GraphType>(</div>
|
|
<div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  graph, [&weighed_cost, &graph](<span class="keywordtype">int</span> arc) {</div>
|
|
<div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  <span class="keywordflow">return</span> weighed_cost(graph.Tail(arc), graph.Head(arc));</div>
|
|
<div class="line"><a name="l00348"></a><span class="lineno"> 348</span>  });</div>
|
|
<div class="line"><a name="l00349"></a><span class="lineno"> 349</span>  }</div>
|
|
<div class="line"><a name="l00350"></a><span class="lineno"> 350</span>  std::vector<int> degrees(graph.num_nodes() + 1, 0);</div>
|
|
<div class="line"><a name="l00351"></a><span class="lineno"> 351</span>  *one_tree_cost = 0;</div>
|
|
<div class="line"><a name="l00352"></a><span class="lineno"> 352</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> arc : mst) {</div>
|
|
<div class="line"><a name="l00353"></a><span class="lineno"> 353</span>  degrees[graph.Head(arc)]++;</div>
|
|
<div class="line"><a name="l00354"></a><span class="lineno"> 354</span>  degrees[graph.Tail(arc)]++;</div>
|
|
<div class="line"><a name="l00355"></a><span class="lineno"> 355</span>  *one_tree_cost += <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(graph.Tail(arc), graph.Head(arc));</div>
|
|
<div class="line"><a name="l00356"></a><span class="lineno"> 356</span>  }</div>
|
|
<div class="line"><a name="l00357"></a><span class="lineno"> 357</span>  <span class="comment">// Add 2 cheapest edges from the nodes in the graph to the extra node not in</span></div>
|
|
<div class="line"><a name="l00358"></a><span class="lineno"> 358</span>  <span class="comment">// the graph.</span></div>
|
|
<div class="line"><a name="l00359"></a><span class="lineno"> 359</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> extra_node = graph.num_nodes();</div>
|
|
<div class="line"><a name="l00360"></a><span class="lineno"> 360</span>  <span class="keyword">const</span> <span class="keyword">auto</span> update_one_tree = [extra_node, one_tree_cost, &degrees,</div>
|
|
<div class="line"><a name="l00361"></a><span class="lineno"> 361</span>  &<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>](<span class="keywordtype">int</span> node) {</div>
|
|
<div class="line"><a name="l00362"></a><span class="lineno"> 362</span>  *one_tree_cost += <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(node, extra_node);</div>
|
|
<div class="line"><a name="l00363"></a><span class="lineno"> 363</span>  degrees.back()++;</div>
|
|
<div class="line"><a name="l00364"></a><span class="lineno"> 364</span>  degrees[node]++;</div>
|
|
<div class="line"><a name="l00365"></a><span class="lineno"> 365</span>  };</div>
|
|
<div class="line"><a name="l00366"></a><span class="lineno"> 366</span>  <span class="keyword">const</span> <span class="keywordtype">int</span> node = <a class="code" href="namespaceoperations__research.html#aeae6cf89ac4d73d2e95cffaa0edbd687">GetNodeMinimizingEdgeCostToSource</a>(</div>
|
|
<div class="line"><a name="l00367"></a><span class="lineno"> 367</span>  graph, extra_node, weighed_cost,</div>
|
|
<div class="line"><a name="l00368"></a><span class="lineno"> 368</span>  [extra_node](<span class="keywordtype">int</span> n) { <span class="keywordflow">return</span> n != extra_node; });</div>
|
|
<div class="line"><a name="l00369"></a><span class="lineno"> 369</span>  update_one_tree(node);</div>
|
|
<div class="line"><a name="l00370"></a><span class="lineno"> 370</span>  update_one_tree(<a class="code" href="namespaceoperations__research.html#aeae6cf89ac4d73d2e95cffaa0edbd687">GetNodeMinimizingEdgeCostToSource</a>(</div>
|
|
<div class="line"><a name="l00371"></a><span class="lineno"> 371</span>  graph, extra_node, weighed_cost,</div>
|
|
<div class="line"><a name="l00372"></a><span class="lineno"> 372</span>  [extra_node, node](<span class="keywordtype">int</span> n) { <span class="keywordflow">return</span> n != extra_node && n != node; }));</div>
|
|
<div class="line"><a name="l00373"></a><span class="lineno"> 373</span>  <span class="keywordflow">return</span> degrees;</div>
|
|
<div class="line"><a name="l00374"></a><span class="lineno"> 374</span> }</div>
|
|
<div class="line"><a name="l00375"></a><span class="lineno"> 375</span>  </div>
|
|
<div class="line"><a name="l00376"></a><span class="lineno"> 376</span> <span class="comment">// Computes the lower bound of a TSP using a given subgradient algorithm.</span></div>
|
|
<div class="line"><a name="l00377"></a><span class="lineno"> 377</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction, <span class="keyword">typename</span> Algorithm></div>
|
|
<div class="line"><a name="l00378"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#a3ed3d609fa06ad508b3d21119f94a560"> 378</a></span> <span class="keywordtype">double</span> <a class="code" href="namespaceoperations__research.html#a3ed3d609fa06ad508b3d21119f94a560">ComputeOneTreeLowerBoundWithAlgorithm</a>(<span class="keywordtype">int</span> number_of_nodes,</div>
|
|
<div class="line"><a name="l00379"></a><span class="lineno"> 379</span>  <span class="keywordtype">int</span> nearest_neighbors,</div>
|
|
<div class="line"><a name="l00380"></a><span class="lineno"> 380</span>  <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00381"></a><span class="lineno"> 381</span>  Algorithm* algorithm) {</div>
|
|
<div class="line"><a name="l00382"></a><span class="lineno"> 382</span>  <span class="keywordflow">if</span> (number_of_nodes < 2) <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00383"></a><span class="lineno"> 383</span>  <span class="keywordflow">if</span> (number_of_nodes == 2) <span class="keywordflow">return</span> <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(0, 1) + <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(1, 0);</div>
|
|
<div class="line"><a name="l00384"></a><span class="lineno"> 384</span>  <span class="keyword">using</span> CostType = decltype(<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(0, 0));</div>
|
|
<div class="line"><a name="l00385"></a><span class="lineno"> 385</span>  <span class="keyword">auto</span> nearest = <a class="code" href="namespaceoperations__research.html#a078701f3ce8570abe24e8157029c8abf">NearestNeighbors</a>(number_of_nodes - 1, nearest_neighbors, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>);</div>
|
|
<div class="line"><a name="l00386"></a><span class="lineno"> 386</span>  <span class="comment">// Ensure nearest arcs result in a connected graph by adding arcs from the</span></div>
|
|
<div class="line"><a name="l00387"></a><span class="lineno"> 387</span>  <span class="comment">// minimum spanning tree; this will add arcs which are likely to be "good"</span></div>
|
|
<div class="line"><a name="l00388"></a><span class="lineno"> 388</span>  <span class="comment">// 1-tree arcs.</span></div>
|
|
<div class="line"><a name="l00389"></a><span class="lineno"> 389</span>  <a class="code" href="namespaceoperations__research.html#adfc52ee652f25f3a2f249ffb830f2e8a">AddArcsFromMinimumSpanningTree</a>(number_of_nodes - 1, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, &nearest);</div>
|
|
<div class="line"><a name="l00390"></a><span class="lineno"> 390</span>  <a class="code" href="classutil_1_1_list_graph.html">util::ListGraph<int, int></a> graph(number_of_nodes - 1, nearest.size());</div>
|
|
<div class="line"><a name="l00391"></a><span class="lineno"> 391</span>  <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>& arc : nearest) {</div>
|
|
<div class="line"><a name="l00392"></a><span class="lineno"> 392</span>  graph.<a class="code" href="classutil_1_1_list_graph.html#a7b505ba4a01bce342d049f5a8674da72">AddArc</a>(arc.first, arc.second);</div>
|
|
<div class="line"><a name="l00393"></a><span class="lineno"> 393</span>  }</div>
|
|
<div class="line"><a name="l00394"></a><span class="lineno"> 394</span>  std::vector<double> weights(number_of_nodes, 0);</div>
|
|
<div class="line"><a name="l00395"></a><span class="lineno"> 395</span>  std::vector<double> best_weights(number_of_nodes, 0);</div>
|
|
<div class="line"><a name="l00396"></a><span class="lineno"> 396</span>  <span class="keywordtype">double</span> max_w = -std::numeric_limits<double>::infinity();</div>
|
|
<div class="line"><a name="l00397"></a><span class="lineno"> 397</span>  <span class="keywordtype">double</span> w = 0;</div>
|
|
<div class="line"><a name="l00398"></a><span class="lineno"> 398</span>  <span class="comment">// Iteratively compute lower bound using a partial graph.</span></div>
|
|
<div class="line"><a name="l00399"></a><span class="lineno"> 399</span>  <span class="keywordflow">while</span> (algorithm->Next()) {</div>
|
|
<div class="line"><a name="l00400"></a><span class="lineno"> 400</span>  CostType one_tree_cost = 0;</div>
|
|
<div class="line"><a name="l00401"></a><span class="lineno"> 401</span>  <span class="keyword">const</span> std::vector<int> degrees =</div>
|
|
<div class="line"><a name="l00402"></a><span class="lineno"> 402</span>  <a class="code" href="namespaceoperations__research.html#aa29730f0377a3408590f4e621af966eb">ComputeOneTree</a>(graph, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, weights, {}, &one_tree_cost);</div>
|
|
<div class="line"><a name="l00403"></a><span class="lineno"> 403</span>  algorithm->OnOneTree(one_tree_cost, w, degrees);</div>
|
|
<div class="line"><a name="l00404"></a><span class="lineno"> 404</span>  w = one_tree_cost;</div>
|
|
<div class="line"><a name="l00405"></a><span class="lineno"> 405</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < number_of_nodes; ++j) {</div>
|
|
<div class="line"><a name="l00406"></a><span class="lineno"> 406</span>  w += weights[j] * (degrees[j] - 2);</div>
|
|
<div class="line"><a name="l00407"></a><span class="lineno"> 407</span>  }</div>
|
|
<div class="line"><a name="l00408"></a><span class="lineno"> 408</span>  <span class="keywordflow">if</span> (w > max_w) {</div>
|
|
<div class="line"><a name="l00409"></a><span class="lineno"> 409</span>  max_w = w;</div>
|
|
<div class="line"><a name="l00410"></a><span class="lineno"> 410</span>  best_weights = weights;</div>
|
|
<div class="line"><a name="l00411"></a><span class="lineno"> 411</span>  algorithm->OnNewWMax(one_tree_cost);</div>
|
|
<div class="line"><a name="l00412"></a><span class="lineno"> 412</span>  }</div>
|
|
<div class="line"><a name="l00413"></a><span class="lineno"> 413</span>  <span class="keyword">const</span> <span class="keywordtype">double</span> step = algorithm->GetStep();</div>
|
|
<div class="line"><a name="l00414"></a><span class="lineno"> 414</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < number_of_nodes; ++j) {</div>
|
|
<div class="line"><a name="l00415"></a><span class="lineno"> 415</span>  weights[j] += step * (degrees[j] - 2);</div>
|
|
<div class="line"><a name="l00416"></a><span class="lineno"> 416</span>  }</div>
|
|
<div class="line"><a name="l00417"></a><span class="lineno"> 417</span>  }</div>
|
|
<div class="line"><a name="l00418"></a><span class="lineno"> 418</span>  <span class="comment">// Compute lower bound using the complete graph on the best weights. This is</span></div>
|
|
<div class="line"><a name="l00419"></a><span class="lineno"> 419</span>  <span class="comment">// necessary as the MSTs computed on nearest neighbors is not guaranteed to</span></div>
|
|
<div class="line"><a name="l00420"></a><span class="lineno"> 420</span>  <span class="comment">// lead to a lower bound.</span></div>
|
|
<div class="line"><a name="l00421"></a><span class="lineno"> 421</span>  <a class="code" href="classutil_1_1_complete_graph.html">util::CompleteGraph<int, int></a> complete_graph(number_of_nodes - 1);</div>
|
|
<div class="line"><a name="l00422"></a><span class="lineno"> 422</span>  CostType one_tree_cost = 0;</div>
|
|
<div class="line"><a name="l00423"></a><span class="lineno"> 423</span>  <span class="comment">// TODO(user): We are not caching here since this would take O(n^2) memory;</span></div>
|
|
<div class="line"><a name="l00424"></a><span class="lineno"> 424</span>  <span class="comment">// however the Kruskal algorithm will expand all arcs also consuming O(n^2)</span></div>
|
|
<div class="line"><a name="l00425"></a><span class="lineno"> 425</span>  <span class="comment">// memory; investigate alternatives to expanding all arcs (Prim's algorithm).</span></div>
|
|
<div class="line"><a name="l00426"></a><span class="lineno"> 426</span>  <span class="keyword">const</span> std::vector<int> degrees =</div>
|
|
<div class="line"><a name="l00427"></a><span class="lineno"> 427</span>  <a class="code" href="namespaceoperations__research.html#aa29730f0377a3408590f4e621af966eb">ComputeOneTree</a>(complete_graph, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, best_weights, {}, &one_tree_cost);</div>
|
|
<div class="line"><a name="l00428"></a><span class="lineno"> 428</span>  w = one_tree_cost;</div>
|
|
<div class="line"><a name="l00429"></a><span class="lineno"> 429</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < number_of_nodes; ++j) {</div>
|
|
<div class="line"><a name="l00430"></a><span class="lineno"> 430</span>  w += best_weights[j] * (degrees[j] - 2);</div>
|
|
<div class="line"><a name="l00431"></a><span class="lineno"> 431</span>  }</div>
|
|
<div class="line"><a name="l00432"></a><span class="lineno"> 432</span>  <span class="keywordflow">return</span> w;</div>
|
|
<div class="line"><a name="l00433"></a><span class="lineno"> 433</span> }</div>
|
|
<div class="line"><a name="l00434"></a><span class="lineno"> 434</span>  </div>
|
|
<div class="line"><a name="l00435"></a><span class="lineno"> 435</span> <span class="comment">// Parameters to configure the computation of the TSP lower bound.</span></div>
|
|
<div class="line"><a name="l00436"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html"> 436</a></span> <span class="keyword">struct </span><a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html">TravelingSalesmanLowerBoundParameters</a> {</div>
|
|
<div class="line"><a name="l00437"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691"> 437</a></span>  <span class="keyword">enum</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691">Algorithm</a> {</div>
|
|
<div class="line"><a name="l00438"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935"> 438</a></span>  <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935">VolgenantJonker</a>,</div>
|
|
<div class="line"><a name="l00439"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691aab5026cdecee6d30b78813ed209bbba3"> 439</a></span>  <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691aab5026cdecee6d30b78813ed209bbba3">HeldWolfeCrowder</a>,</div>
|
|
<div class="line"><a name="l00440"></a><span class="lineno"> 440</span>  };</div>
|
|
<div class="line"><a name="l00441"></a><span class="lineno"> 441</span>  <span class="comment">// Subgradient algorithm to use to compute the TSP lower bound.</span></div>
|
|
<div class="line"><a name="l00442"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#acc4ba09a6333be056db50ed15007518c"> 442</a></span>  <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691">Algorithm</a> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#acc4ba09a6333be056db50ed15007518c">algorithm</a> = <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935">VolgenantJonker</a>;</div>
|
|
<div class="line"><a name="l00443"></a><span class="lineno"> 443</span>  <span class="comment">// Number of iterations to use in the Volgenant-Jonker algorithm. Overrides</span></div>
|
|
<div class="line"><a name="l00444"></a><span class="lineno"> 444</span>  <span class="comment">// automatic iteration computation if positive.</span></div>
|
|
<div class="line"><a name="l00445"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#aa5624a1c87ea6c30028af3168aa6daf9"> 445</a></span>  <span class="keywordtype">int</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#aa5624a1c87ea6c30028af3168aa6daf9">volgenant_jonker_iterations</a> = 0;</div>
|
|
<div class="line"><a name="l00446"></a><span class="lineno"> 446</span>  <span class="comment">// Number of nearest neighbors to consider in the miminum spanning trees.</span></div>
|
|
<div class="line"><a name="l00447"></a><span class="lineno"><a class="line" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#ac0c01b0297a60d1b72ac046280057e20"> 447</a></span>  <span class="keywordtype">int</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#ac0c01b0297a60d1b72ac046280057e20">nearest_neighbors</a> = 40;</div>
|
|
<div class="line"><a name="l00448"></a><span class="lineno"> 448</span> };</div>
|
|
<div class="line"><a name="l00449"></a><span class="lineno"> 449</span>  </div>
|
|
<div class="line"><a name="l00450"></a><span class="lineno"> 450</span> <span class="comment">// Computes the lower bound of a TSP using given parameters.</span></div>
|
|
<div class="line"><a name="l00451"></a><span class="lineno"> 451</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction></div>
|
|
<div class="line"><a name="l00452"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#a516a7ec8626d689aa84729fb6f358f89"> 452</a></span> <span class="keywordtype">double</span> <a class="code" href="namespaceoperations__research.html#a516a7ec8626d689aa84729fb6f358f89">ComputeOneTreeLowerBoundWithParameters</a>(</div>
|
|
<div class="line"><a name="l00453"></a><span class="lineno"> 453</span>  <span class="keywordtype">int</span> number_of_nodes, <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00454"></a><span class="lineno"> 454</span>  <span class="keyword">const</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html">TravelingSalesmanLowerBoundParameters</a>& <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>) {</div>
|
|
<div class="line"><a name="l00455"></a><span class="lineno"> 455</span>  <span class="keyword">using</span> CostType = decltype(<a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>(0, 0));</div>
|
|
<div class="line"><a name="l00456"></a><span class="lineno"> 456</span>  <span class="keywordflow">switch</span> (<a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>.algorithm) {</div>
|
|
<div class="line"><a name="l00457"></a><span class="lineno"> 457</span>  <span class="keywordflow">case</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935">TravelingSalesmanLowerBoundParameters::VolgenantJonker</a>: {</div>
|
|
<div class="line"><a name="l00458"></a><span class="lineno"> 458</span>  <a class="code" href="classoperations__research_1_1_volgenant_jonker_evaluator.html">VolgenantJonkerEvaluator<CostType></a> algorithm(</div>
|
|
<div class="line"><a name="l00459"></a><span class="lineno"> 459</span>  number_of_nodes, <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>.volgenant_jonker_iterations);</div>
|
|
<div class="line"><a name="l00460"></a><span class="lineno"> 460</span>  <span class="keywordflow">return</span> <a class="code" href="namespaceoperations__research.html#a3ed3d609fa06ad508b3d21119f94a560">ComputeOneTreeLowerBoundWithAlgorithm</a>(</div>
|
|
<div class="line"><a name="l00461"></a><span class="lineno"> 461</span>  number_of_nodes, <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>.nearest_neighbors, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, &algorithm);</div>
|
|
<div class="line"><a name="l00462"></a><span class="lineno"> 462</span>  <span class="keywordflow">break</span>;</div>
|
|
<div class="line"><a name="l00463"></a><span class="lineno"> 463</span>  }</div>
|
|
<div class="line"><a name="l00464"></a><span class="lineno"> 464</span>  <span class="keywordflow">case</span> <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691aab5026cdecee6d30b78813ed209bbba3">TravelingSalesmanLowerBoundParameters::HeldWolfeCrowder</a>: {</div>
|
|
<div class="line"><a name="l00465"></a><span class="lineno"> 465</span>  <a class="code" href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html">HeldWolfeCrowderEvaluator<CostType, CostFunction></a> algorithm(</div>
|
|
<div class="line"><a name="l00466"></a><span class="lineno"> 466</span>  number_of_nodes, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>);</div>
|
|
<div class="line"><a name="l00467"></a><span class="lineno"> 467</span>  <span class="keywordflow">return</span> <a class="code" href="namespaceoperations__research.html#a3ed3d609fa06ad508b3d21119f94a560">ComputeOneTreeLowerBoundWithAlgorithm</a>(</div>
|
|
<div class="line"><a name="l00468"></a><span class="lineno"> 468</span>  number_of_nodes, <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>.nearest_neighbors, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>, &algorithm);</div>
|
|
<div class="line"><a name="l00469"></a><span class="lineno"> 469</span>  }</div>
|
|
<div class="line"><a name="l00470"></a><span class="lineno"> 470</span>  <span class="keywordflow">default</span>:</div>
|
|
<div class="line"><a name="l00471"></a><span class="lineno"> 471</span>  <a class="code" href="base_2logging_8h.html#accad43a85d781d53381cd53a9894b6ae">LOG</a>(<a class="code" href="log__severity_8h.html#ac9bcbe19995a8140cd4ec61773cd6e67">ERROR</a>) << <span class="stringliteral">"Unsupported algorithm: "</span> << <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>.algorithm;</div>
|
|
<div class="line"><a name="l00472"></a><span class="lineno"> 472</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00473"></a><span class="lineno"> 473</span>  }</div>
|
|
<div class="line"><a name="l00474"></a><span class="lineno"> 474</span> }</div>
|
|
<div class="line"><a name="l00475"></a><span class="lineno"> 475</span>  </div>
|
|
<div class="line"><a name="l00476"></a><span class="lineno"> 476</span> <span class="comment">// Computes the lower bound of a TSP using default parameters (Volgenant-Jonker</span></div>
|
|
<div class="line"><a name="l00477"></a><span class="lineno"> 477</span> <span class="comment">// algorithm, 200 iterations and 40 nearest neighbors) which have turned out to</span></div>
|
|
<div class="line"><a name="l00478"></a><span class="lineno"> 478</span> <span class="comment">// give good results on the TSPLIB.</span></div>
|
|
<div class="line"><a name="l00479"></a><span class="lineno"> 479</span> <span class="keyword">template</span> <<span class="keyword">typename</span> CostFunction></div>
|
|
<div class="line"><a name="l00480"></a><span class="lineno"><a class="line" href="namespaceoperations__research.html#ae9af26e7687cb65967941eb175148fe5"> 480</a></span> <span class="keywordtype">double</span> <a class="code" href="namespaceoperations__research.html#ae9af26e7687cb65967941eb175148fe5">ComputeOneTreeLowerBound</a>(<span class="keywordtype">int</span> number_of_nodes, <span class="keyword">const</span> CostFunction& <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>) {</div>
|
|
<div class="line"><a name="l00481"></a><span class="lineno"> 481</span>  <a class="code" href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html">TravelingSalesmanLowerBoundParameters</a> <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>;</div>
|
|
<div class="line"><a name="l00482"></a><span class="lineno"> 482</span>  <span class="keywordflow">return</span> <a class="code" href="namespaceoperations__research.html#a516a7ec8626d689aa84729fb6f358f89">ComputeOneTreeLowerBoundWithParameters</a>(number_of_nodes, <a class="code" href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a>,</div>
|
|
<div class="line"><a name="l00483"></a><span class="lineno"> 483</span>  <a class="code" href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a>);</div>
|
|
<div class="line"><a name="l00484"></a><span class="lineno"> 484</span> }</div>
|
|
<div class="line"><a name="l00485"></a><span class="lineno"> 485</span>  </div>
|
|
<div class="line"><a name="l00486"></a><span class="lineno"> 486</span> } <span class="comment">// namespace operations_research</span></div>
|
|
<div class="line"><a name="l00487"></a><span class="lineno"> 487</span>  </div>
|
|
<div class="line"><a name="l00488"></a><span class="lineno"> 488</span> <span class="preprocessor">#endif </span><span class="comment">// OR_TOOLS_GRAPH_ONE_TREE_LOWER_BOUND_H_</span></div>
|
|
<div class="ttc" id="abase_2logging_8h_html_accad43a85d781d53381cd53a9894b6ae"><div class="ttname"><a href="base_2logging_8h.html#accad43a85d781d53381cd53a9894b6ae">LOG</a></div><div class="ttdeci">#define LOG(severity)</div><div class="ttdef"><b>Definition:</b> <a href="base_2logging_8h_source.html#l00420">base/logging.h:420</a></div></div>
|
|
<div class="ttc" id="achristofides_8h_html"><div class="ttname"><a href="christofides_8h.html">christofides.h</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_christofides_path_solver_html"><div class="ttname"><a href="classoperations__research_1_1_christofides_path_solver.html">operations_research::ChristofidesPathSolver</a></div><div class="ttdef"><b>Definition:</b> <a href="christofides_8h_source.html#l00042">christofides.h:42</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_christofides_path_solver_html_ab558649a26fef3a74f0909ef5af45e90"><div class="ttname"><a href="classoperations__research_1_1_christofides_path_solver.html#ab558649a26fef3a74f0909ef5af45e90">operations_research::ChristofidesPathSolver::TravelingSalesmanCost</a></div><div class="ttdeci">CostType TravelingSalesmanCost()</div><div class="ttdef"><b>Definition:</b> <a href="christofides_8h_source.html#l00230">christofides.h:230</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html">operations_research::HeldWolfeCrowderEvaluator</a></div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00206">one_tree_lower_bound.h:206</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html_a2ad04ff9537d97fcabc58c86183890c3"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3">operations_research::HeldWolfeCrowderEvaluator::OnNewWMax</a></div><div class="ttdeci">void OnNewWMax(CostType one_tree_cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00246">one_tree_lower_bound.h:246</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html_a33c2c5b8d838c77c2701a538f7f30ae4"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4">operations_research::HeldWolfeCrowderEvaluator::OnOneTree</a></div><div class="ttdeci">void OnOneTree(CostType one_tree_cost, double w, const std::vector< int > &degrees)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00236">one_tree_lower_bound.h:236</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html_a3947d19ac087ef2cd68c2409920339c4"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a3947d19ac087ef2cd68c2409920339c4">operations_research::HeldWolfeCrowderEvaluator::Next</a></div><div class="ttdeci">bool Next()</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00221">one_tree_lower_bound.h:221</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html_a61aed6a943277e531b904cfdc3616890"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#a61aed6a943277e531b904cfdc3616890">operations_research::HeldWolfeCrowderEvaluator::GetStep</a></div><div class="ttdeci">double GetStep() const</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00234">one_tree_lower_bound.h:234</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_held_wolfe_crowder_evaluator_html_adb1dee05e699715da68918f6b19d3e6d"><div class="ttname"><a href="classoperations__research_1_1_held_wolfe_crowder_evaluator.html#adb1dee05e699715da68918f6b19d3e6d">operations_research::HeldWolfeCrowderEvaluator::HeldWolfeCrowderEvaluator</a></div><div class="ttdeci">HeldWolfeCrowderEvaluator(int number_of_nodes, const CostFunction &cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00208">one_tree_lower_bound.h:208</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html">operations_research::VolgenantJonkerEvaluator</a></div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00153">one_tree_lower_bound.h:153</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html_a24cfa064cc97e776b361abdba5488673"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a24cfa064cc97e776b361abdba5488673">operations_research::VolgenantJonkerEvaluator::VolgenantJonkerEvaluator</a></div><div class="ttdeci">VolgenantJonkerEvaluator(int number_of_nodes, int max_iterations)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00155">one_tree_lower_bound.h:155</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html_a2ad04ff9537d97fcabc58c86183890c3"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a2ad04ff9537d97fcabc58c86183890c3">operations_research::VolgenantJonkerEvaluator::OnNewWMax</a></div><div class="ttdeci">void OnNewWMax(CostType one_tree_cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00183">one_tree_lower_bound.h:183</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html_a33c2c5b8d838c77c2701a538f7f30ae4"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a33c2c5b8d838c77c2701a538f7f30ae4">operations_research::VolgenantJonkerEvaluator::OnOneTree</a></div><div class="ttdeci">void OnOneTree(CostType one_tree_cost, double w, const std::vector< int > &degrees)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00175">one_tree_lower_bound.h:175</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html_a3947d19ac087ef2cd68c2409920339c4"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a3947d19ac087ef2cd68c2409920339c4">operations_research::VolgenantJonkerEvaluator::Next</a></div><div class="ttdeci">bool Next()</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00163">one_tree_lower_bound.h:163</a></div></div>
|
|
<div class="ttc" id="aclassoperations__research_1_1_volgenant_jonker_evaluator_html_a61aed6a943277e531b904cfdc3616890"><div class="ttname"><a href="classoperations__research_1_1_volgenant_jonker_evaluator.html#a61aed6a943277e531b904cfdc3616890">operations_research::VolgenantJonkerEvaluator::GetStep</a></div><div class="ttdeci">double GetStep() const</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00165">one_tree_lower_bound.h:165</a></div></div>
|
|
<div class="ttc" id="aclassutil_1_1_complete_graph_html"><div class="ttname"><a href="classutil_1_1_complete_graph.html">util::CompleteGraph</a></div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l02176">graph.h:2176</a></div></div>
|
|
<div class="ttc" id="aclassutil_1_1_complete_graph_html_a2eeae3a8497dc3942e3db3128a10d41c"><div class="ttname"><a href="classutil_1_1_complete_graph.html#a2eeae3a8497dc3942e3db3128a10d41c">util::CompleteGraph::Tail</a></div><div class="ttdeci">NodeIndexType Tail(ArcIndexType arc) const</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l02210">graph.h:2210</a></div></div>
|
|
<div class="ttc" id="aclassutil_1_1_complete_graph_html_aceb0938bcb2e8e5f37986d4cf8e3a955"><div class="ttname"><a href="classutil_1_1_complete_graph.html#aceb0938bcb2e8e5f37986d4cf8e3a955">util::CompleteGraph::Head</a></div><div class="ttdeci">NodeIndexType Head(ArcIndexType arc) const</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l02203">graph.h:2203</a></div></div>
|
|
<div class="ttc" id="aclassutil_1_1_list_graph_html"><div class="ttname"><a href="classutil_1_1_list_graph.html">util::ListGraph</a></div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00298">graph.h:298</a></div></div>
|
|
<div class="ttc" id="aclassutil_1_1_list_graph_html_a7b505ba4a01bce342d049f5a8674da72"><div class="ttname"><a href="classutil_1_1_list_graph.html#a7b505ba4a01bce342d049f5a8674da72">util::ListGraph::AddArc</a></div><div class="ttdeci">ArcIndexType AddArc(NodeIndexType tail, NodeIndexType head)</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l01140">graph.h:1140</a></div></div>
|
|
<div class="ttc" id="acp__model__fz__solver_8cc_html_a10a1eab179b472c030bdc2a2efef7219"><div class="ttname"><a href="cp__model__fz__solver_8cc.html#a10a1eab179b472c030bdc2a2efef7219">parameters</a></div><div class="ttdeci">SatParameters parameters</div><div class="ttdef"><b>Definition:</b> <a href="cp__model__fz__solver_8cc_source.html#l00108">cp_model_fz_solver.cc:108</a></div></div>
|
|
<div class="ttc" id="aintegral__types_8h_html"><div class="ttname"><a href="integral__types_8h.html">integral_types.h</a></div></div>
|
|
<div class="ttc" id="alog__severity_8h_html_ac9bcbe19995a8140cd4ec61773cd6e67"><div class="ttname"><a href="log__severity_8h.html#ac9bcbe19995a8140cd4ec61773cd6e67">ERROR</a></div><div class="ttdeci">const int ERROR</div><div class="ttdef"><b>Definition:</b> <a href="log__severity_8h_source.html#l00032">log_severity.h:32</a></div></div>
|
|
<div class="ttc" id="aminimum__spanning__tree_8h_html"><div class="ttname"><a href="minimum__spanning__tree_8h.html">minimum_spanning_tree.h</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdoc">The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...</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_a078701f3ce8570abe24e8157029c8abf"><div class="ttname"><a href="namespaceoperations__research.html#a078701f3ce8570abe24e8157029c8abf">operations_research::NearestNeighbors</a></div><div class="ttdeci">std::set< std::pair< int, int > > NearestNeighbors(int number_of_nodes, int number_of_neighbors, const CostFunction &cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00262">one_tree_lower_bound.h:262</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_a33a2f4c26fd60cd0fa98257b571c974f"><div class="ttname"><a href="namespaceoperations__research.html#a33a2f4c26fd60cd0fa98257b571c974f">operations_research::BuildPrimMinimumSpanningTree</a></div><div class="ttdeci">std::vector< typename Graph::ArcIndex > BuildPrimMinimumSpanningTree(const Graph &graph, const ArcValue &arc_value)</div><div class="ttdef"><b>Definition:</b> <a href="minimum__spanning__tree_8h_source.html#l00115">minimum_spanning_tree.h:115</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_a3ed3d609fa06ad508b3d21119f94a560"><div class="ttname"><a href="namespaceoperations__research.html#a3ed3d609fa06ad508b3d21119f94a560">operations_research::ComputeOneTreeLowerBoundWithAlgorithm</a></div><div class="ttdeci">double ComputeOneTreeLowerBoundWithAlgorithm(int number_of_nodes, int nearest_neighbors, const CostFunction &cost, Algorithm *algorithm)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00378">one_tree_lower_bound.h:378</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_a516a7ec8626d689aa84729fb6f358f89"><div class="ttname"><a href="namespaceoperations__research.html#a516a7ec8626d689aa84729fb6f358f89">operations_research::ComputeOneTreeLowerBoundWithParameters</a></div><div class="ttdeci">double ComputeOneTreeLowerBoundWithParameters(int number_of_nodes, const CostFunction &cost, const TravelingSalesmanLowerBoundParameters &parameters)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00452">one_tree_lower_bound.h:452</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_aa29730f0377a3408590f4e621af966eb"><div class="ttname"><a href="namespaceoperations__research.html#aa29730f0377a3408590f4e621af966eb">operations_research::ComputeOneTree</a></div><div class="ttdeci">std::vector< int > ComputeOneTree(const GraphType &graph, const CostFunction &cost, const std::vector< double > &weights, const std::vector< int > &sorted_arcs, CostType *one_tree_cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00331">one_tree_lower_bound.h:331</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_adfc52ee652f25f3a2f249ffb830f2e8a"><div class="ttname"><a href="namespaceoperations__research.html#adfc52ee652f25f3a2f249ffb830f2e8a">operations_research::AddArcsFromMinimumSpanningTree</a></div><div class="ttdeci">void AddArcsFromMinimumSpanningTree(int number_of_nodes, const CostFunction &cost, std::set< std::pair< int, int >> *arcs)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00293">one_tree_lower_bound.h:293</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_ae9af26e7687cb65967941eb175148fe5"><div class="ttname"><a href="namespaceoperations__research.html#ae9af26e7687cb65967941eb175148fe5">operations_research::ComputeOneTreeLowerBound</a></div><div class="ttdeci">double ComputeOneTreeLowerBound(int number_of_nodes, const CostFunction &cost)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00480">one_tree_lower_bound.h:480</a></div></div>
|
|
<div class="ttc" id="anamespaceoperations__research_html_aeae6cf89ac4d73d2e95cffaa0edbd687"><div class="ttname"><a href="namespaceoperations__research.html#aeae6cf89ac4d73d2e95cffaa0edbd687">operations_research::GetNodeMinimizingEdgeCostToSource</a></div><div class="ttdeci">int GetNodeMinimizingEdgeCostToSource(const GraphType &graph, int source, const CostFunction &cost, AcceptFunction accept)</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00310">one_tree_lower_bound.h:310</a></div></div>
|
|
<div class="ttc" id="aresource_8cc_html_a73461c37822b6ebb75b54ba1a9ffb442"><div class="ttname"><a href="resource_8cc.html#a73461c37822b6ebb75b54ba1a9ffb442">delta</a></div><div class="ttdeci">int64 delta</div><div class="ttdef"><b>Definition:</b> <a href="resource_8cc_source.html#l01684">resource.cc:1684</a></div></div>
|
|
<div class="ttc" id="arouting__flow_8cc_html_a26a8cbbc7bcf4117c2bf65104b4a54b4"><div class="ttname"><a href="routing__flow_8cc.html#a26a8cbbc7bcf4117c2bf65104b4a54b4">cost</a></div><div class="ttdeci">int64 cost</div><div class="ttdef"><b>Definition:</b> <a href="routing__flow_8cc_source.html#l00130">routing_flow.cc:130</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html">operations_research::TravelingSalesmanLowerBoundParameters</a></div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00436">one_tree_lower_bound.h:436</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_a5e41188f16a381c8915a17a22228e691"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691">operations_research::TravelingSalesmanLowerBoundParameters::Algorithm</a></div><div class="ttdeci">Algorithm</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00437">one_tree_lower_bound.h:437</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691a324779d0e6f33b00553606d001821935">operations_research::TravelingSalesmanLowerBoundParameters::VolgenantJonker</a></div><div class="ttdeci">@ VolgenantJonker</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00438">one_tree_lower_bound.h:438</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_a5e41188f16a381c8915a17a22228e691aab5026cdecee6d30b78813ed209bbba3"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#a5e41188f16a381c8915a17a22228e691aab5026cdecee6d30b78813ed209bbba3">operations_research::TravelingSalesmanLowerBoundParameters::HeldWolfeCrowder</a></div><div class="ttdeci">@ HeldWolfeCrowder</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00439">one_tree_lower_bound.h:439</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_aa5624a1c87ea6c30028af3168aa6daf9"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#aa5624a1c87ea6c30028af3168aa6daf9">operations_research::TravelingSalesmanLowerBoundParameters::volgenant_jonker_iterations</a></div><div class="ttdeci">int volgenant_jonker_iterations</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00445">one_tree_lower_bound.h:445</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_ac0c01b0297a60d1b72ac046280057e20"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#ac0c01b0297a60d1b72ac046280057e20">operations_research::TravelingSalesmanLowerBoundParameters::nearest_neighbors</a></div><div class="ttdeci">int nearest_neighbors</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00447">one_tree_lower_bound.h:447</a></div></div>
|
|
<div class="ttc" id="astructoperations__research_1_1_traveling_salesman_lower_bound_parameters_html_acc4ba09a6333be056db50ed15007518c"><div class="ttname"><a href="structoperations__research_1_1_traveling_salesman_lower_bound_parameters.html#acc4ba09a6333be056db50ed15007518c">operations_research::TravelingSalesmanLowerBoundParameters::algorithm</a></div><div class="ttdeci">Algorithm algorithm</div><div class="ttdef"><b>Definition:</b> <a href="one__tree__lower__bound_8h_source.html#l00442">one_tree_lower_bound.h:442</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- HTML footer for doxygen 1.8.18-->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_a7cc1eeded8f693d0da6c729bc88c45a.html">ortools</a></li><li class="navelem"><a class="el" href="dir_725f3a5915051842f84e3ea508be2a62.html">graph</a></li><li class="navelem"><a class="el" href="one__tree__lower__bound_8h.html">one_tree_lower_bound.h</a></li>
|
|
<li class="footer">Generated by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|