77 lines
43 KiB
HTML
77 lines
43 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>OR-Tools</title>
|
|
<meta http-equiv="Content-Type" content="text/html;"/>
|
|
<meta charset="utf-8"/>
|
|
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
|
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="banner-container">
|
|
<div id="banner">
|
|
<span id="sfml">OR-Tools 7.1@</span>
|
|
</div>
|
|
</div>
|
|
<div id="content">
|
|
<!-- Generated by Doxygen 1.8.15 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
<li><a href="globals.html"><span>File Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_a7cc1eeded8f693d0da6c729bc88c45a.html">ortools</a></li><li class="navelem"><a class="el" href="dir_4d3a5a688e4550f3d7725aaa5ab9c27b.html">linear_solver</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">linear_expr.h</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="linear__expr_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright 2010-2018 Google LLC</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">//</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">//</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#ifndef OR_TOOLS_LINEAR_SOLVER_LINEAR_EXPR_H_</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#define OR_TOOLS_LINEAR_SOLVER_LINEAR_EXPR_H_</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">// This file allows you to write natural code (like a mathematical equation) to</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">// model optimization problems with MPSolver. It is syntatic sugar on top of</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment">// the MPSolver API, it provides no additional functionality. Use of these APIs</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment">// makes it much easier to write code that is both simple and big-O optimal for</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">// creating your model, at the cost of some additional constant factor</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">// overhead. If model creation is a bottleneck in your problem, consider using</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment">// the MPSolver API directly instead.</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">//</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment">// This file contains two classes:</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment">// 1. LinearExpr: models offset + sum_{i in S} a_i*x_i for decision var x_i,</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">// 2. LinearRange: models lb <= sum_{i in S} a_i*x_i <= ub,</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">// and it provides various operator overloads to build up "LinearExpr"s and</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment">// then convert them to "LinearRange"s.</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">//</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">// Recommended use (avoids dangerous code):</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment">//</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment">// MPSolver solver = ...;</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment">// const LinearExpr x = solver.MakeVar(...); // Note: implicit conversion</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment">// const LinearExpr y = solver.MakeVar(...);</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment">// const LinearExpr z = solver.MakeVar(...);</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="comment">// const LinearExpr e1 = x + y;</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment">// const LinearExpr e2 = (e1 + 7.0 + z)/3.0;</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment">// const LinearRange r = e1 <= e2;</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="comment">// solver.MakeRowConstraint(r);</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="comment">//</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">// WARNING, AVOID THIS TRAP:</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> <span class="comment">//</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="comment">// MPSolver solver = ...;</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="comment">// MPVariable* x = solver.MakeVar(...);</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">// LinearExpr y = x + 5;</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="comment">//</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="comment">// In evaluating "x+5" above, x is NOT converted to a LinearExpr before the</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="comment">// addition, but rather is treated as a pointer, so x+5 gives a new pointer to</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="comment">// garbage memory.</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="comment">//</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> <span class="comment">// For this reason, when using LinearExpr, it is best practice to:</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="comment">// 1. use double literals instead of ints (e.g. "x + 5.0", not "x + 5"),</span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="comment">// 2. Immediately convert all MPVariable* to LinearExpr on creation, and only</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="comment">// hold references to the "LinearExpr"s.</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> <span class="comment">//</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment">// Likewise, the following code is NOT recommended:</span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment">// MPSolver solver = ...;</span></div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="comment">// MPVariable* x = solver.MakeVar(...);</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="comment">// MPVariable* y = solver.MakeVar(...);</span></div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="comment">// LinearExpr e1 = LinearExpr(x) + y + 5;</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">// While it is correct, it violates the natural assumption that the + operator</span></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="comment">// is associative. Thus you are setting a trap for future modifications of the</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="comment">// code, as any of the following changes would lead to the above failure mode:</span></div><div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="linear__expr_8h.html#a6cb9e1af7c42b3893aa112dd4de84f18"> 66</a></span> <span class="comment">// * LinearExpr e1 = LinearExpr(x) + (y + 5);</span></div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span> <span class="comment">// * LinearExpr e1 = y + 5 + LinearExpr(x);</span></div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span> </div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> <span class="preprocessor">#include "absl/container/flat_hash_map.h"</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span> </div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> <span class="keyword">namespace </span><a class="code" href="namespaceoperations__research.html">operations_research</a> {</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span> </div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span> <span class="comment">// NOTE(user): forward declaration is necessary due to cyclic dependencies,</span></div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> <span class="comment">// MPVariable is defined in linear_solver.h, which depends on LinearExpr.</span></div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span> <span class="keyword">class </span>MPVariable;</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> <span class="comment">// LinearExpr models a quantity that is linear in the decision variables</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> <span class="comment">// (MPVariable) of an optimization problem, i.e.</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span> <span class="comment">//</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span> <span class="comment">// offset + sum_{i in S} a_i*x_i,</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span> <span class="comment">//</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> <span class="comment">// where the a_i and offset are constants and the x_i are MPVariables. You can</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> <span class="comment">// use a LinearExpr "linear_expr" with an MPSolver "solver" to:</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> <span class="comment">// * Set as the objective of your optimization problem, e.g.</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> <span class="comment">//</span></div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="comment">// solver.MutableObjective()->MaximizeLinearExpr(linear_expr);</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">// * Create a constraint in your optimization, e.g.</span></div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span> <span class="comment">//</span></div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span> <span class="comment">// solver.MakeRowConstraint(linear_expr1 <= linear_expr2);</span></div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span> <span class="comment">//</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span> <span class="comment">// * Get the value of the quantity after solving, e.g.</span></div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> <span class="comment">//</span></div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span> <span class="comment">// solver.Solve();</span></div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span> <span class="comment">// linear_expr.SolutionValue();</span></div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> <span class="comment">//</span></div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> <span class="comment">// LinearExpr is allowed to delete variables with coefficient zero from the map,</span></div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <span class="comment">// but is not obligated to do so.</span></div><div class="line"><a name="l00099"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearExpr.html"> 99</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a> {</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html#a3245b8350f417872f1f638ecd22a832f">LinearExpr</a>();</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="comment">// Possible implicit conversions are intentional.</span></div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html#a3245b8350f417872f1f638ecd22a832f">LinearExpr</a>(<span class="keywordtype">double</span> constant); <span class="comment">// NOLINT</span></div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <span class="comment">// Possible implicit conversions are intentional.</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  <span class="comment">// Warning: var is not owned.</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html#a3245b8350f417872f1f638ecd22a832f">LinearExpr</a>(<span class="keyword">const</span> MPVariable* var); <span class="comment">// NOLINT</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> </div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  <span class="comment">// Returns 1-var.</span></div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="comment">// NOTE(user): if var is binary variable, this corresponds to the logical</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="comment">// negation of var.</span></div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <span class="comment">// Passing by value is intentional, see the discussion on binary ops.</span></div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="keyword">static</span> <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a> <a class="code" href="classoperations__research_1_1LinearExpr.html#a46b677de8b46c72ffdff9e16bc2e3745">NotVar</a>(<a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a> var);</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> </div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearExpr.html#a5f501758e469b8718b8410bb87100f51">operator+=</a>(<span class="keyword">const</span> <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& rhs);</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearExpr.html#a359bec8d7b3221d7549c98b0825970d4">operator-=</a>(<span class="keyword">const</span> <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& rhs);</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearExpr.html#a757085e5b10be1bde2ff049a3dbc51c7">operator*=</a>(<span class="keywordtype">double</span> rhs);</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearExpr.html#a14e5dbbcd5618dc42a8799181490742e">operator/=</a>(<span class="keywordtype">double</span> rhs);</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a> <a class="code" href="classoperations__research_1_1LinearExpr.html#a3f94eb1c0b25852c0ff0910b83d363d9">operator-</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> </div><div class="line"><a name="l00120"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearExpr.html#aff2f953067d8d8854273fa973496466e"> 120</a></span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearExpr.html#aff2f953067d8d8854273fa973496466e">offset</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> offset_; }</div><div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearExpr.html#a37d87e22cd7125839fab636219336df8"> 121</a></span>  <span class="keyword">const</span> absl::flat_hash_map<const MPVariable*, double>& <a class="code" href="classoperations__research_1_1LinearExpr.html#a37d87e22cd7125839fab636219336df8">terms</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordflow">return</span> terms_;</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  }</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> </div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="comment">// Call only after calling MPSolver::Solve. Evaluates the value of this</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  <span class="comment">// expression at the solution found.</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearExpr.html#a07afbba5788651a38be83e959bbbc92c">SolutionValue</a>() <span class="keyword">const</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="keyword">private</span>:</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordtype">double</span> offset_;</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  absl::flat_hash_map<const MPVariable*, double> terms_;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> };</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> </div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> <span class="comment">// NOTE(user): in the ops below, the non-"const LinearExpr&" are intentional.</span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span> <span class="comment">// We need to create a new LinearExpr for the result, so we lose nothing by</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> <span class="comment">// passing one argument by value, mutating it, and then returning it. In</span></div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> <span class="comment">// particular, this allows (with move semantics and RVO) an optimized</span></div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> <span class="comment">// evaluation of expressions such as</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> <span class="comment">// a + b + c + d</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">// (see http://en.cppreference.com/w/cpp/language/operators).</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> LinearExpr <a class="code" href="namespaceoperations__research.html#a97f9b83239285f5fdfcac1b8e8b4f162">operator+</a>(LinearExpr lhs, <span class="keyword">const</span> LinearExpr& rhs);</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> LinearExpr <a class="code" href="namespaceoperations__research.html#a515cdaf4f9c4000bb3482a0c450e23c3">operator-</a>(LinearExpr lhs, <span class="keyword">const</span> LinearExpr& rhs);</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span> LinearExpr <a class="code" href="namespaceoperations__research.html#a741104fe08089fe3520676487f7a685d">operator*</a>(LinearExpr lhs, <span class="keywordtype">double</span> rhs);</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span> LinearExpr <a class="code" href="namespaceoperations__research.html#abebdd7f40e90df8dc7d557b6e26da942">operator/</a>(LinearExpr lhs, <span class="keywordtype">double</span> rhs);</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> LinearExpr <a class="code" href="namespaceoperations__research.html#a741104fe08089fe3520676487f7a685d">operator*</a>(<span class="keywordtype">double</span> lhs, LinearExpr rhs);</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> </div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span> <span class="comment">// An expression of the form:</span></div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span> <span class="comment">// lower_bound <= sum_{i in S} a_i*x_i <= upper_bound.</span></div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span> <span class="comment">// The sum is represented as a LinearExpr with offset 0.</span></div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span> <span class="comment">//</span></div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> <span class="comment">// Must be added to model with</span></div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="comment">// MPSolver::AddRowConstraint(const LinearRange& range[, const std::string&</span></div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> <span class="comment">// name]);</span></div><div class="line"><a name="l00154"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearRange.html"> 154</a></span> <span class="keyword">class </span><a class="code" href="classoperations__research_1_1LinearRange.html">LinearRange</a> {</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00156"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearRange.html#a9ce7b1b40dc5135ed9ca27cfedeca64e"> 156</a></span>  <a class="code" href="classoperations__research_1_1LinearRange.html#a9ce7b1b40dc5135ed9ca27cfedeca64e">LinearRange</a>() : lower_bound_(0), upper_bound_(0) {}</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  <span class="comment">// The bounds of the linear range are updated so that they include the offset</span></div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  <span class="comment">// from "linear_expr", i.e., we form the range:</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <span class="comment">// lower_bound - offset <= linear_expr - offset <= upper_bound - offset.</span></div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <a class="code" href="classoperations__research_1_1LinearRange.html#a9ce7b1b40dc5135ed9ca27cfedeca64e">LinearRange</a>(<span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearRange.html#ac9dc29ebeaf4a37d108c0094ca89eb9d">lower_bound</a>, <span class="keyword">const</span> <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearRange.html#aa75204d544c4e4fc91c3ee8a091dd690">linear_expr</a>,</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearRange.html#a527995fddd9d1781d996ff6f50e48041">upper_bound</a>);</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_1LinearRange.html#ac9dc29ebeaf4a37d108c0094ca89eb9d"> 163</a></span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearRange.html#ac9dc29ebeaf4a37d108c0094ca89eb9d">lower_bound</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> lower_bound_; }</div><div class="line"><a name="l00164"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearRange.html#aa75204d544c4e4fc91c3ee8a091dd690"> 164</a></span>  <span class="keyword">const</span> <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a>& <a class="code" href="classoperations__research_1_1LinearRange.html#aa75204d544c4e4fc91c3ee8a091dd690">linear_expr</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> linear_expr_; }</div><div class="line"><a name="l00165"></a><span class="lineno"><a class="line" href="classoperations__research_1_1LinearRange.html#a527995fddd9d1781d996ff6f50e48041"> 165</a></span>  <span class="keywordtype">double</span> <a class="code" href="classoperations__research_1_1LinearRange.html#a527995fddd9d1781d996ff6f50e48041">upper_bound</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> upper_bound_; }</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> </div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  <span class="keywordtype">double</span> lower_bound_;</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  <span class="comment">// invariant: linear_expr_.offset() == 0.</span></div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  <a class="code" href="classoperations__research_1_1LinearExpr.html">LinearExpr</a> linear_expr_;</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  <span class="keywordtype">double</span> upper_bound_;</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span> };</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> LinearRange <a class="code" href="namespaceoperations__research.html#a6d1fa20f9c9faf7027c0b16f97139e80">operator<=</a>(<span class="keyword">const</span> LinearExpr& lhs, <span class="keyword">const</span> LinearExpr& rhs);</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span> LinearRange <a class="code" href="namespaceoperations__research.html#a08146f196bd9c3f492ee108732449ced">operator==</a>(<span class="keyword">const</span> LinearExpr& lhs, <span class="keyword">const</span> LinearExpr& rhs);</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span> LinearRange <a class="code" href="namespaceoperations__research.html#ac4052f92af6a7fbb1d45e17befcb68e0">operator>=</a>(<span class="keyword">const</span> LinearExpr& lhs, <span class="keyword">const</span> LinearExpr& rhs);</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> </div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span> <span class="comment">// TODO(user,user): explore defining more overloads to support:</span></div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span> <span class="comment">// solver.AddRowConstraint(0.0 <= x + y + z <= 1.0);</span></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> } <span class="comment">// namespace operations_research</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"> 183</span> <span class="preprocessor">#endif // OR_TOOLS_LINEAR_SOLVER_LINEAR_EXPR_H_</span></div><div class="ttc" id="classoperations__research_1_1LinearRange_html_aa75204d544c4e4fc91c3ee8a091dd690"><div class="ttname"><a href="classoperations__research_1_1LinearRange.html#aa75204d544c4e4fc91c3ee8a091dd690">operations_research::LinearRange::linear_expr</a></div><div class="ttdeci">const LinearExpr & linear_expr() const</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00164">linear_expr.h:164</a></div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_a97f9b83239285f5fdfcac1b8e8b4f162"><div class="ttname"><a href="namespaceoperations__research.html#a97f9b83239285f5fdfcac1b8e8b4f162">operations_research::operator+</a></div><div class="ttdeci">LinearExpr operator+(LinearExpr lhs, const LinearExpr &rhs)</div><div class="ttdoc">NOTE(user): in the ops below, the non-"const LinearExpr&" are intentional.</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_a741104fe08089fe3520676487f7a685d"><div class="ttname"><a href="namespaceoperations__research.html#a741104fe08089fe3520676487f7a685d">operations_research::operator *</a></div><div class="ttdeci">LinearExpr operator *(LinearExpr lhs, double rhs)</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_a6d1fa20f9c9faf7027c0b16f97139e80"><div class="ttname"><a href="namespaceoperations__research.html#a6d1fa20f9c9faf7027c0b16f97139e80">operations_research::operator<=</a></div><div class="ttdeci">LinearRange operator<=(const LinearExpr &lhs, const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearRange_html"><div class="ttname"><a href="classoperations__research_1_1LinearRange.html">operations_research::LinearRange</a></div><div class="ttdoc">An expression of the form: lower_bound <= sum_{i in S} a_i*x_i <= upper_bound.</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00154">linear_expr.h:154</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a07afbba5788651a38be83e959bbbc92c"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a07afbba5788651a38be83e959bbbc92c">operations_research::LinearExpr::SolutionValue</a></div><div class="ttdeci">double SolutionValue() const</div><div class="ttdoc">Call only after calling MPSolver::Solve.</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_a08146f196bd9c3f492ee108732449ced"><div class="ttname"><a href="namespaceoperations__research.html#a08146f196bd9c3f492ee108732449ced">operations_research::operator==</a></div><div class="ttdeci">LinearRange operator==(const LinearExpr &lhs, const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a757085e5b10be1bde2ff049a3dbc51c7"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a757085e5b10be1bde2ff049a3dbc51c7">operations_research::LinearExpr::operator *=</a></div><div class="ttdeci">LinearExpr & operator *=(double rhs)</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a3245b8350f417872f1f638ecd22a832f"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a3245b8350f417872f1f638ecd22a832f">operations_research::LinearExpr::LinearExpr</a></div><div class="ttdeci">LinearExpr()</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearRange_html_ac9dc29ebeaf4a37d108c0094ca89eb9d"><div class="ttname"><a href="classoperations__research_1_1LinearRange.html#ac9dc29ebeaf4a37d108c0094ca89eb9d">operations_research::LinearRange::lower_bound</a></div><div class="ttdeci">double lower_bound() const</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00163">linear_expr.h:163</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearRange_html_a527995fddd9d1781d996ff6f50e48041"><div class="ttname"><a href="classoperations__research_1_1LinearRange.html#a527995fddd9d1781d996ff6f50e48041">operations_research::LinearRange::upper_bound</a></div><div class="ttdeci">double upper_bound() const</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00165">linear_expr.h:165</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html">operations_research::LinearExpr</a></div><div class="ttdoc">LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization...</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00099">linear_expr.h:99</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearRange_html_a9ce7b1b40dc5135ed9ca27cfedeca64e"><div class="ttname"><a href="classoperations__research_1_1LinearRange.html#a9ce7b1b40dc5135ed9ca27cfedeca64e">operations_research::LinearRange::LinearRange</a></div><div class="ttdeci">LinearRange()</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00156">linear_expr.h:156</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a37d87e22cd7125839fab636219336df8"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a37d87e22cd7125839fab636219336df8">operations_research::LinearExpr::terms</a></div><div class="ttdeci">const absl::flat_hash_map< const MPVariable *, double > & terms() const</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00121">linear_expr.h:121</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a5f501758e469b8718b8410bb87100f51"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a5f501758e469b8718b8410bb87100f51">operations_research::LinearExpr::operator+=</a></div><div class="ttdeci">LinearExpr & operator+=(const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a14e5dbbcd5618dc42a8799181490742e"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a14e5dbbcd5618dc42a8799181490742e">operations_research::LinearExpr::operator/=</a></div><div class="ttdeci">LinearExpr & operator/=(double rhs)</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_ac4052f92af6a7fbb1d45e17befcb68e0"><div class="ttname"><a href="namespaceoperations__research.html#ac4052f92af6a7fbb1d45e17befcb68e0">operations_research::operator>=</a></div><div class="ttdeci">LinearRange operator>=(const LinearExpr &lhs, const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_a515cdaf4f9c4000bb3482a0c450e23c3"><div class="ttname"><a href="namespaceoperations__research.html#a515cdaf4f9c4000bb3482a0c450e23c3">operations_research::operator-</a></div><div class="ttdeci">LinearExpr operator-(LinearExpr lhs, const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdoc">Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...</div><div class="ttdef"><b>Definition:</b> <a href="constraint__solver_8h_source.html#l00093">constraint_solver.h:93</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a46b677de8b46c72ffdff9e16bc2e3745"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a46b677de8b46c72ffdff9e16bc2e3745">operations_research::LinearExpr::NotVar</a></div><div class="ttdeci">static LinearExpr NotVar(LinearExpr var)</div><div class="ttdoc">Returns 1-var.</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_aff2f953067d8d8854273fa973496466e"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#aff2f953067d8d8854273fa973496466e">operations_research::LinearExpr::offset</a></div><div class="ttdeci">double offset() const</div><div class="ttdef"><b>Definition:</b> <a href="linear__expr_8h_source.html#l00120">linear_expr.h:120</a></div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a359bec8d7b3221d7549c98b0825970d4"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a359bec8d7b3221d7549c98b0825970d4">operations_research::LinearExpr::operator-=</a></div><div class="ttdeci">LinearExpr & operator-=(const LinearExpr &rhs)</div></div>
|
|
<div class="ttc" id="classoperations__research_1_1LinearExpr_html_a3f94eb1c0b25852c0ff0910b83d363d9"><div class="ttname"><a href="classoperations__research_1_1LinearExpr.html#a3f94eb1c0b25852c0ff0910b83d363d9">operations_research::LinearExpr::operator-</a></div><div class="ttdeci">LinearExpr operator-() const</div></div>
|
|
<div class="ttc" id="namespaceoperations__research_html_abebdd7f40e90df8dc7d557b6e26da942"><div class="ttname"><a href="namespaceoperations__research.html#abebdd7f40e90df8dc7d557b6e26da942">operations_research::operator/</a></div><div class="ttdeci">LinearExpr operator/(LinearExpr lhs, double rhs)</div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div>
|
|
<div id="footer-container">
|
|
<div id="footer">
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|