Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::sat::IntVar Class Reference

#include <cp_model.h>

Public Member Functions

 IntVar ()=default
 
 IntVar (const BoolVar &var)
 
BoolVar ToBoolVar () const
 
IntVar WithName (absl::string_view name)
 Sets the name of the variable.
 
std::string Name () const
 Returns the name of the variable (or the empty string if not set).
 
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.
 

Friends

class BoolVar
 
class CpModelBuilder
 
class CumulativeConstraint
 
class DoubleLinearExpr
 
class LinearExpr
 
class IntervalVar
 
class ReservoirConstraint
 
int64_t SolutionIntegerValue (const CpSolverResponse &r, const LinearExpr &expr)
 Evaluates the value of an linear expression in a solver response.
 

Detailed Description

An integer variable.

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

Definition at line 145 of file cp_model.h.

Constructor & Destructor Documentation

◆ IntVar() [1/2]

operations_research::sat::IntVar::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]

operations_research::sat::IntVar::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.

Definition at line 99 of file cp_model.cc.

Member Function Documentation

◆ DebugString()

std::string operations_research::sat::IntVar::DebugString ( ) const

Definition at line 136 of file cp_model.cc.

◆ Domain()

operations_research::Domain operations_research::sat::IntVar::Domain ( ) const

Returns the domain of the variable.

Note
we keep the fully qualified return type as compilation fails with gcc otherwise.

Definition at line 131 of file cp_model.cc.

◆ index()

int operations_research::sat::IntVar::index ( ) const
inline

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

Definition at line 192 of file cp_model.h.

◆ Name()

std::string operations_research::sat::IntVar::Name ( ) const

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

Definition at line 126 of file cp_model.cc.

◆ operator!=()

bool operations_research::sat::IntVar::operator!= ( const IntVar & other) const
inline

Definition at line 180 of file cp_model.h.

◆ operator==()

bool operations_research::sat::IntVar::operator== ( const IntVar & other) const
inline

Definition at line 176 of file cp_model.h.

◆ ToBoolVar()

BoolVar operations_research::sat::IntVar::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.

Definition at line 109 of file cp_model.cc.

◆ WithName()

IntVar operations_research::sat::IntVar::WithName ( absl::string_view name)

Sets the name of the variable.

Definition at line 119 of file cp_model.cc.

Friends And Related Symbol Documentation

◆ BoolVar

friend class BoolVar
friend

Definition at line 195 of file cp_model.h.

◆ CpModelBuilder

friend class CpModelBuilder
friend

Definition at line 196 of file cp_model.h.

◆ CumulativeConstraint

friend class CumulativeConstraint
friend

Definition at line 197 of file cp_model.h.

◆ DoubleLinearExpr

friend class DoubleLinearExpr
friend

Definition at line 198 of file cp_model.h.

◆ IntervalVar

friend class IntervalVar
friend

Definition at line 200 of file cp_model.h.

◆ LinearExpr

friend class LinearExpr
friend

Definition at line 199 of file cp_model.h.

◆ ReservoirConstraint

friend class ReservoirConstraint
friend

Definition at line 201 of file cp_model.h.

◆ SolutionIntegerValue

int64_t SolutionIntegerValue ( const CpSolverResponse & r,
const LinearExpr & expr )
friend

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

Definition at line 1392 of file cp_model.cc.


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