Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
model_builder_helper.h
Go to the documentation of this file.
1// Copyright 2010-2025 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
14#ifndef OR_TOOLS_LINEAR_SOLVER_WRAPPERS_MODEL_BUILDER_HELPER_H_
15#define OR_TOOLS_LINEAR_SOLVER_WRAPPERS_MODEL_BUILDER_HELPER_H_
16
17#include <algorithm>
18#include <atomic>
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <optional>
23#include <string>
24#include <utility>
25#include <vector>
26
27#include "absl/container/btree_map.h"
28#include "absl/container/fixed_array.h"
32
33namespace operations_research {
34namespace mb {
35
36#if !defined(SWIG)
37// Base implementation of linear expressions.
38
40class FlatExpr;
41class ExprVisitor;
42class LinearExpr;
45class Variable;
46
47// A linear expression that containing variables and constants.
48class LinearExpr : public std::enable_shared_from_this<LinearExpr> {
49 public:
50 virtual ~LinearExpr() = default;
51 virtual void Visit(ExprVisitor& /*lin*/, double /*c*/) = 0;
52 virtual std::string ToString() const = 0;
53 virtual std::string DebugString() const = 0;
54
55 static std::shared_ptr<LinearExpr> Term(std::shared_ptr<LinearExpr> expr,
56 double coeff);
57 static std::shared_ptr<LinearExpr> Affine(std::shared_ptr<LinearExpr> expr,
58 double coeff, double constant);
59 static std::shared_ptr<LinearExpr> AffineCst(double value, double coeff,
60 double constant);
61 static std::shared_ptr<LinearExpr> Constant(double value);
62
63 std::shared_ptr<LinearExpr> Add(std::shared_ptr<LinearExpr> expr);
64 virtual std::shared_ptr<LinearExpr> AddFloat(double cst);
65 std::shared_ptr<LinearExpr> Sub(std::shared_ptr<LinearExpr> expr);
66 virtual std::shared_ptr<LinearExpr> SubFloat(double cst);
67 virtual std::shared_ptr<LinearExpr> RSubFloat(double cst);
68 virtual std::shared_ptr<LinearExpr> MulFloat(double cst);
69 virtual std::shared_ptr<LinearExpr> Neg();
70
71 std::shared_ptr<BoundedLinearExpression> Eq(std::shared_ptr<LinearExpr> rhs);
72 std::shared_ptr<BoundedLinearExpression> EqCst(double rhs);
73 std::shared_ptr<BoundedLinearExpression> Ge(std::shared_ptr<LinearExpr> rhs);
74 std::shared_ptr<BoundedLinearExpression> GeCst(double rhs);
75 std::shared_ptr<BoundedLinearExpression> Le(std::shared_ptr<LinearExpr> rhs);
76 std::shared_ptr<BoundedLinearExpression> LeCst(double rhs);
77};
78
79// Compare the indices of variables.
81 bool operator()(std::shared_ptr<Variable> lhs,
82 std::shared_ptr<Variable> rhs) const;
83};
84
85// A visitor class to parse a floating point linear expression.
87 public:
88 virtual ~ExprVisitor() = default;
89 void AddToProcess(std::shared_ptr<LinearExpr> expr, double coeff);
90 void AddConstant(double constant);
91 virtual void AddVarCoeff(std::shared_ptr<Variable> var, double coeff) = 0;
92 void Clear();
93
94 protected:
95 std::vector<std::pair<std::shared_ptr<LinearExpr>, double>> to_process_;
96 double offset_ = 0;
97};
98
99class ExprFlattener : public ExprVisitor {
100 public:
101 ~ExprFlattener() override = default;
102 void AddVarCoeff(std::shared_ptr<Variable> var, double coeff) override;
103 double Flatten(std::vector<std::shared_ptr<Variable>>* vars,
104 std::vector<double>* coeffs);
105
106 private:
107 absl::btree_map<std::shared_ptr<Variable>, double, VariableComparator>
108 canonical_terms_;
109};
110
112 public:
113 explicit ExprEvaluator(ModelSolverHelper* helper) : helper_(helper) {}
114 ~ExprEvaluator() override = default;
115 void AddVarCoeff(std::shared_ptr<Variable> var, double coeff) override;
116 double Evaluate();
117
118 private:
119 ModelSolverHelper* helper_;
120};
121
122// A flat linear expression sum(vars[i] * coeffs[i]) + offset
123class FlatExpr : public LinearExpr {
124 public:
125 explicit FlatExpr(std::shared_ptr<LinearExpr> expr);
126 // Flatten pos - neg.
127 FlatExpr(std::shared_ptr<LinearExpr> pos, std::shared_ptr<LinearExpr> neg);
128 FlatExpr(const std::vector<std::shared_ptr<Variable>>&,
129 const std::vector<double>&, double);
130 explicit FlatExpr(double offset);
131 const std::vector<std::shared_ptr<Variable>>& vars() const { return vars_; }
132 std::vector<int> VarIndices() const;
133 const std::vector<double>& coeffs() const { return coeffs_; }
134 double offset() const { return offset_; }
135
136 void Visit(ExprVisitor& lin, double c) override;
137 std::string ToString() const override;
138 std::string DebugString() const override;
139
140 private:
141 std::vector<std::shared_ptr<Variable>> vars_;
142 std::vector<double> coeffs_;
143 double offset_;
144};
145
146// A class to hold a sum of linear expressions, and optional integer and
147// double offsets.
148class SumArray : public LinearExpr {
149 public:
150 explicit SumArray(std::vector<std::shared_ptr<LinearExpr>> exprs,
151 double offset);
152 ~SumArray() override = default;
153
154 void Visit(ExprVisitor& lin, double c) override;
155
156 std::string ToString() const override;
157 std::string DebugString() const override;
158 std::shared_ptr<LinearExpr> AddInPlace(std::shared_ptr<LinearExpr> expr);
159 std::shared_ptr<LinearExpr> AddFloatInPlace(double cst);
160 int num_exprs() const;
161 double offset() const;
162
163 private:
164 std::vector<std::shared_ptr<LinearExpr>> exprs_;
165 double offset_;
166};
167
168// A class to hold a weighted sum of floating point linear expressions.
170 public:
171 WeightedSumArray(const std::vector<std::shared_ptr<LinearExpr>>& exprs,
172 const std::vector<double>& coeffs, double offset);
173 ~WeightedSumArray() override = default;
174
175 void Visit(ExprVisitor& lin, double c) override;
176 std::string ToString() const override;
177 std::string DebugString() const override;
178
179 private:
180 const absl::FixedArray<std::shared_ptr<LinearExpr>, 2> exprs_;
181 const absl::FixedArray<double, 2> coeffs_;
182 double offset_;
183};
184
185// A class to hold linear_expr * a = b.
186class AffineExpr : public LinearExpr {
187 public:
188 AffineExpr(std::shared_ptr<LinearExpr> expr, double coeff, double offset);
189 ~AffineExpr() override = default;
190
191 void Visit(ExprVisitor& lin, double c) override;
192
193 std::string ToString() const override;
194 std::string DebugString() const override;
195
196 std::shared_ptr<LinearExpr> expression() const { return expr_; }
197 double coefficient() const { return coeff_; }
198 double offset() const { return offset_; }
199
200 std::shared_ptr<LinearExpr> AddFloat(double cst) override;
201 std::shared_ptr<LinearExpr> SubFloat(double cst) override;
202 std::shared_ptr<LinearExpr> RSubFloat(double cst) override;
203 std::shared_ptr<LinearExpr> MulFloat(double cst) override;
204 std::shared_ptr<LinearExpr> Neg() override;
205
206 private:
207 std::shared_ptr<LinearExpr> expr_;
208 double coeff_;
209 double offset_;
210};
211
212// A class to hold a fixed value.
213class FixedValue : public LinearExpr {
214 public:
215 explicit FixedValue(double value) : value_(value) {}
216 ~FixedValue() override = default;
217
218 void Visit(ExprVisitor& lin, double c) override;
219
220 std::string ToString() const override;
221 std::string DebugString() const override;
222
223 private:
224 double value_;
225};
226
227// A class to hold a variable index.
228class Variable : public LinearExpr {
229 public:
231 Variable(ModelBuilderHelper* helper, double lb, double ub, bool is_integral);
232 Variable(ModelBuilderHelper* helper, double lb, double ub, bool is_integral,
233 const std::string& name);
234 Variable(ModelBuilderHelper* helper, int64_t lb, int64_t ub,
235 bool is_integral);
236 Variable(ModelBuilderHelper* helper, int64_t lb, int64_t ub, bool is_integral,
237 const std::string& name);
238 ~Variable() override {}
239
240 ModelBuilderHelper* helper() const { return helper_; }
241 int index() const { return index_; }
242 std::string name() const;
243 void SetName(const std::string& name);
244 double lower_bounds() const;
245 void SetLowerBound(double lb);
246 double upper_bound() const;
247 void SetUpperBound(double ub);
248 bool is_integral() const;
249 void SetIsIntegral(bool is_integral);
250 double objective_coefficient() const;
251 void SetObjectiveCoefficient(double coeff);
252
253 void Visit(ExprVisitor& lin, double c) override {
254 std::shared_ptr<Variable> var =
255 std::static_pointer_cast<Variable>(shared_from_this());
256 lin.AddVarCoeff(var, c);
257 }
258
259 std::string ToString() const override;
260
261 std::string DebugString() const override;
262
263 bool operator<(const Variable& other) const { return index_ < other.index_; }
264
265 protected:
268};
269
270template <typename H>
271H AbslHashValue(H h, std::shared_ptr<Variable> i) {
272 return H::combine(std::move(h), i->index());
273}
274
275// A class to hold a linear expression with bounds.
277 public:
278 BoundedLinearExpression(std::shared_ptr<LinearExpr> expr, double lower_bound,
279 double upper_bound);
280 BoundedLinearExpression(std::shared_ptr<LinearExpr> pos,
281 std::shared_ptr<LinearExpr> neg, double lower_bound,
282 double upper_bound);
283 BoundedLinearExpression(std::shared_ptr<LinearExpr> expr, int64_t lower_bound,
284 int64_t upper_bound);
285 BoundedLinearExpression(std::shared_ptr<LinearExpr> pos,
286 std::shared_ptr<LinearExpr> neg, int64_t lower_bound,
287 int64_t upper_bound);
288
290
291 double lower_bound() const;
292 double upper_bound() const;
293 const std::vector<std::shared_ptr<Variable>>& vars() const;
294 const std::vector<double>& coeffs() const;
295 std::string ToString() const;
296 std::string DebugString() const;
297 bool CastToBool(bool* result) const;
298
299 private:
300 std::vector<std::shared_ptr<Variable>> vars_;
301 std::vector<double> coeffs_;
302 double lower_bound_;
303 double upper_bound_;
304};
305
306#endif // !defined(SWIG)
307
308// The arguments of the functions defined below must follow these rules
309// to be wrapped by SWIG correctly:
310// 1) Their types must include the full operations_research::
311// namespace.
312// 2) Their names must correspond to the ones declared in the .swig
313// file (see the java/ and csharp/ subdirectories).
314
315// Helper for importing/exporting models and model protobufs.
316//
317// Wrapping global function is brittle with SWIG. It is much easier to
318// wrap static class methods.
319//
320// Note: all these methods rely on c++ code that uses absl::Status or
321// absl::StatusOr. Unfortunately, these are inconsistently wrapped in non C++
322// languages. As a consequence, we need to provide an API that does not involve
323// absl::Status or absl::StatusOr.
325 public:
326 void OverwriteModel(const ModelBuilderHelper& other_helper);
328 options = MPModelExportOptions());
330 options = MPModelExportOptions());
331 bool WriteToMpsFile(const std::string& filename,
334 bool ReadModelFromProtoFile(const std::string& filename);
335 bool WriteModelToProtoFile(const std::string& filename);
336
337 bool ImportFromMpsString(const std::string& mps_string);
338 bool ImportFromMpsFile(const std::string& mps_file);
339 bool ImportFromLpString(const std::string& lp_string);
340 bool ImportFromLpFile(const std::string& lp_file);
341
342 const MPModelProto& model() const;
344
345 // Direct low level model building API.
346 int AddVar();
347 void SetVarLowerBound(int var_index, double lb);
348 void SetVarUpperBound(int var_index, double ub);
349 void SetVarIntegrality(int var_index, bool is_integer);
350 void SetVarObjectiveCoefficient(int var_index, double coeff);
351 void SetVarName(int var_index, const std::string& name);
352
353 double VarLowerBound(int var_index) const;
354 double VarUpperBound(int var_index) const;
355 bool VarIsIntegral(int var_index) const;
356 double VarObjectiveCoefficient(int var_index) const;
357 std::string VarName(int var_index) const;
358
359 double ConstraintLowerBound(int ct_index) const;
360 double ConstraintUpperBound(int ct_index) const;
362 std::string ConstraintName(int ct_index) const;
363 std::vector<double> ConstraintCoefficients(int ct_index) const;
364 std::vector<int> ConstraintVarIndices(int ct_index) const;
365 void AddConstraintTerm(int ct_index, int var_index, double coeff);
366 void ClearConstraintTerms(int ct_index);
367 void SafeAddConstraintTerm(int ct_index, int var_index, double coeff);
368 void SetConstraintCoefficient(int ct_index, int var_index, double coeff);
369 void SetConstraintLowerBound(int ct_index, double lb);
370 void SetConstraintName(int ct_index, const std::string& name);
371 void SetConstraintUpperBound(int ct_index, double ub);
372
373 bool EnforcedIndicatorValue(int ct_index) const;
374 bool IsEnforcedConstraint(int ct_index) const;
375 double EnforcedConstraintLowerBound(int ct_index) const;
376 double EnforcedConstraintUpperBound(int ct_index) const;
378 int EnforcedIndicatorVariableIndex(int ct_index) const;
379 std::string EnforcedConstraintName(int ct_index) const;
380 std::vector<double> EnforcedConstraintCoefficients(int ct_index) const;
381 std::vector<int> EnforcedConstraintVarIndices(int ct_index) const;
382 void AddEnforcedConstraintTerm(int ct_index, int var_index, double coeff);
383 void ClearEnforcedConstraintTerms(int ct_index);
384 void SafeAddEnforcedConstraintTerm(int ct_index, int var_index, double coeff);
385 void SetEnforcedConstraintCoefficient(int ct_index, int var_index,
386 double coeff);
387 void SetEnforcedConstraintLowerBound(int ct_index, double lb);
388 void SetEnforcedConstraintName(int ct_index, const std::string& name);
389 void SetEnforcedConstraintUpperBound(int ct_index, double ub);
390 void SetEnforcedIndicatorValue(int ct_index, bool positive);
391 void SetEnforcedIndicatorVariableIndex(int ct_index, int var_index);
392
393 int num_constraints() const;
394 int num_variables() const;
395
396 std::string name() const;
397 void SetName(const std::string& name);
398
399 void ClearObjective();
400 bool maximize() const;
401 void SetMaximize(bool maximize);
402 double ObjectiveOffset() const;
403 void SetObjectiveOffset(double offset);
404
405 void ClearHints();
406 void AddHint(int var_index, double var_value);
407
408 private:
409 MPModelProto model_;
410};
411
412// Simple director class for C#.
414 public:
415 virtual ~MbLogCallback() {}
416 virtual void NewMessage(const std::string& message) = 0;
417};
418
434
435// Class used to solve a request. This class is not meant to be exposed to the
436// public. Its responsibility is to bridge the MPModelProto in the non-C++
437// languages with the C++ Solve method.
438//
439// It contains 2 helper objects: a logger, and an atomic bool to interrupt
440// search.
442 public:
443 explicit ModelSolverHelper(const std::string& solver_name);
444 bool SolverIsSupported() const;
445 void Solve(const ModelBuilderHelper& model);
446
447 // Only used by the CVXPY interface. Does not store the response internally.
448 std::optional<MPSolutionResponse> SolveRequest(const MPModelRequest& request);
449
450 // Returns true if the interrupt signal was correctly sent, that is if the
451 // underlying solver supports it.
452 bool InterruptSolve();
453
454 void SetLogCallback(std::function<void(const std::string&)> log_callback);
456 void ClearLogCallback();
457
458 bool has_response() const;
459 bool has_solution() const;
460 const MPSolutionResponse& response() const;
461 SolveStatus status() const;
462
463 // If not defined, or no solution, they will silently return 0.
464 double objective_value() const;
465 double best_objective_bound() const;
466 double variable_value(int var_index) const;
467#if !defined(SWIG)
468 double expression_value(std::shared_ptr<LinearExpr> expr) const;
469#endif // !defined(SWIG)
470 double reduced_cost(int var_index) const;
471 double dual_value(int ct_index) const;
472 double activity(int ct_index);
473
474 std::string status_string() const;
475 double wall_time() const;
476 double user_time() const;
477
478 // Solve parameters.
479 void SetTimeLimitInSeconds(double limit);
481 const std::string& solver_specific_parameters);
482 void EnableOutput(bool enabled);
483
484 // TODO(user): set parameters.
485
486 private:
487 SolveInterrupter interrupter_;
488 std::atomic<bool> interrupt_solve_ = false;
489 std::function<void(const std::string&)> log_callback_;
490 std::optional<MPSolutionResponse> response_;
491 std::optional<MPModelRequest::SolverType> solver_type_;
492 std::optional<double> time_limit_in_second_;
493 std::string solver_specific_parameters_;
494 std::optional<const MPModelProto*> model_of_last_solve_;
495 std::vector<double> activities_;
496 bool solver_output_ = false;
497 mutable ExprEvaluator evaluator_;
498};
499
500} // namespace mb
501} // namespace operations_research
502
503#endif // OR_TOOLS_LINEAR_SOLVER_WRAPPERS_MODEL_BUILDER_HELPER_H_
AffineExpr(std::shared_ptr< LinearExpr > expr, double coeff, double offset)
std::string DebugString() const override
std::shared_ptr< LinearExpr > Neg() override
std::shared_ptr< LinearExpr > SubFloat(double cst) override
std::shared_ptr< LinearExpr > RSubFloat(double cst) override
std::shared_ptr< LinearExpr > AddFloat(double cst) override
void Visit(ExprVisitor &lin, double c) override
std::shared_ptr< LinearExpr > MulFloat(double cst) override
std::shared_ptr< LinearExpr > expression() const
A class to hold a linear expression with bounds.
BoundedLinearExpression(std::shared_ptr< LinearExpr > expr, double lower_bound, double upper_bound)
const std::vector< std::shared_ptr< Variable > > & vars() const
void AddVarCoeff(std::shared_ptr< Variable > var, double coeff) override
double Flatten(std::vector< std::shared_ptr< Variable > > *vars, std::vector< double > *coeffs)
void AddVarCoeff(std::shared_ptr< Variable > var, double coeff) override
A visitor class to parse a floating point linear expression.
std::vector< std::pair< std::shared_ptr< LinearExpr >, double > > to_process_
void AddToProcess(std::shared_ptr< LinearExpr > expr, double coeff)
Expression visitors.
virtual void AddVarCoeff(std::shared_ptr< Variable > var, double coeff)=0
void Visit(ExprVisitor &lin, double c) override
std::string DebugString() const override
A flat linear expression sum(vars[i] * coeffs[i]) + offset.
std::string ToString() const override
void Visit(ExprVisitor &lin, double c) override
const std::vector< std::shared_ptr< Variable > > & vars() const
FlatExpr(std::shared_ptr< LinearExpr > expr)
const std::vector< double > & coeffs() const
std::vector< int > VarIndices() const
std::string DebugString() const override
A linear expression that containing variables and constants.
virtual std::string ToString() const =0
std::shared_ptr< LinearExpr > Add(std::shared_ptr< LinearExpr > expr)
std::shared_ptr< BoundedLinearExpression > Le(std::shared_ptr< LinearExpr > rhs)
virtual std::string DebugString() const =0
std::shared_ptr< LinearExpr > Sub(std::shared_ptr< LinearExpr > expr)
std::shared_ptr< BoundedLinearExpression > EqCst(double rhs)
std::shared_ptr< BoundedLinearExpression > LeCst(double rhs)
static std::shared_ptr< LinearExpr > Affine(std::shared_ptr< LinearExpr > expr, double coeff, double constant)
static std::shared_ptr< LinearExpr > Constant(double value)
static std::shared_ptr< LinearExpr > AffineCst(double value, double coeff, double constant)
std::shared_ptr< BoundedLinearExpression > Ge(std::shared_ptr< LinearExpr > rhs)
virtual std::shared_ptr< LinearExpr > Neg()
virtual std::shared_ptr< LinearExpr > RSubFloat(double cst)
virtual std::shared_ptr< LinearExpr > AddFloat(double cst)
virtual void Visit(ExprVisitor &, double)=0
virtual std::shared_ptr< LinearExpr > MulFloat(double cst)
static std::shared_ptr< LinearExpr > Term(std::shared_ptr< LinearExpr > expr, double coeff)
Expressions.
std::shared_ptr< BoundedLinearExpression > GeCst(double rhs)
std::shared_ptr< BoundedLinearExpression > Eq(std::shared_ptr< LinearExpr > rhs)
virtual std::shared_ptr< LinearExpr > SubFloat(double cst)
virtual void NewMessage(const std::string &message)=0
void SetEnforcedConstraintLowerBound(int ct_index, double lb)
std::vector< int > ConstraintVarIndices(int ct_index) const
std::vector< double > EnforcedConstraintCoefficients(int ct_index) const
void SetVarIntegrality(int var_index, bool is_integer)
void SetEnforcedIndicatorValue(int ct_index, bool positive)
void SafeAddEnforcedConstraintTerm(int ct_index, int var_index, double coeff)
void SetEnforcedConstraintName(int ct_index, const std::string &name)
void SetVarName(int var_index, const std::string &name)
void AddConstraintTerm(int ct_index, int var_index, double coeff)
bool WriteToMpsFile(const std::string &filename, const operations_research::MPModelExportOptions &options=MPModelExportOptions())
bool ReadModelFromProtoFile(const std::string &filename)
std::string ExportToMpsString(const operations_research::MPModelExportOptions &options=MPModelExportOptions())
void SetEnforcedConstraintCoefficient(int ct_index, int var_index, double coeff)
std::string EnforcedConstraintName(int ct_index) const
void AddEnforcedConstraintTerm(int ct_index, int var_index, double coeff)
void OverwriteModel(const ModelBuilderHelper &other_helper)
ModelBuilderHelper.
bool WriteModelToProtoFile(const std::string &filename)
void SetEnforcedIndicatorVariableIndex(int ct_index, int var_index)
void SetConstraintLowerBound(int ct_index, double lb)
bool ImportFromMpsFile(const std::string &mps_file)
void SetEnforcedConstraintUpperBound(int ct_index, double ub)
void AddHint(int var_index, double var_value)
int AddVar()
Direct low level model building API.
void SetVarObjectiveCoefficient(int var_index, double coeff)
void SetConstraintName(int ct_index, const std::string &name)
bool ImportFromMpsString(const std::string &mps_string)
bool ImportFromLpString(const std::string &lp_string)
bool ImportFromLpFile(const std::string &lp_file)
void SetConstraintUpperBound(int ct_index, double ub)
std::vector< double > ConstraintCoefficients(int ct_index) const
void SafeAddConstraintTerm(int ct_index, int var_index, double coeff)
void SetConstraintCoefficient(int ct_index, int var_index, double coeff)
std::string ExportToLpString(const operations_research::MPModelExportOptions &options=MPModelExportOptions())
std::vector< int > EnforcedConstraintVarIndices(int ct_index) const
void Solve(const ModelBuilderHelper &model)
void SetSolverSpecificParameters(const std::string &solver_specific_parameters)
ModelSolverHelper(const std::string &solver_name)
std::optional< MPSolutionResponse > SolveRequest(const MPModelRequest &request)
Only used by the CVXPY interface. Does not store the response internally.
double objective_value() const
If not defined, or no solution, they will silently return 0.
const MPSolutionResponse & response() const
void SetLogCallbackFromDirectorClass(MbLogCallback *log_callback)
double expression_value(std::shared_ptr< LinearExpr > expr) const
void SetTimeLimitInSeconds(double limit)
Solve parameters.
void SetLogCallback(std::function< void(const std::string &)> log_callback)
void Visit(ExprVisitor &lin, double c) override
std::shared_ptr< LinearExpr > AddInPlace(std::shared_ptr< LinearExpr > expr)
std::string ToString() const override
std::shared_ptr< LinearExpr > AddFloatInPlace(double cst)
std::string DebugString() const override
SumArray(std::vector< std::shared_ptr< LinearExpr > > exprs, double offset)
A class to hold a variable index.
bool operator<(const Variable &other) const
Variable(ModelBuilderHelper *helper, int index)
void Visit(ExprVisitor &lin, double c) override
void SetName(const std::string &name)
ModelBuilderHelper * helper() const
std::string DebugString() const override
std::string ToString() const override
WeightedSumArray(const std::vector< std::shared_ptr< LinearExpr > > &exprs, const std::vector< double > &coeffs, double offset)
void Visit(ExprVisitor &lin, double c) override
H AbslHashValue(H h, std::shared_ptr< Variable > i)
In SWIG mode, we don't want anything besides these top-level includes.
bool operator()(std::shared_ptr< Variable > lhs, std::shared_ptr< Variable > rhs) const