1.5 The class OZ_FiniteDomain

Instances of this class represent the domains for finite domain integer variables. A domain may have holes and can range from 0 to OZ_getFDSup(), which is currently 134\;217\;726.

The representation of a finite domain consists of two parts. As long as there are no holes in the domain it suffices to store the lower and upper bound of the domain. Holes are stored in the so-called extension of the domain representation. This extension is either a bit-vector or a list of intervals. The kind of extension used is automatically determined and not visible outside.

The smallest element of a domain d is denoted by min(d) and the largest element by max(d).

1.5.1 Miscellaneous

OZ_FDState

enum OZ_FDState {fd_emptyfd_fullfd_boolfd_singl};

Values of this enumerable type are used when constructing an instance of the class OZ_FiniteDomain or in conjunction with operators == resp. !=.

value

explanation

fd_empty

The domain does not contain any element.

fd_full

The domain contains all elements possible,

i. e.

0, \ldots, \mbox{\tt OZ\_getFDSup()}.

fd_bool

The domain contains 0 and 1.

fd_singl

The domain contains a single element.

1.5.2 Constructor Member Functions

OZ_FiniteDomain

OZ_FiniteDomain(void);

This default constructor creates an uninitialized instance.

OZ_FiniteDomain

OZ_FiniteDomain(const OZ_FiniteDomain &d);

This copy constructor copies the current domain of d to *this, so that d and *this denote the same domain but are independent representations of it.

OZ_FiniteDomain

OZ_FiniteDomain(OZ_FDState state);

This constructor creates an object which represents a domain according to the value of state. Valid values for state are fd_empty and fd_full.

OZ_FiniteDomain

OZ_FiniteDomain(OZ_Term t);

This constructor is the composition of the default constructor and the member function initDescr().

OZ_FiniteDomain

OZ_FiniteDomain(const OZ_FSetValue &fs);

This constructor initialises *this with the values contained in the finite set fs.

1.5.3 Initialisation Member Functions

The return value of all initialisation member functions is the size of the domain they initialised.

initRange

int OZ_FiniteDomain::initRange(int lint u);

Initialises an instance of class OZ_FiniteDomain to the domain \{l, \ldots, u\}.

In case l > u, the domain is set to be empty.

initSingleton

int OZ_FiniteDomain::initSingleton(int l);

Initialises an instance of class OZ_FiniteDomain to the domain \{l\}.

initDescr

int OZ_FiniteDomain::initDescr(OZ_Term d);

Initialises an instance of class OZ_FiniteDomain to a domain according to the domain description d. The domain description must be conform with level4 (see syntax definition of a domain description in Section 1.2.4, entry expectDomDesc).

initFull

int OZ_FiniteDomain::initFull(void);

Initialises an instance of class OZ_FiniteDomain to the domain \{0, \ldots, \mbox{\tt OZ\_getFDSup()}\}.

initEmpty

int OZ_FiniteDomain::initEmpty(void);

Initialises an instance of class OZ_FiniteDomain to the empty domain.

initBool

int OZ_FiniteDomain::initBool(void);

Initialises an instance of class OZ_FiniteDomain to the domain \{0,1\}.

1.5.4 Reflection Member Functions

getMidElem

