Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_model_utils.cc File Reference
#include "ortools/sat/cp_model_utils.h"
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/stl_util.h"
#include "ortools/sat/cp_model.pb.h"
#include "ortools/sat/sat_base.h"
#include "ortools/util/saturated_arithmetic.h"
#include "ortools/util/sorted_interval_list.h"

Go to the source code of this file.

Namespaces

namespace  operations_research
 In SWIG mode, we don't want anything besides these top-level includes.
namespace  operations_research::sat

Macros

#define APPLY_TO_SINGULAR_FIELD(ct_name, field_name)
#define APPLY_TO_REPEATED_FIELD(ct_name, field_name)

Functions

 ABSL_FLAG (bool, cp_model_dump_models, false, "DEBUG ONLY. When set to true, SolveCpModel() will dump its model " "protos (original model, presolved model, mapping model) in text " "format to 'FLAGS_cp_model_dump_prefix'{model|presolved_model|" "mapping_model}.pb.txt.")
 ABSL_FLAG (std::string, cp_model_dump_prefix, "/tmp/", "Prefix filename for all dumped files")
 ABSL_FLAG (bool, cp_model_dump_submodels, false, "DEBUG ONLY. When set to true, solve will dump all " "lns or objective_shaving submodels proto in text format to " "'FLAGS_cp_model_dump_prefix'xxx.pb.txt.")
int64_t operations_research::sat::LinearExpressionGcd (const LinearExpressionProto &expr, int64_t gcd)
void operations_research::sat::DivideLinearExpression (int64_t divisor, LinearExpressionProto *expr)
void operations_research::sat::SetToNegatedLinearExpression (const LinearExpressionProto &input_expr, LinearExpressionProto *output_negated_expr)
 Fills the target as negated ref.
IndexReferences operations_research::sat::GetReferencesUsedByConstraint (const ConstraintProto &ct)
void operations_research::sat::GetReferencesUsedByConstraint (const ConstraintProto &ct, std::vector< int > *variables, std::vector< int > *literals)
void operations_research::sat::ApplyToAllLiteralIndices (const std::function< void(int *)> &f, ConstraintProto *ct)
void operations_research::sat::ApplyToAllVariableIndices (const std::function< void(int *)> &f, ConstraintProto *ct)
void operations_research::sat::ApplyToAllIntervalIndices (const std::function< void(int *)> &f, ConstraintProto *ct)
absl::string_view operations_research::sat::ConstraintCaseName (ConstraintProto::ConstraintCase constraint_case)
std::vector< int > operations_research::sat::UsedVariables (const ConstraintProto &ct)
std::vector< int > operations_research::sat::UsedIntervals (const ConstraintProto &ct)
 Returns the sorted list of interval used by a constraint.
int64_t operations_research::sat::ComputeInnerObjective (const CpObjectiveProto &objective, absl::Span< const int64_t > solution)
bool operations_research::sat::ExpressionContainsSingleRef (const LinearExpressionProto &expr)
 Returns true if a linear expression can be reduced to a single ref.
bool operations_research::sat::ExpressionIsAffine (const LinearExpressionProto &expr)
 Checks if the expression is affine or constant.
int operations_research::sat::GetSingleRefFromExpression (const LinearExpressionProto &expr)
void operations_research::sat::AddLinearExpressionToLinearConstraint (const LinearExpressionProto &expr, int64_t coefficient, LinearConstraintProto *linear)
void operations_research::sat::AddWeightedLiteralToLinearConstraint (int lit, int64_t coeff, LinearConstraintProto *linear, int64_t *offset)
bool operations_research::sat::SafeAddLinearExpressionToLinearConstraint (const LinearExpressionProto &expr, int64_t coefficient, LinearConstraintProto *linear)
 Same method, but returns if the addition was possible without overflowing.
bool operations_research::sat::LinearExpressionProtosAreEqual (const LinearExpressionProto &a, const LinearExpressionProto &b, int64_t b_scaling=1)
 Returns true iff a == b * b_scaling.
uint64_t operations_research::sat::FingerprintExpression (const LinearExpressionProto &lin, uint64_t seed)
 Returns a stable fingerprint of a linear expression.
uint64_t operations_research::sat::FingerprintModel (const CpModelProto &model, uint64_t seed=kDefaultFingerprintSeed)
 Returns a stable fingerprint of a model.
void operations_research::sat::SetupTextFormatPrinter (google::protobuf::TextFormat::Printer *printer)
bool operations_research::sat::ConvertCpModelProtoToCnf (const CpModelProto &cp_model, std::string *out)
int operations_research::sat::CombineSeed (int base_seed, int64_t delta)
 We assume delta >= 0 and we only use the low bit of delta.

Macro Definition Documentation

◆ APPLY_TO_REPEATED_FIELD

#define APPLY_TO_REPEATED_FIELD ( ct_name,
field_name )
Value:
{ \
for (int& r : *ct->mutable_##ct_name()->mutable_##field_name()) f(&r); \
}

Definition at line 246 of file cp_model_utils.cc.

◆ APPLY_TO_SINGULAR_FIELD

#define APPLY_TO_SINGULAR_FIELD ( ct_name,
field_name )
Value:
{ \
int temp = ct->mutable_##ct_name()->field_name(); \
f(&temp); \
ct->mutable_##ct_name()->set_##field_name(temp); \
}

Definition at line 239 of file cp_model_utils.cc.

Function Documentation

◆ ABSL_FLAG() [1/3]

ABSL_FLAG ( bool ,
cp_model_dump_models ,
false ,
"DEBUG ONLY. When set to true,
SolveCpModel() will dump its model " "protos(original model, presolved model, mapping model) in text " "format to 'FLAGS_cp_model_dump_prefix'{model|presolved_model|" "mapping_model}.pb.txt."  )

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

◆ ABSL_FLAG() [2/3]

ABSL_FLAG ( bool ,
cp_model_dump_submodels ,
false ,
"DEBUG ONLY. When set to true,
solve will dump all " "lns or objective_shaving submodels proto in text format to " " 'FLAGS_cp_model_dump_prefix 'xxx.pb.txt."  )

◆ ABSL_FLAG() [3/3]

ABSL_FLAG ( std::string ,
cp_model_dump_prefix ,
"/tmp/" ,
"Prefix filename for all dumped files"  )