C++ Reference

C++ Reference: CP-SAT

operations_research::sat Namespace Reference

Classes

class  BoolVar
 A Boolean variable. More...
 
class  IntVar
 An integer variable. More...
 
class  LinearExpr
 A dedicated container for linear expressions. More...
 
class  DoubleLinearExpr
 A dedicated container for linear expressions with double coefficients. More...
 
class  IntervalVar
 Represents a Interval variable. More...
 
class  Constraint
 A constraint. More...
 
class  CircuitConstraint
 Specialized circuit constraint. More...
 
class  MultipleCircuitConstraint
 Specialized circuit constraint. More...
 
class  TableConstraint
 Specialized assignment constraint. More...
 
class  ReservoirConstraint
 Specialized reservoir constraint. More...
 
class  AutomatonConstraint
 Specialized automaton constraint. More...
 
class  NoOverlap2DConstraint
 Specialized no_overlap2D constraint. More...
 
class  CumulativeConstraint
 Specialized cumulative constraint. More...
 
class  CpModelBuilder
 Wrapper class around the cp_model proto. More...
 
class  Model
 Class that owns everything related to a particular optimization model. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const BoolVar &var)
 
BoolVar Not (BoolVar x)
 A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer. More...
 
std::ostream & operator<< (std::ostream &os, const IntVar &var)
 
std::ostream & operator<< (std::ostream &os, const LinearExpr &e)
 
std::ostream & operator<< (std::ostream &os, const DoubleLinearExpr &e)
 
std::ostream & operator<< (std::ostream &os, const IntervalVar &var)
 
template<typename H >
AbslHashValue (H h, const IntVar &i)
 
template<typename H >
AbslHashValue (H h, const IntervalVar &i)
 
int64_t SolutionIntegerValue (const CpSolverResponse &r, const LinearExpr &expr)
 Evaluates the value of an linear expression in a solver response. More...
 
bool SolutionBooleanValue (const CpSolverResponse &r, BoolVar x)
 Evaluates the value of a Boolean literal in a solver response. More...
 
std::string VarDebugString (const CpModelProto &proto, int index)
 
LinearExpr operator- (LinearExpr expr)
 
LinearExpr operator+ (const LinearExpr &lhs, const LinearExpr &rhs)
 
LinearExpr operator+ (LinearExpr &&lhs, const LinearExpr &rhs)
 
LinearExpr operator+ (const LinearExpr &lhs, LinearExpr &&rhs)
 
LinearExpr operator+ (LinearExpr &&lhs, LinearExpr &&rhs)
 
LinearExpr operator- (const LinearExpr &lhs, const LinearExpr &rhs)
 
LinearExpr operator- (LinearExpr &&lhs, const LinearExpr &rhs)
 
LinearExpr operator- (const LinearExpr &lhs, LinearExpr &&rhs)
 
LinearExpr operator- (LinearExpr &&lhs, LinearExpr &&rhs)
 
LinearExpr operator* (LinearExpr expr, int64_t factor)
 
LinearExpr operator* (int64_t factor, LinearExpr expr)
 
DoubleLinearExpr operator- (DoubleLinearExpr expr)
 
DoubleLinearExpr operator+ (const DoubleLinearExpr &lhs, const DoubleLinearExpr &rhs)
 
DoubleLinearExpr operator+ (DoubleLinearExpr &&lhs, const DoubleLinearExpr &rhs)
 
DoubleLinearExpr operator+ (const DoubleLinearExpr &lhs, DoubleLinearExpr &&rhs)
 
DoubleLinearExpr operator+ (DoubleLinearExpr &&lhs, DoubleLinearExpr &&rhs)
 
DoubleLinearExpr operator+ (DoubleLinearExpr expr, double rhs)
 
DoubleLinearExpr operator+ (double lhs, DoubleLinearExpr expr)
 
DoubleLinearExpr operator- (const DoubleLinearExpr &lhs, const DoubleLinearExpr &rhs)
 
DoubleLinearExpr operator- (DoubleLinearExpr &&lhs, const DoubleLinearExpr &rhs)
 
DoubleLinearExpr operator- (const DoubleLinearExpr &lhs, DoubleLinearExpr &&rhs)
 
