14#ifndef OR_TOOLS_FLATZINC_MODEL_H_
15#define OR_TOOLS_FLATZINC_MODEL_H_
23#include "absl/container/flat_hash_map.h"
24#include "absl/strings/string_view.h"
25#include "absl/types/span.h"
56 static Domain Interval(int64_t included_min, int64_t included_max);
79 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;
278 std::vector<Annotation> args);
310 Bounds(int64_t min_value_, int64_t max_value_)
325 absl::string_view
name, std::vector<Bounds>
bounds,
344 : name_(
name), objective_(nullptr), maximize_(true) {}
356 void AddConstraint(absl::string_view
id, std::vector<Argument> arguments,
358 void AddConstraint(absl::string_view
id, std::vector<Argument> arguments);
372 const std::vector<Variable*>&
variables()
const {
return variables_; }
373 const std::vector<Constraint*>&
constraints()
const {
return constraints_; }
375 return search_annotations_;
382 const std::vector<SolutionOutputSpecs>&
output()
const {
return output_; }
391 return float_objective_variables_;
394 return float_objective_coefficients_;
400 float_objective_variables_.push_back(
var);
401 float_objective_coefficients_.push_back(coeff);
404 float_objective_offset_ = offset;
410 const std::string&
name()
const {
return name_; }
413 const std::string name_;
416 std::vector<Variable*> variables_;
419 std::vector<Constraint*> constraints_;
423 std::vector<Variable*> float_objective_variables_;
424 std::vector<double> float_objective_coefficients_;
425 double float_objective_offset_ = 0.0;
427 std::vector<Annotation> search_annotations_;
428 std::vector<SolutionOutputSpecs> output_;
436 : model_(
model), logger_(logger) {}
438 return constraints_per_variables_[
var].size();
446 std::map<std::string, std::vector<Constraint*>> constraints_per_type_;
447 absl::flat_hash_map<const Variable*, std::vector<Constraint*>>
448 constraints_per_variables_;
int NumVariableOccurrences(Variable *var)
ModelStatistics(const Model &model, SolverLogger *logger)
void PrintStatistics() const
--— Model statistics --—
void AddConstraint(absl::string_view id, std::vector< Argument > arguments, bool is_domain)
Creates and add a constraint to the model.
const std::vector< double > & float_objective_coefficients() const
void AddFloatingPointObjectiveTerm(Variable *var, double coeff)
const std::vector< Variable * > & float_objective_variables() const
util::MutableVectorIteration< SolutionOutputSpecs > mutable_output()
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
--— Accessors and mutators --—
Variable * AddFloatConstant(double value)
std::string DebugString() const
Services.
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
Variable * AddVariable(absl::string_view name, const Domain &domain, bool defined)
--— Builder methods --—
bool IsInconsistent() const
util::MutableVectorIteration< Annotation > mutable_search_annotations()
void Minimize(Variable *obj, std::vector< Annotation > search_annotations)
Variable * AddConstant(int64_t value)
void FlattenAnnotations(const Annotation &ann, std::vector< Annotation > *out)
Flatten Search annotations.
In SWIG mode, we don't want anything besides these top-level includes.
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()
--— Annotation --—
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)
int Size() const
Returns the number of object in the argument.
static Argument FloatValue(double value)
bool IsVariable() const
Returns true if the argument is a variable.
std::vector< Domain > domains
bool HasOneValueAt(int pos) const
Returns true is the pos-th argument is fixed.
Variable * VarAt(int pos) const
std::string DebugString() const
bool IsArrayOfValues() const
static Argument VoidArgument()
static Argument IntegerValue(int64_t value)
--— Argument --—
int64_t ValueAt(int pos) const
Returns the value of the pos-th element.
static Argument Interval(int64_t imin, int64_t imax)
static Argument FromDomain(const Domain &domain)
int64_t Value() const
Returns the value of the argument. Does DCHECK(HasOneValue()).
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
std::string DebugString() const
--— Constraint --—
Constraint(absl::string_view t, std::vector< Argument > args, bool strong_propag)
void MarkAsInactive()
Helpers to be used during presolve.
void RemoveArg(int arg_pos)
Helper method to remove one argument.
void SetAsFalse()
Set as a False constraint.
bool presolve_propagation_done
Indicates if presolve has finished propagating this constraint.
std::vector< Argument > arguments
static Domain AllFloats()
bool IntersectWithSingleton(int64_t value)
static Domain IntegerList(std::vector< int64_t > values)
The values will be sorted and duplicate values will be removed.
bool OverlapsDomain(const Domain &other) const
static Domain IntegerValue(int64_t value)
int64_t Max() const
Returns the max of the domain.
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()
Sets the empty float domain. Returns true.
bool is_a_set
Indicates if the domain was created as a set domain.
static Domain EmptyDomain()
bool IntersectWithFloatDomain(const Domain &domain)
bool RemoveValue(int64_t value)
static Domain FloatInterval(double lb, double ub)
int64_t Min() const
Returns the min of the domain.
std::vector< int64_t > values
These should never be modified from outside the class.
bool is_float
Float domain.
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
Various inclusion tests on a domain.
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)
int64_t Value() const
Returns the value of the domain. HasOneValue() must return true.
bool IntersectWithListOfIntegers(absl::Span< const int64_t > integers)
bool IsAllInt64() const
Returns true if the domain is [kint64min..kint64max].
bool OverlapsIntList(const std::vector< int64_t > &vec) const
std::string DebugString() const
--— SolutionOutputSpecs --—
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()
Empty output.
static SolutionOutputSpecs SingleVariable(absl::string_view name, Variable *variable, bool display_as_boolean)
Will output: name = <variable value>.
std::vector< Bounds > bounds
bool Merge(absl::string_view other_name, const Domain &other_domain, bool other_temporary)
std::string DebugString() const
Allow iterating over a vector<T> as a mutable vector<T*>.