<ahref="assignment_8h.html">Go to the documentation of this file.</a><divclass="fragment"><divclass="line"><aid="l00001"name="l00001"></a><spanclass="lineno"> 1</span><spanclass="comment">// Copyright 2010-2021 Google LLC</span></div>
<divclass="line"><aid="l00002"name="l00002"></a><spanclass="lineno"> 2</span><spanclass="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div>
<divclass="line"><aid="l00003"name="l00003"></a><spanclass="lineno"> 3</span><spanclass="comment">// you may not use this file except in compliance with the License.</span></div>
<divclass="line"><aid="l00004"name="l00004"></a><spanclass="lineno"> 4</span><spanclass="comment">// You may obtain a copy of the License at</span></div>
<divclass="line"><aid="l00008"name="l00008"></a><spanclass="lineno"> 8</span><spanclass="comment">// Unless required by applicable law or agreed to in writing, software</span></div>
<divclass="line"><aid="l00009"name="l00009"></a><spanclass="lineno"> 9</span><spanclass="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div>
<divclass="line"><aid="l00010"name="l00010"></a><spanclass="lineno"> 10</span><spanclass="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<divclass="line"><aid="l00011"name="l00011"></a><spanclass="lineno"> 11</span><spanclass="comment">// See the License for the specific language governing permissions and</span></div>
<divclass="line"><aid="l00012"name="l00012"></a><spanclass="lineno"> 12</span><spanclass="comment">// limitations under the License.</span></div>
<divclass="line"><aid="l00014"name="l00014"></a><spanclass="lineno"> 14</span><spanclass="comment">// Simple interface to solve the linear sum assignment problem. It</span></div>
<divclass="line"><aid="l00015"name="l00015"></a><spanclass="lineno"> 15</span><spanclass="comment">// uses about twice as much memory as directly using the</span></div>
<divclass="line"><aid="l00016"name="l00016"></a><spanclass="lineno"> 16</span><spanclass="comment">// LinearSumAssignment class template, but it is as fast and presents</span></div>
<divclass="line"><aid="l00017"name="l00017"></a><spanclass="lineno"> 17</span><spanclass="comment">// a simpler interface. This is the class you should use in most</span></div>
<divclass="line"><aid="l00020"name="l00020"></a><spanclass="lineno"> 20</span><spanclass="comment">// The assignment problem: Given N "left" nodes and N "right" nodes,</span></div>
<divclass="line"><aid="l00021"name="l00021"></a><spanclass="lineno"> 21</span><spanclass="comment">// and a set of left->right arcs with integer costs, find a perfect</span></div>
<divclass="line"><aid="l00022"name="l00022"></a><spanclass="lineno"> 22</span><spanclass="comment">// matching (i.e., each "left" node is assigned to one "right" node)</span></div>
<divclass="line"><aid="l00023"name="l00023"></a><spanclass="lineno"> 23</span><spanclass="comment">// that minimizes the overall cost.</span></div>
<divclass="line"><aid="l00035"name="l00035"></a><spanclass="lineno"> 35</span><spanclass="comment">// printf("The best possible cost is %d.\n", assignment.OptimalCost());</span></div>
<divclass="line"><aid="l00038"name="l00038"></a><spanclass="lineno"> 38</span><spanclass="comment">// printf("left node %d assigned to right node %d with cost %d.\n",</span></div>
<divclass="line"><aid="l00043"name="l00043"></a><spanclass="lineno"> 43</span><spanclass="comment">// printf("Note that it may not be the unique optimal assignment.");</span></div>
<divclass="line"><aid="l00045"name="l00045"></a><spanclass="lineno"> 45</span><spanclass="comment">// printf("There is an issue with the input or no perfect matching exists.");</span></div>
<divclass="line"><aid="l00059"name="l00059"></a><spanclass="lineno"> 59</span><spanclass="comment">// The constructor takes no size.</span></div>
<divclass="line"><aid="l00060"name="l00060"></a><spanclass="lineno"> 60</span><spanclass="comment">// New node indices will be created lazily by AddArcWithCost().</span></div>
<divclass="line"><aid="l00063"name="l00063"></a><spanclass="lineno"> 63</span><spanclass="comment">// Adds an arc from a left node to a right node with a given cost.</span></div>
<divclass="line"><aid="l00064"name="l00064"></a><spanclass="lineno"> 64</span><spanclass="comment">// * Node indices must be non-negative (>= 0). For a perfect</span></div>
<divclass="line"><aid="l00065"name="l00065"></a><spanclass="lineno"> 65</span><spanclass="comment">// matching to exist on n nodes, the values taken by "left_node"</span></div>
<divclass="line"><aid="l00066"name="l00066"></a><spanclass="lineno"> 66</span><spanclass="comment">// must cover [0, n), same for "right_node".</span></div>
<divclass="line"><aid="l00067"name="l00067"></a><spanclass="lineno"> 67</span><spanclass="comment">// * The arc cost can be any integer, negative, positive or zero.</span></div>
<divclass="line"><aid="l00068"name="l00068"></a><spanclass="lineno"> 68</span><spanclass="comment">// * After the method finishes, NumArcs() == the returned ArcIndex + 1.</span></div>
<divclass="line"><aid="l00072"name="l00072"></a><spanclass="lineno"> 72</span><spanclass="comment">// Returns the current number of left nodes which is the same as the</span></div>
<divclass="line"><aid="l00073"name="l00073"></a><spanclass="lineno"> 73</span><spanclass="comment">// number of right nodes. This is one greater than the largest node</span></div>
<divclass="line"><aid="l00074"name="l00074"></a><spanclass="lineno"> 74</span><spanclass="comment">// index seen so far in AddArcWithCost().</span></div>
<divclass="line"><aid="l00077"name="l00077"></a><spanclass="lineno"> 77</span><spanclass="comment">// Returns the current number of arcs in the graph.</span></div>
<divclass="line"><aid="l00081"name="l00081"></a><spanclass="lineno"> 81</span><spanclass="comment">// The implementation will crash if "arc" is not in [0, NumArcs()).</span></div>
<divclass="line"><aid="l00086"name="l00086"></a><spanclass="lineno"> 86</span><spanclass="comment">// Solves the problem (finds the perfect matching that minimizes the</span></div>
<divclass="line"><aid="l00087"name="l00087"></a><spanclass="lineno"> 87</span><spanclass="comment">// cost) and returns the solver status.</span></div>
<divclass="line"><aid="l00089"name="l00089"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2579881e7c83261bc21bafb5a5c92cad"> 89</a></span><aclass="code hl_enumvalue"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2579881e7c83261bc21bafb5a5c92cad">OPTIMAL</a>, <spanclass="comment">// The algorithm found a minimum-cost perfect matching.</span></div>
<divclass="line"><aid="l00090"name="l00090"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2884fa43446c0cbc9c7a9b74d41d7483"> 90</a></span><aclass="code hl_enumvalue"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2884fa43446c0cbc9c7a9b74d41d7483">INFEASIBLE</a>, <spanclass="comment">// The given problem admits no perfect matching.</span></div>
<divclass="line"><aid="l00091"name="l00091"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba63e6c2750d99f3c548e6a08bb6822fe2"> 91</a></span><aclass="code hl_enumvalue"href="classoperations__research_1_1_simple_linear_sum_assignment.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba63e6c2750d99f3c548e6a08bb6822fe2">POSSIBLE_OVERFLOW</a>, <spanclass="comment">// Some cost magnitude is too large.</span></div>
<divclass="line"><aid="l00095"name="l00095"></a><spanclass="lineno"> 95</span><spanclass="comment">// Returns the cost of an assignment with minimal cost.</span></div>
<divclass="line"><aid="l00096"name="l00096"></a><spanclass="lineno"> 96</span><spanclass="comment">// This is 0 if the last Solve() didn't return OPTIMAL.</span></div>
<divclass="line"><aid="l00099"name="l00099"></a><spanclass="lineno"> 99</span><spanclass="comment">// Returns the right node assigned to the given left node in the</span></div>
<divclass="line"><aid="l00100"name="l00100"></a><spanclass="lineno"> 100</span><spanclass="comment">// last solution computed by Solve(). This works only if Solve()</span></div>
<divclass="line"><aid="l00101"name="l00101"></a><spanclass="lineno"> 101</span><spanclass="comment">// returned OPTIMAL.</span></div>
<divclass="line"><aid="l00103"name="l00103"></a><spanclass="lineno"> 103</span><spanclass="comment">// Note: It is possible that there is more than one optimal</span></div>
<divclass="line"><aid="l00104"name="l00104"></a><spanclass="lineno"> 104</span><spanclass="comment">// solution. The algorithm is deterministic so it will always return</span></div>
<divclass="line"><aid="l00105"name="l00105"></a><spanclass="lineno"> 105</span><spanclass="comment">// the same solution for a given problem. There is no such guarantee</span></div>
<divclass="line"><aid="l00106"name="l00106"></a><spanclass="lineno"> 106</span><spanclass="comment">// from one code version to the next, but the code does not change</span></div>
<divclass="line"><aid="l00112"name="l00112"></a><spanclass="lineno"> 112</span><spanclass="comment">// Returns the cost of the arc used for "left_node"'s assignment.</span></div>
<divclass="line"><aid="l00113"name="l00113"></a><spanclass="lineno"> 113</span><spanclass="comment">// This works only if Solve() returned OPTIMAL.</span></div>
<divclass="ttc"id="anamespaceoperations__research_html"><divclass="ttname"><ahref="namespaceoperations__research.html">operations_research</a></div><divclass="ttdoc">Collection of objects used to extend the Constraint Solver library.</div><divclass="ttdef"><b>Definition:</b><ahref="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>