DoubleLinearExpr operator- (DoubleLinearExpr &&lhs, DoubleLinearExpr &&rhs)
 
DoubleLinearExpr operator- (DoubleLinearExpr epxr, double rhs)
 
DoubleLinearExpr operator- (double lhs, DoubleLinearExpr expr)
 
DoubleLinearExpr operator* (DoubleLinearExpr expr, double factor)
 
DoubleLinearExpr operator* (double factor, DoubleLinearExpr expr)
 
std::string CpSatSolverVersion ()
 Returns a string that describes the version of the solver. More...
 
CpSolverResponse Solve (const CpModelProto &model_proto)
 Solves the given CpModelProto and returns an instance of CpSolverResponse. More...
 
CpSolverResponse SolveWithParameters (const CpModelProto &model_proto, const SatParameters &params)
 Solves the given CpModelProto with the given parameters. More...
 
std::string CpModelStats (const CpModelProto &model)
 Returns a string with some statistics on the given CpModelProto. More...
 
std::string CpSolverResponseStats (const CpSolverResponse &response, bool has_objective=true)
 Returns a string with some statistics on the solver response. More...
 
CpSolverResponse SolveCpModel (const CpModelProto &model_proto, Model *model)
 Solves the given CpModelProto. More...
 
CpSolverResponse SolveWithParameters (const CpModelProto &model_proto, const std::string &params)
 Solves the given CpModelProto with the given sat parameters as string in JSon format, and returns an instance of CpSolverResponse. More...
 
std::function< void(Model *)> NewFeasibleSolutionObserver (const std::function< void(const CpSolverResponse &response)> &observer)
 Creates a solution observer with the model with model.Add(NewFeasibleSolutionObserver([](response){...}));. More...
 
std::function< SatParameters(Model *)> NewSatParameters (const std::string &params)
 Creates parameters for the solver, which you can add to the model with. More...
 
std::function< SatParameters(Model *)> NewSatParameters (const SatParameters &parameters)
 

Function Documentation

◆ AbslHashValue() [1/2]

H operations_research::sat::AbslHashValue ( h,
const IntervalVar i 
)

Definition at line 515 of file cp_model.h.

◆ AbslHashValue() [2/2]

H operations_research::sat::AbslHashValue ( h,
const IntVar i 
)

Definition at line 510 of file cp_model.h.

◆ CpModelStats()

std::string operations_research::sat::CpModelStats ( const CpModelProto &  model)

Returns a string with some statistics on the given CpModelProto.

◆ CpSatSolverVersion()

std::string operations_research::sat::CpSatSolverVersion ( )

Returns a string that describes the version of the solver.

◆ CpSolverResponseStats()

std::string operations_research::sat::CpSolverResponseStats ( const CpSolverResponse &  response,
bool  has_objective = true 
)

Returns a string with some statistics on the solver response.

If the second argument is false, we will just display NA for the objective value instead of zero. It is not really needed but it makes things a bit clearer to see that there is no objective.

◆ NewFeasibleSolutionObserver()

std::function<void(Model*)> operations_research::sat::NewFeasibleSolutionObserver ( const std::function< void(const CpSolverResponse &response)> &  observer)

Creates a solution observer with the model with model.Add(NewFeasibleSolutionObserver([](response){...}));.

The given function will be called on each improving feasible solution found during the search. For a non-optimization problem, if the option to find all solution was set, then this will be called on each new solution.

WARNING: Except when enumerate_all_solution() is true, one shouldn't rely on this to get a set of "diverse" solutions since any future change to the solver might completely kill any diversity in the set of solutions observed.

Valid usage of this includes implementing features like:

  • Enumerating all solution via enumerate_all_solution(). If only n solutions are needed, this can also be used to abort when this number is reached.
  • Aborting early if a good enough solution is found.
  • Displaying log progress.
  • etc...

◆ NewSatParameters() [1/2]

std::function<SatParameters(Model*)> operations_research::sat::NewSatParameters ( const SatParameters &  parameters)

◆ NewSatParameters() [2/2]

std::function<SatParameters(Model*)> operations_research::sat::NewSatParameters ( const std::string &  params)

Creates parameters for the solver, which you can add to the model with.

