C++ Reference

C++ Reference: CP-SAT

Detailed Description

An integer variable.

This class wraps an IntegerVariableProto. This can only be constructed via CpModelBuilder.NewIntVar().

Definition at line 142 of file cp_model.h.

Public Member Functions

 IntVar ()=default
 A default constructed IntVar can be used to mean not defined yet. More...
 
 IntVar (const BoolVar &var)
 Cast BoolVar -> IntVar. More...
 
BoolVar ToBoolVar () const
 Cast IntVar -> BoolVar. More...
 
IntVar WithName (const std::string &name)
 Sets the name of the variable. More...
 
std::string Name () const
 Returns the name of the variable (or the empty string if not set). More...
 
bool operator== (const IntVar &other) const
 
bool operator!= (const IntVar &other) const
 
::operations_research::Domain Domain () const
 
std::string DebugString () const
 
int index () const
 Returns the index of the variable in the model. This will be non-negative. More...
 

Constructor & Destructor Documentation

◆ IntVar() [1/2]

IntVar ( )
default

A default constructed IntVar can be used to mean not defined yet.

However, it shouldn't be passed to any of the functions in this file. Doing so will crash in debug mode and will result in an invalid model in opt mode.

◆ IntVar() [2/2]

IntVar ( const BoolVar var)
explicit

Cast BoolVar -> IntVar.

The IntVar will take the value 1 (when the bool is true) and 0 otherwise.

Warning: If you construct an IntVar from a negated BoolVar, this might create a new variable in the model. Otherwise this just point to the same underlying variable.

Member Function Documentation

◆ DebugString()

std::string DebugString ( ) const

◆ Domain()

◆ index()

int index ( ) const
inline

Returns the index of the variable in the model. This will be non-negative.

Definition at line 187 of file cp_model.h.

◆ Name()

std::string Name ( ) const

Returns the name of the variable (or the empty string if not set).

◆ operator!=()

bool operator!= ( const IntVar other) const
inline

Definition at line 175 of file cp_model.h.

◆ operator==()

bool operator== ( const IntVar other) const
inline

Definition at line 171 of file cp_model.h.

◆ ToBoolVar()

BoolVar ToBoolVar ( ) const

Cast IntVar -> BoolVar.

Warning: The domain of the var must be within {0,1}. If not, we crash in debug mode, and in opt mode you will get an invalid model if you use this BoolVar anywhere since it will not have a valid domain.

◆ WithName()

IntVar WithName ( const std::string &  name)

Sets the name of the variable.


The documentation for this class was generated from the following file: