Skip to main content
FRAMES NO FRAMES

Class IlcCPEngine

Definition file: ilcp/cpext.h
Map of IlcCPEngineIlcCPEngineIloCPEngineIlcCPEngine
An instance of this class represents a backtracking search engine for CP Optimizer.

You never need to create an instance of this class. The master IloCP object will create instances of this class which you can then use in your own CP Optimizer extensions code in C++. Specifically, you can get the current instance from within an instance of IlcGoalI, IlcDemonI or IlcConstraintI by calling the getCPEngine() member function. Likewise, these classes (as well as others such as IlcRevInt) require that you pass an instance of this class when building an object of that type.

The search can also be influenced by adding constraints (add(const IlcConstraint ct)) or by performing "internal" solves (solve(IlcGoal goal, IlcBool restore = IlcFalse)).

Most member functions in this class contain assert statements. For an explanation of the macro NDEBUG (a way to turn on or turn off these assert statements), see the concept Assert and NDEBUG.

See Also:

Method Summary
public voidadd(const IlcConstraint constraint) const
public voidaddReversibleAction(const IlcGoal goal) const
public voidexitSearch() const
public voidfail(IlcAny label=0) const
public IlcAllocationStack *getHeap() const
public IlcFloatgetInfo(const char * name) const
public IlcIntgetInfo(IlcCPEngine::IntInfo info) const
public IlcIntgetRandomInt(IlcInt n) const
public IlcFloatgetRandomNum() const
public ostream &out() const
public IlcBoolsolve(const IlcGoal goal, IlcBool restore=IlcFalse) const
Inner Enumeration
IlcCPEngine::IntInfo Integer information for IlcCPEngine.
Method Detail

add

public void add(const IlcConstraint constraint) const

This member function adds constraint to the invoking engine so that it takes constraint into account during its search.

This function may only be called from inside an IlcGoalI or IlcConstraintI::post.


addReversibleAction

public void addReversibleAction(const IlcGoal goal) const

For managing reversible changes that are not assignments, CP Optimizer provides reversible actions. Such actions are executed when CP Optimizer restores the state of the invoking optimizer. A reversible action is created by the member function addReversibleAction.

However, where possible, it is much more efficient to use the reversible classes—IlcRevInt, IlcRevAny, IlcRevBool, IlcRevFloat—to manage reversible assignments than to use reversible actions.

In the member function addReversibleAction, the argument goal must be a goal that does not change the state of the invoking engine. That is, it must not execute any reversible assignments, nor call other goals, nor call the member function fail. If the local engine backtracks to a choice point that was set before this call to addReversibleAction, then goal will be executed.

The execution of reversible actions is interleaved with the restoration of reversible states. Thus when a reversible goal is called, the state of the invoking CP optimizer is the same as the state of the invoking solver when addReversibleAction was called.


exitSearch

public void exitSearch() const

This member function completely exits the search of the invoking worker.

See Also:


fail

public void fail(IlcAny label=0) const

The backtrack of a search goal is triggered by this member function. In fact, this member function triggers the failure of the executing instance of IlcGoal. The execution of the current goal then stops, and goal execution resumes at the last choice point with untried subgoals. It is possible to resume goal execution at an earlier choice point by associating labels with choice points. Then the member function fail can be called with a label, and in that case, goal execution resumes at the last choice point with that label.

See Also:


getHeap

public IlcAllocationStack * getHeap() const

This member function returns a pointer to the heap associated with the invoking engine. Use this member function with the overloaded new operator, like this:

new (cpengine.getHeap())

getInfo

public IlcFloat getInfo(const char * name) const

This method returns the value of information named name in the invoking IlcCPEngine instance. The information is with respect to this local worker, and not globally over the whole search process.


getInfo

public IlcInt getInfo(IlcCPEngine::IntInfo info) const

This method returns the value of the Integer information info in the invoking IlcCPEngine instance. The information is with respect to this local worker, and not globally over the whole search process.


getRandomInt

public IlcInt getRandomInt(IlcInt n) const

This member function returns a pseudo-randomly generated integer value in the range [0..n).

See Also:


getRandomNum

public IlcFloat getRandomNum() const

This member function returns a pseudo-randomly generated floating-point value in the range [0..1).


out

public ostream & out() const

This member function returns a reference to the stream currently used for logging. It returns the same stream provided by IloCP::out (IloAlgorithm::out).


solve

public IlcBool solve(const IlcGoal goal, IlcBool restore=IlcFalse) const

This member function solves a sub-problem by using the goal goal passed as a parameter. The parameter restore indicates whether or not at the end of the search the invoking engine should restore the state that it was in prior to the search.


Inner Enumeration Detail

Enumeration IntInfo

Definition file: ilcp/cpext.h
Integer information for IlcCPEngine.

An enumeration for the class IlcCPEngine.

These values are used by IlcCPEngine::getInfo to obtain local information about the invoking worker as opposed to global information over the whole search process. For example, IlcCPEngine::getInfo(IlcCPEngine::NumberOfBranches) will return the number of branches executed by this local worker up to the current point in search.

Fields

NumberOfChoicePoints = 1

This information is the number of choice points executed so far in the local worker IlcCPEngine instance.

NumberOfFails = 2

This information is the number of fails executed so far in the local worker IlcCPEngine instance.

NumberOfBranches = 3

This information is the number of branches executed so far in the local worker IlcCPEngine instance.

NumberOfEngineVariables = 6

Advanced information. This information represents the total number of ''engine'' variables created in the local engine at the current point in search. Instances of IlcIntVar, IlcIntervalVar and IlcSequenceVar are engine variables.

MemoryUsage = 8

This information represents the total memory, in bytes, used by the local IlcCPEngine instance and any of its slave objects.

WorkerId = 26

CP Optimizer assigns an ID to each local worker when solving in parallel. This ID can take a value to 0 to the number of worker threads less one.

NumberOfEngineConstraints = 2018

Advanced information. This information represents the total number of ''engine'' constraints created in the local engine at the current point in search. This is largely an internal measurement but can be useful for debugging or understanding memory usage.

ILC_MAX_IntInfo