Google OR-Tools: ortools/flatzinc/model.h Source File
14#ifndef ORTOOLS_FLATZINC_MODEL_H_
15#define ORTOOLS_FLATZINC_MODEL_H_
23#include "absl/container/flat_hash_map.h"
24#include "absl/strings/string_view.h"
25#include "absl/types/span.h"
29namespace fz {
55 static Domain Interval(int64_t included_min, int64_t included_max);
69 bool empty() const;
72 int64_t Min() const;
75 int64_t Max() const;
78 int64_t Value() const;
84 bool Contains(int64_t value) const;
85 bool OverlapsIntList(const std::vector<int64_t>& vec) const;
120struct Variable {
131 bool Merge(absl::string_view other_name, const Domain& other_domain,
150 Variable(absl::string_view name_, const Domain& domain_, bool temporary_);
189 int64_t Value() const;
196 bool Contains(int64_t value) const;
198 int64_t ValueAt(int pos) const;
208 int Size() const;
220 Constraint(absl::string_view t, std::vector<Argument> args,
348 : name_(name), objective_(nullptr), maximize_(true) {}
356 bool defined, bool set_is_fixed = false);
360 void AddConstraint(absl::string_view id, std::vector<Argument> arguments,
361 bool is_domain, bool symmetry, bool redundant);
362 void AddConstraint(absl::string_view id, std::vector<Argument> arguments);
376 const std::vector<Variable*>& variables() const { return variables_; }
377 const std::vector<Constraint*>& constraints() const { return constraints_; }
381 const std::vector<SolutionOutputSpecs>& output() const { return output_; }
382 bool maximize() const { return maximize_; }
404 const std::string& name() const { return name_; }
410 std::vector<Variable*> variables_;
413 std::vector<Constraint*> constraints_;
417 std::vector<Variable*> float_objective_variables_;
418 std::vector<double> float_objective_coefficients_;
419 double float_objective_offset_ = 0.0;
421 std::vector<Annotation> search_annotations_;
438 const Model& model_;
440 std::map<std::string, std::vector<Constraint*>> constraints_per_type_;
441 absl::flat_hash_map<const Variable*, std::vector<Constraint*>>
Model(absl::string_view name)
Definition model.h:347
int NumVariableOccurrences(Variable *var)
Definition model.h:431
ModelStatistics(const Model &model, SolverLogger *logger)
Definition model.h:429
void PrintStatistics() const
bool maximize() const
Definition model.h:382
void AddConstraint(absl::string_view id, std::vector< Argument > arguments, bool is_domain, bool symmetry, bool redundant)
const std::vector< double > & float_objective_coefficients() const
Definition model.h:387
void AddFloatingPointObjectiveTerm(Variable *var, double coeff)
Definition model.h:393
const std::vector< Variable * > & float_objective_variables() const
Definition model.h:384
Model(absl::string_view name)
Definition model.h:347
const std::vector< Constraint * > & constraints() const
Definition model.h:377
void SetObjective(Variable *obj)
Definition model.h:391
void SetFloatingPointObjectiveOffset(double offset)
Definition model.h:397
const std::vector< SolutionOutputSpecs > & output() const
Definition model.h:381
const std::vector< Variable * > & variables() const
Definition model.h:376
Variable * AddVariable(absl::string_view name, const Domain &domain, bool defined, bool set_is_fixed=false)
Variable * AddFloatConstant(double value)
std::string DebugString() const
void AddOutput(SolutionOutputSpecs output)
void Maximize(Variable *obj, std::vector< Annotation > search_annotations)
double float_objective_offset() const
Definition model.h:390
void Satisfy(std::vector< Annotation > search_annotations)
const std::string & name() const
Definition model.h:404
const std::vector< Annotation > & search_annotations() const
Definition model.h:378
Variable * objective() const
Definition model.h:383
void ClearObjective()
Definition model.h:392
bool IsInconsistent() const
void Minimize(Variable *obj, std::vector< Annotation > search_annotations)
Variable * AddConstant(int64_t value)
void FlattenAnnotations(const Annotation &ann, std::vector< Annotation > *out)
Constraint(absl::string_view t, std::vector< Argument > args, bool strong_propag, bool sym, bool redundant)
Definition model.h:220
std::vector< int64_t > values
Definition model.h:106
static Annotation String(absl::string_view str)
static Annotation FunctionCall(absl::string_view id)
void AppendAllVariables(std::vector< Variable * > *vars) const
Type type
Definition model.h:300
std::string id
Definition model.h:303
static Annotation FunctionCallWithArguments(absl::string_view id, std::vector< Annotation > args)
static Annotation Empty()
static Annotation AnnotationList(std::vector< Annotation > list)
static Annotation IntegerList(const std::vector< int64_t > &values)
static Annotation VarRefArray(std::vector< Variable * > variables)
static Annotation Identifier(absl::string_view id)
std::vector< Variable * > variables
Definition model.h:305
int64_t interval_max
Definition model.h:302
std::vector< int64_t > values
Definition model.h:306
Type
Definition model.h:266
@ INT_LIST
Definition model.h:271
@ ANNOTATION_LIST
Definition model.h:267
@ INT_VALUE
Definition model.h:270
@ VAR_REF_ARRAY
Definition model.h:274
@ INTERVAL
Definition model.h:272
@ FUNCTION_CALL
Definition model.h:269
@ STRING_VALUE
Definition model.h:275
@ VAR_REF
Definition model.h:273
@ IDENTIFIER
Definition model.h:268
bool IsFunctionCallWithIdentifier(absl::string_view identifier) const
Definition model.h:292
static Annotation VarRef(Variable *var)
static Annotation IntegerValue(int64_t value)
static Annotation Interval(int64_t interval_min, int64_t interval_max)
std::vector< Annotation > annotations
Definition model.h:304
int64_t interval_min
Definition model.h:301
std::string string_value
Definition model.h:307
std::string DebugString() const
std::vector< Variable * > variables
Definition model.h:212
static Argument FloatList(std::vector< double > floats)
static Argument FloatValue(double value)
std::vector< Domain > domains
Definition model.h:213
bool HasOneValueAt(int pos) const
Variable * VarAt(int pos) const
std::string DebugString() const
bool IsArrayOfValues() const
static Argument VoidArgument()
static Argument IntegerValue(int64_t value)
int64_t ValueAt(int pos) const
static Argument Interval(int64_t imin, int64_t imax)
static Argument FromDomain(const Domain &domain)
static Argument IntegerList(std::vector< int64_t > values)
static Argument VarRef(Variable *var)
static Argument FloatInterval(double lb, double ub)
std::vector< double > floats
Definition model.h:214
bool Contains(int64_t value) const
static Argument DomainList(std::vector< Domain > domains)
static Argument VarRefArray(std::vector< Variable * > vars)
Type type
Definition model.h:210
Type
Definition model.h:156
@ VAR_REF_ARRAY
Definition model.h:165
@ VAR_REF
Definition model.h:164
@ INT_INTERVAL
Definition model.h:158
@ DOMAIN_LIST
Definition model.h:160
@ FLOAT_LIST
Definition model.h:163
@ INT_LIST
Definition model.h:159
@ FLOAT_INTERVAL
Definition model.h:162
@ VOID_ARGUMENT
Definition model.h:166
@ INT_VALUE
Definition model.h:157
@ FLOAT_VALUE
Definition model.h:161
std::vector< int64_t > values
Definition model.h:211
bool is_symmetric_breaking
Definition model.h:255
std::string DebugString() const
void RemoveArg(int arg_pos)
Constraint(absl::string_view t, std::vector< Argument > args, bool strong_propag, bool sym, bool redundant)
Definition model.h:220
bool active
Definition model.h:252
bool is_redundant
Definition model.h:258
std::vector< Argument > arguments
Definition model.h:241
std::string type
Definition model.h:240
bool strong_propagation
Definition model.h:247
static Domain AllFloats()
bool IntersectWithSingleton(int64_t value)
static Domain IntegerList(std::vector< int64_t > values)
bool OverlapsDomain(const Domain &other) const
static Domain IntegerValue(int64_t value)
std::string DebugString() const
bool is_interval
Definition model.h:107
static Domain FloatValue(double value)
bool IntersectWithInterval(int64_t interval_min, int64_t interval_max)
bool IntersectWithDomain(const Domain &domain)
bool SetEmptyFloatDomain()
bool is_a_set
Definition model.h:110
static Domain EmptyDomain()
bool IntersectWithFloatDomain(const Domain &domain)
bool RemoveValue(int64_t value)
static Domain FloatInterval(double lb, double ub)
std::vector< int64_t > values
Definition model.h:106
bool display_as_boolean
Definition model.h:108
bool is_float
Definition model.h:113
static Domain SetOfBoolean()
static Domain Interval(int64_t included_min, int64_t included_max)
static Domain SetOfAllInt64()
static Domain SetOfInterval(int64_t included_min, int64_t included_max)
bool Contains(int64_t value) const
bool OverlapsIntInterval(int64_t lb, int64_t ub) const
std::vector< double > float_values
Definition model.h:114
static Domain SetOfIntegerList(std::vector< int64_t > values)
static Domain SetOfIntegerValue(int64_t value)
bool IntersectWithListOfIntegers(absl::Span< const int64_t > integers)
bool OverlapsIntList(const std::vector< int64_t > &vec) const
bool is_fixed_set
Definition model.h:111
int64_t max_value
Definition model.h:318
std::string DebugString() const
Bounds(int64_t min_value_, int64_t max_value_)
Definition model.h:314
int64_t min_value
Definition model.h:317
std::string name
Definition model.h:336
bool display_as_boolean
Definition model.h:342
std::vector< Variable * > flat_variables
Definition model.h:338
static SolutionOutputSpecs MultiDimensionalArray(absl::string_view name, std::vector< Bounds > bounds, std::vector< Variable * > flat_variables, bool display_as_boolean)
std::string DebugString() const
Variable * variable
Definition model.h:337
static SolutionOutputSpecs VoidOutput()
static SolutionOutputSpecs SingleVariable(absl::string_view name, Variable *variable, bool display_as_boolean)
std::vector< Bounds > bounds
Definition model.h:341
friend class Model
Definition model.h:148
std::string name
Definition model.h:136
bool active
Definition model.h:145
Domain domain
Definition model.h:137
bool temporary
Definition model.h:141
bool Merge(absl::string_view other_name, const Domain &other_domain, bool other_temporary)
std::string DebugString() const