Class SimpleBacktrackableManager

java.lang.Object
org.jacop.core.SimpleBacktrackableManager
All Implemented Interfaces:
BacktrackableManager
Direct Known Subclasses:
IntervalBasedBacktrackableManager

public class SimpleBacktrackableManager extends 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
    int
    It specifies the current level which is active in the manager.
    boolean
    It specifies if for the current level we have reached the cutoff value.
    (package private) SparseSet
    It contains indexes of objects changed at active level.
    (package private) int
    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.
    (package private) final boolean
    It specifies if the debugging information should be displayed.
    (package private) final int[]
    It is a fake variable to distinguish between empty levels and full levels.
    (package private) final int[]
    It is a fake variable to disinguish between full levels and empty ones.
    (package private) List<Integer>
    It specifies the levels of the store for which trails are stored.
    (package private) int
    It specifies the actual number of objects in the objects array.
    It stores objects which change has to be restored upon backtracking.
    (package private) List<int[]>
    It specifies a trail.
    boolean
    It 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

    Modifier and Type
    Method
    Description
    void
    addChanged(int index)
    It allows to inform the manager that a given item with id (index) has changed at given level.
    int
    It returns the current level at which the changes are being registered.
    boolean
    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.
     
    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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • 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

      List<int[]> trail
      It specifies a trail. A recorded changes which will be used upon backtracking to inform the objects about backtracking.
    • levelInfo

      List<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:
  • Constructor Details

    • 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 Details

    • 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 String toString()
      Overrides:
      toString in class 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.