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"
55 static Domain Interval(int64_t included_min, int64_t included_max);
78 int64_t
Value()
const;
131 bool Merge(absl::string_view other_name,
const Domain& other_domain,
132 bool other_temporary);
150 Variable(absl::string_view name_,
const Domain& domain_,
bool temporary_);
189 int64_t
Value()
const;
198 int64_t
ValueAt(
int pos)
const;
221 bool strong_propag,
bool sym,
bool redundant)
282 std::vector<Annotation> args);
314 Bounds(int64_t min_value_, int64_t max_value_)
329 absl::string_view
name, std::vector<Bounds>
bounds,
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_; }
379 return search_annotations_;
381 const std::vector<SolutionOutputSpecs>&
output()
const {
return output_; }
385 return float_objective_variables_;
388 return float_objective_coefficients_;
394 float_objective_variables_.push_back(var);
395 float_objective_coefficients_.push_back(coeff);
398 float_objective_offset_ = offset;
404 const std::string&
name()
const {
return name_; }
407 const std::string 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_;
422 std::vector<SolutionOutputSpecs> output_;
430 : model_(model), logger_(logger) {}
432 return constraints_per_variables_[var].size();
440 std::map<std::string, std::vector<Constraint*>> constraints_per_type_;
441 absl::flat_hash_map<const Variable*, std::vector<Constraint*>>
442 constraints_per_variables_;
Model(absl::string_view name)
int NumVariableOccurrences(Variable *var)
ModelStatistics(const Model &model, SolverLogger *logger)
void PrintStatistics() const
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
void AddFloatingPointObjectiveTerm(Variable *var, double coeff)
const std::vector< Variable * > & float_objective_variables() const
Model(absl::string_view name)
const std::vector< Constraint * > & constraints() const
void SetObjective(Variable *obj)
void SetFloatingPointObjectiveOffset(double offset)
const std::vector< SolutionOutputSpecs > & output() const
const std::vector< Variable * > & variables() const
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
void Satisfy(std::vector< Annotation > search_annotations)
const std::string & name() const
const std::vector< Annotation > & search_annotations() const
Variable * objective() const
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)
std::vector< int64_t > values
static Annotation String(absl::string_view str)
static Annotation FunctionCall(absl::string_view id)
void AppendAllVariables(std::vector< Variable * > *vars) const
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
std::vector< int64_t > values
bool IsFunctionCallWithIdentifier(absl::string_view identifier) const
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
std::string DebugString() const
std::vector< Variable * > variables
static Argument FloatList(std::vector< double > floats)
static Argument FloatValue(double value)
std::vector< Domain > domains
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
bool Contains(int64_t value) const
static Argument DomainList(std::vector< Domain > domains)
static Argument VarRefArray(std::vector< Variable * > vars)
std::vector< int64_t > values
bool is_symmetric_breaking
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)
std::vector< Argument > arguments
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
static Domain FloatValue(double value)
bool IntersectWithInterval(int64_t interval_min, int64_t interval_max)
bool IntersectWithDomain(const Domain &domain)
bool SetEmptyFloatDomain()
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
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
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
std::string DebugString() const
Bounds(int64_t min_value_, int64_t max_value_)
std::vector< Variable * > flat_variables
static SolutionOutputSpecs MultiDimensionalArray(absl::string_view name, std::vector< Bounds > bounds, std::vector< Variable * > flat_variables, bool display_as_boolean)
std::string DebugString() const
static SolutionOutputSpecs VoidOutput()
static SolutionOutputSpecs SingleVariable(absl::string_view name, Variable *variable, bool display_as_boolean)
std::vector< Bounds > bounds
bool Merge(absl::string_view other_name, const Domain &other_domain, bool other_temporary)
std::string DebugString() const