Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
VariableHelper.cs
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15{
16using System;
17using System.Collections.Generic;
18
19// Patch the MPVariable class to support the natural language API.
20public partial class Variable
21{
22 public static LinearExpr operator +(Variable a, double v)
23 {
24 return new VarWrapper(a) + v;
25 }
26
27 public static LinearExpr operator +(double v, Variable a)
28 {
29 return a + v;
30 }
31
33 {
34 return new VarWrapper(a) + b;
35 }
36
38 {
39 return new VarWrapper(a) + new VarWrapper(b);
40 }
41
43 {
44 return a + new VarWrapper(b);
45 }
46
47 public static LinearExpr operator -(Variable a, double v)
48 {
49 return new VarWrapper(a) - v;
50 }
51
52 public static LinearExpr operator -(double v, Variable a)
53 {
54 return v - new VarWrapper(a);
55 }
56
58 {
59 return new VarWrapper(a) - b;
60 }
61
63 {
64 return a - new VarWrapper(b);
65 }
66
68 {
69 return new VarWrapper(a) - new VarWrapper(b);
70 }
71
73 {
74 return -new VarWrapper(a);
75 }
76
77 public static LinearExpr operator *(Variable a, double v)
78 {
79 return new VarWrapper(a) * v;
80 }
81
82 public static LinearExpr operator /(Variable a, double v)
83 {
84 return new VarWrapper(a) / v;
85 }
86
87 public static LinearExpr operator *(double v, Variable a)
88 {
89 return v * new VarWrapper(a);
90 }
91
92 public static RangeConstraint operator ==(Variable a, double v)
93 {
94 return new VarWrapper(a) == v;
95 }
96
97 public static RangeConstraint operator ==(double v, Variable a)
98 {
99 return v == new VarWrapper(a);
100 }
101
102 public static RangeConstraint operator !=(Variable a, double v)
103 {
104 return new VarWrapper(a) != v;
105 }
106
107 public static RangeConstraint operator !=(double v, Variable a)
108 {
109 return new VarWrapper(a) != v;
110 }
111
113 {
114 return new VarWrapper(a) == b;
115 }
116
118 {
119 return a == new VarWrapper(b);
120 }
121
123 {
124 return new VarEquality(a, b, true);
125 }
126
128 {
129 return new VarWrapper(a) != b;
130 }
131
133 {
134 return a != new VarWrapper(b);
135 }
136
138 {
139 return new VarEquality(a, b, false);
140 }
141
142 public static RangeConstraint operator <=(Variable a, double v)
143 {
144 return new VarWrapper(a) <= v;
145 }
146
147 public static RangeConstraint operator >=(Variable a, double v)
148 {
149 return new VarWrapper(a) >= v;
150 }
151
152 public static RangeConstraint operator <=(double v, Variable a)
153 {
154 return new VarWrapper(a) >= v;
155 }
156
157 public static RangeConstraint operator >=(double v, Variable a)
158 {
159 return new VarWrapper(a) <= v;
160 }
161
163 {
164 return new VarWrapper(a) <= b;
165 }
166
168 {
169 return new VarWrapper(a) >= b;
170 }
171
173 {
174 return new VarWrapper(a) <= new VarWrapper(b);
175 }
176
178 {
179 return new VarWrapper(a) >= new VarWrapper(b);
180 }
181
183 {
184 return a <= new VarWrapper(b);
185 }
186
188 {
189 return a >= new VarWrapper(b);
190 }
191}
192
193// TODO(user): Try to move this code back to the .i with @define macros.
194public partial class MPVariableVector : IDisposable,
195 System.Collections.IEnumerable
196#if !SWIG_DOTNET_1
197 ,
198 System.Collections.Generic.IList<Variable>
199#endif
200{
201 // cast from C# MPVariable array
202 public static implicit operator MPVariableVector(Variable[] inVal)
203 {
204 var outVal = new MPVariableVector();
205 foreach (Variable element in inVal)
206 {
207 outVal.Add(element);
208 }
209 return outVal;
210 }
211
212 // cast to C# MPVariable array
213 public static implicit operator Variable[](MPVariableVector inVal)
214 {
215 var outVal = new Variable[inVal.Count];
216 inVal.CopyTo(outVal);
217 return outVal;
218 }
219}
220
221} // namespace Google.OrTools.LinearSolver
Patch the MPVariable class to support the natural language API.
static RangeConstraint operator<=(Variable a, double v)
static RangeConstraint operator==(Variable a, double v)
static LinearExpr operator/(Variable a, double v)
static RangeConstraint operator!=(Variable a, double v)
static RangeConstraint operator>=(Variable a, double v)
static LinearExpr operator+(Variable a, double v)
static LinearExpr operator-(Variable a, double v)
static LinearExpr operator*(Variable a, double v)