model->Add(NewSatParameters(parameters_as_string_or_proto))
std::function< SatParameters(Model *)> NewSatParameters(const std::string &params)
Creates parameters for the solver, which you can add to the model with.

before calling SolveCpModel().

◆ Not()

BoolVar operations_research::sat::Not ( BoolVar  x)

A convenient wrapper so we can write Not(x) instead of x.Not() which is sometimes clearer.

◆ operator*() [1/4]

DoubleLinearExpr operations_research::sat::operator* ( double  factor,
DoubleLinearExpr  expr 
)
inline

Definition at line 1295 of file cp_model.h.

◆ operator*() [2/4]

DoubleLinearExpr operations_research::sat::operator* ( DoubleLinearExpr  expr,
double  factor 
)
inline

Definition at line 1290 of file cp_model.h.

◆ operator*() [3/4]

LinearExpr operations_research::sat::operator* ( int64_t  factor,
LinearExpr  expr 
)
inline

Definition at line 1209 of file cp_model.h.

◆ operator*() [4/4]

LinearExpr operations_research::sat::operator* ( LinearExpr  expr,
int64_t  factor 
)
inline

Definition at line 1205 of file cp_model.h.

◆ operator+() [1/10]

DoubleLinearExpr operations_research::sat::operator+ ( const DoubleLinearExpr lhs,
const DoubleLinearExpr rhs 
)
inline

Definition at line 1221 of file cp_model.h.

◆ operator+() [2/10]

DoubleLinearExpr operations_research::sat::operator+ ( const DoubleLinearExpr lhs,
DoubleLinearExpr &&  rhs 
)
inline

Definition at line 1232 of file cp_model.h.

◆ operator+() [3/10]

LinearExpr operations_research::sat::operator+ ( const LinearExpr lhs,
const LinearExpr rhs 
)
inline

Definition at line 1163 of file cp_model.h.

◆ operator+() [4/10]

LinearExpr operations_research::sat::operator+ ( const LinearExpr lhs,
LinearExpr &&  rhs 
)
inline

Definition at line 1172 of file cp_model.h.

◆ operator+() [5/10]

DoubleLinearExpr operations_research::sat::operator+ ( double  lhs,
DoubleLinearExpr  expr 
)
inline

Definition at line 1252 of file cp_model.h.

◆ operator+() [6/10]

DoubleLinearExpr operations_research::sat::operator+ ( DoubleLinearExpr &&  lhs,
const DoubleLinearExpr rhs 
)
inline

Definition at line 1227 of file cp_model.h.

◆ operator+() [7/10]

DoubleLinearExpr operations_research::sat::operator+ ( DoubleLinearExpr &&  lhs,
DoubleLinearExpr &&  rhs 
)
inline

Definition at line 1237 of file cp_model.h.

◆ operator+() [8/10]

DoubleLinearExpr operations_research::sat::operator+ ( DoubleLinearExpr  expr,
double  rhs 
)
inline

Definition at line 1248 of file cp_model.h.

◆ operator+() [9/10]

LinearExpr operations_research::sat::operator+ ( LinearExpr &&  lhs,
const LinearExpr rhs 
)
inline

Definition at line 1168 of file cp_model.h.

◆ operator+() [10/10]

LinearExpr operations_research::sat::operator+ ( LinearExpr &&  lhs,
LinearExpr &&  rhs 
)
inline

Definition at line 1176 of file cp_model.h.

◆ operator-() [1/12]

DoubleLinearExpr operations_research::sat::operator- ( const DoubleLinearExpr lhs,
const DoubleLinearExpr rhs 
)
inline

Definition at line 1257 of file cp_model.h.

◆ operator-() [2/12]

DoubleLinearExpr operations_research::sat::operator- ( const DoubleLinearExpr lhs,
DoubleLinearExpr &&  rhs 
)
inline

Definition at line 1268 of file cp_model.h.

◆ operator-() [3/12]

LinearExpr operations_research::sat::operator- ( const LinearExpr lhs,
const LinearExpr rhs 
)
inline

Definition at line 1186 of file cp_model.h.

◆ operator-() [4/12]

LinearExpr operations_research::sat::operator- ( const LinearExpr lhs,
LinearExpr &&  rhs 
)
inline

