21#include "absl/container/flat_hash_map.h"
29#ifdef USE_LINEAR_EXPRESSION_COUNTERS
34 ++num_calls_copy_constructor_;
37LinearExpression::LinearExpression(LinearExpression&& other)
38 : terms_(
std::move(other.terms_)),
40 ++num_calls_move_constructor_;
43LinearExpression& LinearExpression::operator=(
const LinearExpression& other) {
44 terms_ = other.terms_;
49ABSL_CONST_INIT
thread_local int
50 LinearExpression::num_calls_default_constructor_ = 0;
51ABSL_CONST_INIT
thread_local int LinearExpression::num_calls_copy_constructor_ =
53ABSL_CONST_INIT
thread_local int LinearExpression::num_calls_move_constructor_ =
55ABSL_CONST_INIT
thread_local int
56 LinearExpression::num_calls_initializer_list_constructor_ = 0;
58void LinearExpression::ResetCounters() {
59 num_calls_default_constructor_ = 0;
60 num_calls_copy_constructor_ = 0;
61 num_calls_move_constructor_ = 0;
62 num_calls_initializer_list_constructor_ = 0;
66double LinearExpression::Evaluate(
68 if (variable_values.
model() !=
nullptr &&
model() !=
nullptr) {
73 for (
const auto& [variable_id,
coef] : terms_.raw_map()) {
74 result +=
coef * variable_values.
raw_map().at(variable_id);
79double LinearExpression::EvaluateWithDefaultZero(
81 if (variable_values.
model() !=
nullptr &&
model() !=
nullptr) {
86 for (
const auto& [variable_id,
coef] : terms_.raw_map()) {
101 const std::vector<Variable> sorted_variables = expression.terms_.SortedKeys();
103 for (
const auto v : sorted_variables) {
109 ostr << expression.terms_.at(v) <<
"*";
110 const std::string&
name = v.name();
112 ostr <<
"[" << v <<
"]";
121 ostr << expression.
offset();
#define CHECK_EQ(val1, val2)
IndexedModel * model() const
const StorageType & raw_map() const
LinearExpression()=default
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
constexpr absl::string_view kObjectsFromOtherIndexedModel
std::ostream & operator<<(std::ostream &ostr, const BoundedLinearExpression &bounded_expression)
Collection of objects used to extend the Constraint Solver library.
LinearExpression expression