Package org.svvrl.goal.core
Class AbstractControllableAlgorithm
java.lang.Object
org.svvrl.goal.core.AbstractAlgorithm
org.svvrl.goal.core.AbstractControllableAlgorithm
- All Implemented Interfaces:
java.util.EventListener
,Algorithm
,AlgorithmListener
,ControllableAlgorithm
- Direct Known Subclasses:
AbstractControllableGameSolver
,AbstractEditableAlgorithm
public abstract class AbstractControllableAlgorithm extends AbstractAlgorithm implements ControllableAlgorithm
This class provides default implementations for the
ControllableAlgorithm
interface. The initial running status is
Run. There are some methods that act as marks of a step or a stage of an
algorithm.
An object of this class is capable of adding other
ControllableAlgorithm
objects as subroutines. In this case, the
object will listen to the execution of its subroutines.
- Author:
- Ming-Hsien Tsai
-
Constructor Summary
Constructors Constructor Description AbstractControllableAlgorithm()
Constructs this algorithm with an empty name and empty options.AbstractControllableAlgorithm(java.lang.String name)
Constructs this algorithm with a specified name and empty options.AbstractControllableAlgorithm(java.lang.String name, Properties options)
Constructs this algorithm with a specified name and predefined options.AbstractControllableAlgorithm(Properties options)
Constructs this algorithm with an empty name and predefined options. -
Method Summary
Modifier and Type Method Description void
addControllableListener(ControllableListener l)
Inserts a controllable listener.void
addSubAlgorithm(Algorithm alg)
Adds a specified algorithm as a subroutine of this algorithm.void
doPause()
Pauses this algorithm.void
doStage()
Performs a single stage.void
doStart()
Executes this algorithm step-by-step automatically.void
doStep()
Performs a single step.protected void
fireReferenceChangedEvent()
Inform the listeners that the reference to the object has been changed.double
getInterval()
Returns the time interval in seconds between steps.int
getStages()
Returns the number of stages left for this algorithm to do.ControllableStatus
getStatus()
Returns the running status of this algorithm.protected void
pause()
Pauses this algorithm if the running status is not Run.protected void
pause(java.lang.String msg)
Outputs a step message and then pauses this algorithm if the running status is not Run.void
removeControllableListener(ControllableListener l)
Removes a controllable listener.void
removeSubAlgorithm(Algorithm alg)
Removes a specified algorithm from the subroutines of this algorithm.void
setInterval(double i)
Sets the time interval in seconds between steps.void
setStages(int i)
Sets the maximal number of stages that can be performed by this algorithm.void
setStatus(ControllableStatus status)
Sets the running status of this algorithm.void
setSynchronizationObject(java.lang.Object obj)
Sets the object for synchronization.protected void
stagePause()
Pauses this algorithm if the running status is not Run.protected void
stagePause(java.lang.String msg)
Outputs a stage message and pauses this algorithm if the running Status is not Run.Methods inherited from class org.svvrl.goal.core.AbstractAlgorithm
addAlgorithmListener, addProgress, appendStageMessage, appendStepMessage, getAlgorithmListeners, getCurrentProgress, getMaximalProgress, getMinimalProgress, getName, getOptions, getSubAlgorithms, isDeterministicProgress, removeAlgorithmListener, setCurrentProgress, setDeterministicProgress, setMaximalProgress, setMinimalProgress
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.svvrl.goal.core.Algorithm
addAlgorithmListener, getAlgorithmListeners, getOptions, removeAlgorithmListener
Methods inherited from interface org.svvrl.goal.core.AlgorithmListener
appendStageMessage, appendStepMessage, getCurrentProgress, getMaximalProgress, getMinimalProgress, setCurrentProgress, setDeterministicProgress, setMaximalProgress, setMinimalProgress
-
Constructor Details
-
AbstractControllableAlgorithm
public AbstractControllableAlgorithm()Constructs this algorithm with an empty name and empty options. -
AbstractControllableAlgorithm
public AbstractControllableAlgorithm(java.lang.String name)Constructs this algorithm with a specified name and empty options.- Parameters:
name
- the name of this algorithm
-
AbstractControllableAlgorithm
Constructs this algorithm with an empty name and predefined options.- Parameters:
options
- the predefined options of this algorithm
-
AbstractControllableAlgorithm
Constructs this algorithm with a specified name and predefined options.- Parameters:
name
- the name of this algorithmoptions
- the predefined options of this algorithm
-
-
Method Details
-
setStages
public void setStages(int i)Description copied from interface:ControllableAlgorithm
Sets the maximal number of stages that can be performed by this algorithm.- Specified by:
setStages
in interfaceControllableAlgorithm
- Parameters:
i
- the maximal number of stages
-
getStages
public int getStages()Description copied from interface:ControllableAlgorithm
Returns the number of stages left for this algorithm to do. A negative value means that there is no restriction on the number of stages.- Specified by:
getStages
in interfaceControllableAlgorithm
- Returns:
- the number of stages left for this algorithm to do
-
setSynchronizationObject
public void setSynchronizationObject(java.lang.Object obj)Description copied from interface:ControllableAlgorithm
Sets the object for synchronization. When this algorithm is going to pause and wait for a notification, the methodobj.wait()
will be invoked. When this algorithm is going to continue its execution, the methodobj.notify()
will be invoked.- Specified by:
setSynchronizationObject
in interfaceControllableAlgorithm
- Parameters:
obj
- the object for synchronization
-
addSubAlgorithm
Description copied from class:AbstractAlgorithm
Adds a specified algorithm as a subroutine of this algorithm. This method will add this algorithm as an algorithm listener of the subroutine such that the algorithm listeners of this algorithm also know what is going on in the subroutine.- Overrides:
addSubAlgorithm
in classAbstractAlgorithm
- Parameters:
alg
- the algorithm as a subroutine of this algorithm
-
removeSubAlgorithm
Description copied from class:AbstractAlgorithm
Removes a specified algorithm from the subroutines of this algorithm.- Overrides:
removeSubAlgorithm
in classAbstractAlgorithm
- Parameters:
alg
- an algorithm to be removed from the subroutines of this algorithm
-
setStatus
Description copied from interface:ControllableAlgorithm
Sets the running status of this algorithm. The statusesStep
,Stage
,Start
, andStop
should correspond to the methodsdoStep
,doStage
,doStart
, anddoPause
respectively.- Specified by:
setStatus
in interfaceControllableAlgorithm
- Parameters:
status
- the status of this algorithm
-
doStage
public void doStage()Description copied from interface:ControllableAlgorithm
Performs a single stage.- Specified by:
doStage
in interfaceControllableAlgorithm
-
doStep
public void doStep()Description copied from interface:ControllableAlgorithm
Performs a single step.- Specified by:
doStep
in interfaceControllableAlgorithm
-
doStart
public void doStart()Description copied from interface:ControllableAlgorithm
Executes this algorithm step-by-step automatically. Between each step, there is a time interval set by the methodsetInterval
.- Specified by:
doStart
in interfaceControllableAlgorithm
- See Also:
ControllableAlgorithm.setInterval(double)
-
doPause
public void doPause()Description copied from interface:ControllableAlgorithm
Pauses this algorithm.- Specified by:
doPause
in interfaceControllableAlgorithm
-
addControllableListener
Description copied from interface:ControllableAlgorithm
Inserts a controllable listener.- Specified by:
addControllableListener
in interfaceControllableAlgorithm
- Parameters:
l
- a controllable listener to be added
-
removeControllableListener
Description copied from interface:ControllableAlgorithm
Removes a controllable listener.- Specified by:
removeControllableListener
in interfaceControllableAlgorithm
- Parameters:
l
- a controllable listener to be removed
-
fireReferenceChangedEvent
protected void fireReferenceChangedEvent()Inform the listeners that the reference to the object has been changed. -
getInterval
public double getInterval()Description copied from interface:ControllableAlgorithm
Returns the time interval in seconds between steps.- Specified by:
getInterval
in interfaceControllableAlgorithm
- Returns:
- the time interval between steps, measured in seconds
-
setInterval
public void setInterval(double i)Description copied from interface:ControllableAlgorithm
Sets the time interval in seconds between steps.- Specified by:
setInterval
in interfaceControllableAlgorithm
- Parameters:
i
- the time interval between steps, measured in seconds
-
getStatus
Description copied from interface:ControllableAlgorithm
Returns the running status of this algorithm.- Specified by:
getStatus
in interfaceControllableAlgorithm
- Returns:
- the status of this algorithm
-
pause
protected void pause()Pauses this algorithm if the running status is not Run. This method can be considered as a mark indicating that a step is finished here. -
pause
protected void pause(java.lang.String msg)Outputs a step message and then pauses this algorithm if the running status is not Run. This method can be considered as a mark indicating that a step is finished here.- Parameters:
msg
- an output message
-
stagePause
protected void stagePause()Pauses this algorithm if the running status is not Run. This method can be considered as a mark indicating that a stage is finished here. -
stagePause
protected void stagePause(java.lang.String msg)Outputs a stage message and pauses this algorithm if the running Status is not Run. This method can be considered as a mark indicating that a stage is finished here.- Parameters:
msg
- an output message
-