KIntVar

class KIntVar : public KNumVar

This class implements an integer variable with enumerated (finite) domain. Decision variables are the variable quantities that we are trying to instantiate in order to satisfy the constraints of our problem. In this version, Artelys Kalis works with integer variables : decision variables which are constrained to take only integer values. These integer variables are represented by instances of the class KIntVar.

Example :

KProblem  p(...);
// X is an integer variable that can take value 0,1,2,3,4,5,6,7,8,9,10
KIntVar X(p, "X", 0, 10);
// Y is an integer variable that can take value 7,8,10 (3 different values)
KIntVar Y(p, "Y", KIntArray(3, 7, 8, 10));

// Z is an integer variable that can take value 3,4,5
KIntVar Z;
Z = KIntVar(p,3,5);

See

KIntArray KIntVarArray

Since

2016.1

Public Functions

KIntVar()

Default constructor.

KIntVar(KProblem &problem, const char *name, const int minValue = 0, const int maxValue = 1, bool isBoundIntVar = false)

Main constructor : minValue and maxValue are the bounds of the KIntVar’s domain

Parameters
  • problem – Involved problem

  • name – Name of the variable

  • minValue – lower bound for the variable

  • maxValue – upper bound for the variable

  • isBoundIntVar – false if the domain may have holes, true otherwise

KIntVar(KProblem &problem, const char *name, KIntArray &domain)

Main constructor : enumerated domain.

KIntVar(KProblem &problem)

Basic constructor.

KIntVar(const KIntVar &toCopy)

Copy constructor.

void instantiate(const int value)

Instantiate the variable to a value.

void remVal(const int value)

Remove value from the variable’s domain.

virtual const char *getName() const

Return the name of the variable.

virtual void setName(const char *name)

Set the name of the variable.

virtual double getInf() const

Returns lower bound of this variable.

int getIntInf() const

Returns integer lower bound of this variable.

double getMiddle() const

Returns value in variable’s domain and close to the middle.

virtual double getSup() const

Returns upper bound of this variable.

int getIntSup() const

Returns integer upper bound of this variable.

int getDomainSize() const

Returns current domain size of the variable.

virtual double getValue(void) const

Returns current instantiation of the variable (when the variable is not instantiated the returned value is undefined)

int getIntValue(void) const

Returns current instantiation of the variable (when the variable is not instantiated the returned value is undefined)

virtual bool getIsInstantiated() const

Returns true if the variable has been assigned a value, false otherwise.

virtual int getDegree() const

Returns the number of constraints where this variable appears.

virtual double getTarget() const

Get target value.

int getRandomValue() const

Get a random value in the domain of the variable.

void getNextDomainValue(int &next)

Get value immediatly after “next” in the domain of the variable and put it into next.

void getPrevDomainValue(int &prev)

Get value immediatly before “prev” in the domain of the variable and put it into prev.

bool shaveFromLeft(void)

Shave lower bound of variable.

bool shaveFromRight(void)

Shave upper bound of variable.

bool shaveOnValue(int val)

Shave the value ‘val’.

void setInf(int value)

Set the lower bound to value.

void setSup(int value)

Set the upper bound to value.

void setTarget(int value)

Set the target value.

void optimizeDomainRepresentation()

Optimize the internal representation of the domain.

bool canBeInstantiatedTo(int value)

Check if value is in the domain.

bool isEqualTo(KIntVar &x)

Check if equal to x.

KIntVar *getCopyPtr() const

Return a copy of this KIntVar object.

KIntVar &operator=(const KIntVar &toCopy)

overloaded operator =

virtual void print(std::ostream &fout) const

Pretty printing of the variable to an ouput stream.

virtual void print(void) const

Pretty printing to the standard ouput stream.

virtual void print(void *ctx, PrintFunctionPtr *pfp) const

Pretty printing.

virtual int instanceof(void) const

Return the type of this variable

Parameters
  • KNumVar::IsKNumVar – for an instance of the class KNumVar

  • KNumVar::IsKIntVar – for an instance of the class KNumVar

  • KNumVar::IsKFloatVar – for an instance of the class KNumVar