int getMidElem(voidconst;

This member function returns the element in the middle of the domain. For the domain d it is (max(d)-min(d))\; div\;
2. If this value happens to be a hole the element closest to it will be returned. In case there are two elements with the same distance to the middle of the domain the smaller one will be taken.

getNextSmallerElem

int getNextSmallerElem(int vconst;

This member function returns the largest element in the domain smaller than v. In case v is the smallest element it returns -1.

getNextLargerElem

int getNextLargerElem(int vconst;

This member function returns the smallest element in the domain larger than v. In case v is the largest element it returns -1.

getLowerIntervalBd

int getLowerIntervalBd(int vconst;

This member function returns the smallest value of the interval v belongs to. In case v does not belong to any interval the function returns -1.

getUpperIntervalBd

int getUpperIntervalBd(int vconst;

This member function returns the largest value of the interval v belongs to. In case v does not belong to any interval the function returns -1.

getSize

int getSize(voidconst;

This member function returns the size of the domain, i. e. the number of elements in the domain.

getMinElem

int getMinElem(voidconst;

This member function returns the smallest element of the domain.

getMaxElem

int getMaxElem(voidconst;

This member function returns the largest element of the domain.

getSingleElem

int getSingleElem(voidconst;

This member function returns the element of a singleton domain. In case the domain is not a singleton domain it returns -1.

1.5.5 Operator Member Functions

operator =

const OZ_FiniteDomain &operator = (const OZ_FiniteDomain &fd);

This assignment operator copies fd to its left hand side, so that both domains are the same but are independent of each other.

operator ==

OZ_Boolean operator == (const OZ_FDState sconst;

This operator returns OZ_TRUE if the domain corresponds to the value of s. Otherwise it returns OZ_FALSE.

operator ==

OZ_Boolean operator == (const int iconst;

This operator returns OZ_TRUE if the domain contains only i. Otherwise it returns OZ_FALSE.

operator !=

OZ_Boolean operator != (const OZ_FDState sconst;

This operator returns OZ_TRUE if the domain does not correspond to the value of s. Otherwise it returns OZ_FALSE.

operator !=

OZ_Boolean operator != (const int iconst;

This operator returns OZ_TRUE if the domain does not contain i or contains more than one element. Otherwise it returns OZ_FALSE.

operator &

OZ_FiniteDomain operator & (const OZ_FiniteDomain &yconst;

This member function returns the intersection of the finite domains represented by y and *this.

operator |

OZ_FiniteDomain operator | (const OZ_FiniteDomain &yconst;

This member function returns the union of the finite domains represented by y and *this.

operator ~

OZ_FiniteDomain operator ~ (voidconst;

This member function returns the negation of the finite domain represented by *this. The negation is computed by removing all elements in *this from \{0, \ldots, \mbox{\tt
OZ\_getFDSup()}\}.

operator &=

int operator &= (const OZ_FiniteDomain &y);
int operator &= (const int y);

This member function computes the intersection of the finite domains represented by y and *this and assigns the result to *this. Further, the size of the updated domain is returned.

operator +=

int operator += (const int y);

This member function adds the element y to the domain represented by *this and returns the size of the updated domain.

operator -=

int operator -= (const int y);

This member function removes the element y from the domain represented by *this and returns the size of the updated domain.

operator -=

int operator -= (const OZ_FiniteDomain &y);

This member function removes all elements contained in the domain represented by y from the domain represented by *this and returns the size of the updated domain.

operator <=

int operator <= (const int y);

This member function removes all elements being larger than y from the domain represented by *this and returns the size of the updated domain.

operator >=

int operator >= (const int y);

This member function removes all elements being smaller than y from the domain represented by *this and returns the size of the updated domain.

1.5.6 Auxiliary Member Functions

intersectWithBool

int intersectWithBool(void);

This member function intersects the current domain with the domain \{0,1\} and produces the following return value.

return value

meaning

-2

The resulting domain is empty.

-1

The resulting domain is \{0,1\}

otherwise

The remaining element is returned.

constrainBool

int constrainBool(void);

This member function intersects the current domain with the domain \{0,1\} and returns the size of resulting domain.

isIn

OZ_Boolean isIn(int iconst;

This member function returns OZ_TRUE if i is contained in the domain represented by *this. Otherwise it returns OZ_FALSE.

copyExtension

void copyExtension(void);

This member function replaces the current extension of the domain representation by a copy of it.

disposeExtension

void disposeExtension(void);

This member function frees the heap memory occupied by the extension of the domain.

toString

char * toString(voidconst;

Returns a textual representation of the finite domain pointing to a static array of chars.


Tobias Müller
Version 1.4.0 (20080702)