Package org.jacop.core
Class SimpleBacktrackableManager
- java.lang.Object
-
- org.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:
- 4.8
-
-
Field Summary
Fields Modifier and Type Field Description intcurrentLevelIt specifies the current level which is active in the manager.booleancurrentLevelMaxIt specifies if for the current level we have reached the cutoff value.(package private) SparseSetcurrentlyChangedIt contains indexes of objects changed at active level.(package private) intcutOffValueIt specifies the cutoff value after which a trail is no longer stored and recovery of the old state is done by informing all the variables about the backtracking.(package private) booleandebugIt specifies if the debugging information should be displayed.(package private) int[]emptyLevelIt is a fake variable to distinguish between empty levels and full levels.(package private) int[]fullLevelIt is a fake variable to disinguish between full levels and empty ones.(package private) java.util.List<java.lang.Integer>levelInfoIt specifies the levels of the store for which trails are stored.(package private) intnoOfObjectsIt specifies the actual number of objects in the objects array.Backtrackable[]objectsIt stores objects which change has to be restored upon backtracking.(package private) java.util.List<int[]>trailIt specifies a trail.booleantrailContainsAllChangesIt specifies if for the current level the all changes are already stored in the trail.
-
Constructor Summary
Constructors Constructor Description SimpleBacktrackableManager(Backtrackable[] vars, int noOfObjects)It constructs a trail manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChanged(int index)It allows to inform the manager that a given item with id (index) has changed at given level.intgetLevel()It returns the current level at which the changes are being registered.booleanisRecognizedAsChanged(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.voidremoveLevel(int removedLevel)It allows to inform all objects which have changed at removedLevel that the backtracking from that level has occurred.voidsetLevel(int level)It specifies the level which should become the active one in the manager.voidsetSize(int size)It specifies how many objects within objects array are being actually managed.java.lang.StringtoString()voidupdate(Backtrackable[] objects, int noOfObjects)It updates the manager with new array of objects to manage and new number of them.
-
-
-
Field Detail
-
currentLevel
public int currentLevel
It specifies the current level which is active in the manager.
-
noOfObjects
int noOfObjects
It specifies the actual number of objects in the objects array.
-
currentlyChanged
SparseSet currentlyChanged
It contains indexes of objects changed at active level. It may be empty if trailContainsAllChanges is set to true.
-
trail
java.util.List<int[]> trail
It specifies a trail. A recorded changes which will be used upon backtracking to inform the objects about backtracking.
-
levelInfo
java.util.List<java.lang.Integer> levelInfo
It specifies the levels of the store for which trails are stored.
-
cutOffValue
int cutOffValue
It specifies the cutoff value after which a trail is no longer stored and recovery of the old state is done by informing all the variables about the backtracking.
-
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.
-
emptyLevel
final int[] emptyLevel
It is a fake variable to distinguish between empty levels and full levels.
-
fullLevel
final int[] fullLevel
It is a fake variable to disinguish between full levels and empty ones.
-
debug
final boolean debug
It specifies if the debugging information should be displayed.- See Also:
- Constant Field Values
-
-
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:
addChangedin interfaceBacktrackableManager- 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:
setLevelin interfaceBacktrackableManager- 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:
removeLevelin interfaceBacktrackableManager- 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:
setSizein interfaceBacktrackableManager- Parameters:
size- the number of objects in the array.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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:
isRecognizedAsChangedin interfaceBacktrackableManager- 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:BacktrackableManagerIt returns the current level at which the changes are being registered.- Specified by:
getLevelin interfaceBacktrackableManager- Returns:
- the active level for which the changes are being registered.
-
update
public void update(Backtrackable[] objects, int noOfObjects)
Description copied from interface:BacktrackableManagerIt 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:
updatein interfaceBacktrackableManager- Parameters:
objects- a new array of objectsnoOfObjects- number of objects in the new array to be taken care of.
-
-