Package repast.simphony.parameter
Class ParameterTreeSweeper
- java.lang.Object
-
- repast.simphony.parameter.ParameterTreeSweeper
-
- All Implemented Interfaces:
ParameterSetter
,ParameterSweeper
- Direct Known Subclasses:
OptimizedParameterSweeper
public class ParameterTreeSweeper extends Object implements ParameterSweeper
The default implementation of a parameter sweeper. This will just next through all itsParameterSetter
s always performing the nexts in the same way. For a given parameter tree this sweeper will:
First, execute a next on all of the elements in the tree generating a base set of parameters that will be executed.
Second, execute the leaves of the tree until they are finished. After one finishes it will next the parent of that item, and then execute its subleaves again. In other words, the lowest levels are executed until they are finished, as they finish their parents are then called, followed by calling the lower levels again. Finish propagates upwards until everything has finished.- Author:
- Jerry Vos
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
firstTime
protected ParameterSetter
lastAddedSetter
protected NaryTree<ParameterSetter>
paramTree
protected ParameterSetter
rootSetter
protected RunParameterSetter
runSetter
protected NaryTreeTraverser<ParameterSetter>
traverser
-
Constructor Summary
Constructors Constructor Description ParameterTreeSweeper()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(ParameterSetter setter)
Adds the givenParameterSetter
to be executed as a direct descendent of previously added node.void
add(ParameterSetter parent, ParameterSetter setter)
Adds the givenParameterSetter
to specified parent initialzier.void
addDoubleRange(String param, double base, double max, double step)
Adds a sweep dimension for the specifed double parameter -- that is, for every run currently defined for this sweeper, runs will now be made for each step from base to max.void
addIntRange(String param, int base, int max, int step)
Adds a sweep dimension for the specifed integer parameter -- that is, for every run currently defined for this sweeper, runs will now be made for each step from base to max.void
addToRoot(ParameterSetter setter)
Adds the specified parameter setter as a child of the root.boolean
atEnd()
Returns true if all theParameterSetter
s have finished.protected boolean
childrenFinished(ParameterSetter parent)
protected Parameters
firstParameters(Parameters params)
Collection<ParameterSetter>
getChildren(ParameterSetter parentSetter)
Retrieves theParameterSetter
s that are direct children of the specified setter.ParameterSetter
getRootParameterSetter()
Retrieves the rootParameterSetter
, that all other setters are a child of.int
getRunCount()
void
next(Parameters params)
Executes theParameterSetter
s as specified in this class's description.protected Parameters
nextParameters(Parameters params)
protected Parameters
nextParameters(ParameterSetter init, Parameters params)
protected void
nextSelf(ParameterSetter init, Parameters params)
void
remove(ParameterSetter setter)
Removes the givenParameterSetter
from those to be executedvoid
reset(Parameters params)
Resets all the parameter initializersprotected void
resetChildren(ParameterSetter init, Parameters params)
void
setRunCount(int count)
Sets the number of time that the sweeper should execute a run for each unique parameter combination.String
toString()
String
toStringChildren(ParameterSetter setter)
-
-
-
Field Detail
-
rootSetter
protected ParameterSetter rootSetter
-
runSetter
protected RunParameterSetter runSetter
-
lastAddedSetter
protected ParameterSetter lastAddedSetter
-
firstTime
protected boolean firstTime
-
paramTree
protected NaryTree<ParameterSetter> paramTree
-
traverser
protected NaryTreeTraverser<ParameterSetter> traverser
-
-
Method Detail
-
atEnd
public boolean atEnd()
Returns true if all theParameterSetter
s have finished.- Specified by:
atEnd
in interfaceParameterSetter
- Returns:
- (not) all
ParameterSetter
s have finished
-
next
public void next(Parameters params)
Executes theParameterSetter
s as specified in this class's description.- Specified by:
next
in interfaceParameterSetter
- Parameters:
params
- the parameters object to load settings into
-
reset
public void reset(Parameters params)
Resets all the parameter initializers- Specified by:
reset
in interfaceParameterSetter
-
nextParameters
protected Parameters nextParameters(ParameterSetter init, Parameters params)
-
nextSelf
protected void nextSelf(ParameterSetter init, Parameters params)
-
resetChildren
protected void resetChildren(ParameterSetter init, Parameters params)
-
childrenFinished
protected boolean childrenFinished(ParameterSetter parent)
-
nextParameters
protected Parameters nextParameters(Parameters params)
-
firstParameters
protected Parameters firstParameters(Parameters params)
-
add
public void add(ParameterSetter parent, ParameterSetter setter)
Adds the givenParameterSetter
to specified parent initialzier.- Specified by:
add
in interfaceParameterSweeper
- Parameters:
parent
- the parent setter the new setter is a child ofsetter
- a parameter setter that will be executed- Throws:
IllegalArgumentException
- if either the parent or the setter are null.
-
add
public void add(ParameterSetter setter)
Adds the givenParameterSetter
to be executed as a direct descendent of previously added node. The last added setter will be the "innermost" setter executed during a sweep. All convenience methods use this method. (This supports the typical usage where we simply intend to create an n-D cube space to sweep through.- Parameters:
setter
- a parameter setter that will be executed
-
addToRoot
public void addToRoot(ParameterSetter setter)
Adds the specified parameter setter as a child of the root.- Parameters:
setter
- the setter to add
-
remove
public void remove(ParameterSetter setter)
Removes the givenParameterSetter
from those to be executed- Specified by:
remove
in interfaceParameterSweeper
- Parameters:
setter
- a parameter setter to remove
-
addIntRange
public void addIntRange(String param, int base, int max, int step)
Adds a sweep dimension for the specifed integer parameter -- that is, for every run currently defined for this sweeper, runs will now be made for each step from base to max. (Conveience method.)- Parameters:
param
- parameter namebase
- starting valuemax
- ending valuestep
- added to current value to get next
-
addDoubleRange
public void addDoubleRange(String param, double base, double max, double step)
Adds a sweep dimension for the specifed double parameter -- that is, for every run currently defined for this sweeper, runs will now be made for each step from base to max. (Conveience method.)- Parameters:
param
- parameter namebase
- starting valuemax
- ending valuestep
- added to current value to get next
-
setRunCount
public void setRunCount(int count)
Sets the number of time that the sweeper should execute a run for each unique parameter combination. Note: this method only manages the default run initialzer that will be placed just below root. If aRunParameterSetter
is also added elsewhere, that intializer will also create new runs. Also, if new runs are added directly to root (e.g., not using conveinience methods) those runs may not be subject to this count.- Parameters:
count
- number of runs to execute for each combination of paramaters
-
getRunCount
public int getRunCount()
-
getRootParameterSetter
public ParameterSetter getRootParameterSetter()
Retrieves the rootParameterSetter
, that all other setters are a child of.- Specified by:
getRootParameterSetter
in interfaceParameterSweeper
- Returns:
- the root
ParameterSetter
-
getChildren
public Collection<ParameterSetter> getChildren(ParameterSetter parentSetter)
Retrieves theParameterSetter
s that are direct children of the specified setter.- Specified by:
getChildren
in interfaceParameterSweeper
- Parameters:
parentSetter
- the setter whose children to fetch- Returns:
- the direct descendants of the specified setter
-
toStringChildren
public String toStringChildren(ParameterSetter setter)
-
-