Definition at line 1195 of file cp_model.h.

◆ operator-() [5/12]

DoubleLinearExpr operations_research::sat::operator- ( double  lhs,
DoubleLinearExpr  expr 
)
inline

Definition at line 1284 of file cp_model.h.

◆ operator-() [6/12]

DoubleLinearExpr operations_research::sat::operator- ( DoubleLinearExpr &&  lhs,
const DoubleLinearExpr rhs 
)
inline

Definition at line 1263 of file cp_model.h.

◆ operator-() [7/12]

DoubleLinearExpr operations_research::sat::operator- ( DoubleLinearExpr &&  lhs,
DoubleLinearExpr &&  rhs 
)
inline

Definition at line 1274 of file cp_model.h.

◆ operator-() [8/12]

DoubleLinearExpr operations_research::sat::operator- ( DoubleLinearExpr  epxr,
double  rhs 
)
inline

Definition at line 1280 of file cp_model.h.

◆ operator-() [9/12]

DoubleLinearExpr operations_research::sat::operator- ( DoubleLinearExpr  expr)
inline

Definition at line 1216 of file cp_model.h.

◆ operator-() [10/12]

LinearExpr operations_research::sat::operator- ( LinearExpr &&  lhs,
const LinearExpr rhs 
)
inline

Definition at line 1191 of file cp_model.h.

◆ operator-() [11/12]

LinearExpr operations_research::sat::operator- ( LinearExpr &&  lhs,
LinearExpr &&  rhs 
)
inline

Definition at line 1200 of file cp_model.h.

◆ operator-() [12/12]

LinearExpr operations_research::sat::operator- ( LinearExpr  expr)
inline

Definition at line 1161 of file cp_model.h.

◆ operator<<() [1/5]

std::ostream& operations_research::sat::operator<< ( std::ostream &  os,
const BoolVar var 
)

◆ operator<<() [2/5]

std::ostream& operations_research::sat::operator<< ( std::ostream &  os,
const DoubleLinearExpr e 
)

◆ operator<<() [3/5]

std::ostream& operations_research::sat::operator<< ( std::ostream &  os,
const IntervalVar var 
)

◆ operator<<() [4/5]

std::ostream& operations_research::sat::operator<< ( std::ostream &  os,
const IntVar var 
)

◆ operator<<() [5/5]

std::ostream& operations_research::sat::operator<< ( std::ostream &  os,
const LinearExpr e 
)

◆ SolutionBooleanValue()

bool operations_research::sat::SolutionBooleanValue ( const CpSolverResponse &  r,
BoolVar  x 
)

Evaluates the value of a Boolean literal in a solver response.

◆ SolutionIntegerValue()

int64_t operations_research::sat::SolutionIntegerValue ( const CpSolverResponse &  r,
const LinearExpr expr 
)

Evaluates the value of an linear expression in a solver response.

◆ Solve()

CpSolverResponse operations_research::sat::Solve ( const CpModelProto &  model_proto)

Solves the given CpModelProto and returns an instance of CpSolverResponse.

◆ SolveCpModel()

CpSolverResponse operations_research::sat::SolveCpModel ( const CpModelProto &  model_proto,
Model model 
)

Solves the given CpModelProto.

This advanced API accept a Model* which allows to access more adavanced features by configuring some classes in the Model before solve.

For instance:

  • model->Add(NewSatParameters(parameters_as_string_or_proto));
  • model->GetOrCreate<TimeLimit>()->RegisterExternalBooleanAsLimit(&stop);
  • model->Add(NewFeasibleSolutionObserver(observer));

◆ SolveWithParameters() [1/2]

CpSolverResponse operations_research::sat::SolveWithParameters ( const CpModelProto &  model_proto,
const SatParameters &  params 
)

Solves the given CpModelProto with the given parameters.

◆ SolveWithParameters() [2/2]

CpSolverResponse operations_research::sat::SolveWithParameters ( const CpModelProto &  model_proto,
const std::string &  params 
)

Solves the given CpModelProto with the given sat parameters as string in JSon format, and returns an instance of CpSolverResponse.

◆ VarDebugString()

std::string operations_research::sat::VarDebugString ( const CpModelProto &  proto,
int  index 
)