Google OR-Tools: ortools/linear_solver/linear_expr.cc Source File
23#include "absl/strings/str_join.h"
24#include "absl/strings/string_view.h"
83 for (const auto& pair : terms_) {
84 solution += pair.first->solution_value() * pair.second;
91void AppendTerm(const double coef, absl::string_view var_name,
92 const bool is_first, std::string* s) {
95 absl::StrAppend(s, var_name);
97 absl::StrAppend(s, "-", var_name);
99 absl::StrAppend(s, coef, "*", var_name);
102 const std::string op = coef < 0 ? "-" : "+";
103 const double abs_coef = std::abs(coef);
105 absl::StrAppend(s, " ", op, " ", var_name);
107 absl::StrAppend(s, " ", op, " ", abs_coef, "*", var_name);
112void AppendOffset(const double offset, const bool is_first, std::string* s) {
114 absl::StrAppend(s, offset);
117 const std::string op = offset < 0 ? "-" : "+";
118 absl::StrAppend(s, " ", op, " ", std::abs(offset));
126 std::vector<const MPVariable*> vars_in_order;
127 for (const auto& var_val_pair : terms_) {
128 vars_in_order.push_back(var_val_pair.first);
130 std::sort(vars_in_order.begin(), vars_in_order.end(),
132 return v->index() < u->index();
136 for (const MPVariable* var : vars_in_order) {
138 DCHECK(!var->name().empty());
139 AppendTerm(terms_.at(var), var->name(), is_first, &result);
178 lower_bound_ -= linear_expr_.offset();
179 upper_bound_ -= linear_expr_.offset();
184 return LinearRange(-std::numeric_limits<double>::infinity(), lhs - rhs, 0);
190 return LinearRange(0, lhs - rhs, std::numeric_limits<double>::infinity());
double SolutionValue() const
Definition linear_expr.cc:81
LinearExpr()
Definition linear_expr.cc:32
LinearExpr operator-() const
Definition linear_expr.cc:72
LinearExpr & operator/=(double rhs)
Definition linear_expr.cc:67
std::string ToString() const
Definition linear_expr.cc:125
LinearExpr & operator+=(const LinearExpr &rhs)
Definition linear_expr.cc:38
static LinearExpr NotVar(LinearExpr var)
Definition linear_expr.cc:75
LinearExpr & operator-=(const LinearExpr &rhs)
Definition linear_expr.cc:46
LinearExpr & operator*=(double rhs)
Definition linear_expr.cc:54
double upper_bound() const
const LinearExpr & linear_expr() const
double lower_bound() const
The class for variables of a Mathematical Programming (MP) model.
LinearRange operator==(const LinearExpr &lhs, const LinearExpr &rhs)
Definition linear_expr.cc:186
LinearExpr operator*(LinearExpr lhs, double rhs)
Definition linear_expr.cc:160
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
LinearExpr operator-(LinearExpr lhs, const LinearExpr &rhs)
Definition linear_expr.cc:156
LinearRange operator<=(const LinearExpr &lhs, const LinearExpr &rhs)
Definition linear_expr.cc:183
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
LinearExpr operator+(LinearExpr lhs, const LinearExpr &rhs)
Definition linear_expr.cc:152
LinearExpr operator/(LinearExpr lhs, double rhs)
Definition linear_expr.cc:164
LinearRange operator>=(const LinearExpr &lhs, const LinearExpr &rhs)
Definition linear_expr.cc:189