JaCoP.core
Class SimpleBacktrackableManager

java.lang.Object
  extended by JaCoP.core.SimpleBacktrackableManager
All Implemented Interfaces:
BacktrackableManager
Direct Known Subclasses:
IntervalBasedBacktrackableManager

public class SimpleBacktrackableManager
extends java.lang.Object
implements BacktrackableManager

It is responsible of remembering what variables have changed at given store level.

Version:
3.1
Author:
Radoslaw Szymanek and Krzysztof Kuchcinski

Field Summary
 int currentLevel
          It specifies the current level which is active in the manager.
 boolean currentLevelMax
          It specifies if for the current level we have reached the cutoff value.
 Backtrackable[] objects
          It stores objects which change has to be restored upon backtracking.
 boolean trailContainsAllChanges
          It specifies if for the current level the all changes are already stored in the trail.
 
Constructor Summary
SimpleBacktrackableManager(Backtrackable[] vars, int noOfObjects)
          It constructs a trail manager.
 
Method Summary
 void addChanged(int index)
          It allows to inform the manager that a given item with id (index) has changed at given level.
 int getLevel()
          It returns the current level at which the changes are being registered.
 boolean isRecognizedAsChanged(int index)
          It allows for easy testing if a given object is considered by the manager as the object which has changed and needs being informed about backtracking.
 void removeLevel(int removedLevel)
          It allows to inform all objects which have changed at removedLevel that the backtracking from that level has occurred.
 void setLevel(int level)
          It specifies the level which should become the active one in the manager.
 void setSize(int size)
          It specifies how many objects within objects array are being actually managed.
 java.lang.String toString()
           
 void update(Backtrackable[] objects, int noOfObjects)
          It updates the manager with new array of objects to manage and new number of them.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentLevel

public int currentLevel
It specifies the current level which is active in the manager.


objects

public Backtrackable[] objects
It stores objects which change has to be restored upon backtracking. The positions of objects will be stored by the manager and all changed objects will have their function removeLevel() be called.


trailContainsAllChanges

public boolean trailContainsAllChanges
It specifies if for the current level the all changes are already stored in the trail. This situation occurs after each backtrack. If new changes are added then this flag indicates that trail has to be used.


currentLevelMax

public boolean currentLevelMax
It specifies if for the current level we have reached the cutoff value.

Constructor Detail

SimpleBacktrackableManager

public SimpleBacktrackableManager(Backtrackable[] vars,
                                  int noOfObjects)
It constructs a trail manager.

Parameters:
noOfObjects - it specifies number of objects being managed.
vars - it specifies the list of objects being managed.
Method Detail

addChanged

public void addChanged(int index)
It allows to inform the manager that a given item with id (index) has changed at given level.

Specified by:
addChanged in interface BacktrackableManager
Parameters:
index - it specifies the index of the object which has changed.

setLevel

public void setLevel(int level)
It specifies the level which should become the active one in the manager.

Specified by:
setLevel in interface BacktrackableManager
Parameters:
level - the active level at which the changes will be recorded.

removeLevel

public void removeLevel(int removedLevel)
It allows to inform all objects which have changed at removedLevel that the backtracking from that level has occurred.

Specified by:
removeLevel in interface BacktrackableManager
Parameters:
removedLevel - it specifies the level which is being removed.

setSize

public void setSize(int size)
It specifies how many objects within objects array are being actually managed. It allows to specify partially empty array.

Specified by:
setSize in interface BacktrackableManager
Parameters:
size - the number of objects in the array.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isRecognizedAsChanged

public boolean isRecognizedAsChanged(int index)
It allows for easy testing if a given object is considered by the manager as the object which has changed and needs being informed about backtracking.

Specified by:
isRecognizedAsChanged in interface BacktrackableManager
Parameters:
index - the position of the object which status is in question.
Returns:
it returns true if the manager recognizes object at position index as changed one.

getLevel

public int getLevel()
Description copied from interface: BacktrackableManager
It returns the current level at which the changes are being registered.

Specified by:
getLevel in interface BacktrackableManager
Returns:
the active level for which the changes are being registered.

update

public void update(Backtrackable[] objects,
                   int noOfObjects)
Description copied from interface: BacktrackableManager
It updates the manager with new array of objects to manage and new number of them. This function works properly only during model creation phase, so manager can learn about freshly created objects. If used during search then the old array must be part of the new array to allow manager work properly.

Specified by:
update in interface BacktrackableManager
Parameters:
objects - a new array of objects
noOfObjects - number of objects in the new array to be taken care of.