|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ascape.model.AscapeObject
org.ascape.model.rule.Rule
public abstract class Rule
An abstract base class for behaviors that can be be iterated across agent scapes or a single agent. You can subclass rule to provide any kind of behavior you want for an agent. Often, rules will simply call agent member functions. But, because rules aren't themselves member functions of agents, they don't need to follow class inheiritance rules, and they can be added, removed and executed dynamically. In effect, they provide a kind of dynamic method dispatch capability to the framework, and allow us to flexibly execute methods upon collections of agents without needing to know anything about the underlying structure of the collection or the method of execution. The system is designed to be powerful, without imposing large performance or conceptual costs. For many common tasks, you can use built-in rules. For example, if you want to allow movement for your agents, you can add a standard movement rule to the scape containing them. These rules are memebers of the Agent and Cell classes.
scape.addRule(MOVEMENT_RULE);Then, simply override the built-in agent movement rule.
public class MyAgent extends CellOccupant { ... public void movement() { [Your movement code] } ... } There are a number of rules that have behavior allready defined. (And more planned.) For these ruels, you simply need to add them to a scape. So to have you agents take a random walk in any direction, simply add the random walk rule. <pre> scape.addRule(RANDOM_WALK_RULE); <pre> To create your own rules you can implement a rule as a straight-forward class. You may want to do this if there is significant state that is kept as part of the rule, as we do for our stat collector and value setter rules, or if you want to extend rules in different ways. But typically, rules are implemented as inner classes, static member classes or anoymous inner classes. <pre> scape.addRule(new Rule("Update Radius & ExecutionStrategy") { public void execute(Agent agent) { ((NormCell) agent).updateRadius(); ((NormCell) agent).updateStrategy(); } }); </pre> Information about the rule provided by the isRandomExecution and isCauseDelete is used by the scape execution methods to optimize rule execution. The default behavior is conservative, that is, rules are assumed to need random execution and potentially cause deletion in their parent scapes. For better performance, if your rules do not need to be execute randomly (typically because their outcomes do not affect otehr agents and/or are not affected by execution order), or cannot cause an agent to be deleted, you should override these methods and return false.
Scape
,
Agent
,
Cell
,
StatCollector
,
ValueSetter
,
Propogate
,
Serialized FormField Summary |
---|
Fields inherited from class org.ascape.model.AscapeObject |
---|
ARBITRARY_SEED, name, scape |
Constructor Summary | |
---|---|
Rule(java.lang.String name)
Constructs a rule with the providied name. |
Method Summary | |
---|---|
abstract void |
execute(Agent agent)
Perform the rule for the specified agent. |
Scape |
getScape()
Returns the scape the agent will act within. |
boolean |
isCauseRemoval()
Could this rule cause the removal of any agents from within an this rule's scape or any agent's scape? Used to determine safe optimization of iterations. |
boolean |
isIterateAll()
Should this rule be iterated across all even if iterations per cycle is set? Typically false. |
boolean |
isRandomExecution()
Does this action affect the state of any other agent in such a way that that another agent's execution of this rule would be affected? Used to determine safe optimization of iterations. |
void |
setScape(Scape scape)
Sets the scape for the agent to act within. |
Methods inherited from class org.ascape.model.AscapeObject |
---|
clone, diffDeep, diffDeep, diffDeepBFS, diffDeepDFS, diffDeepValidate, diffDeepVisit, equalsDeep, equalsDeep, equalsDeep, getComparisonStream, getName, getRandom, getRandomSeed, randomInRange, randomInRange, randomIs, randomToLimit, reseed, setComparisonStream, setName, setRandom, setRandomSeed, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Rule(java.lang.String name)
name
- the name of this objectMethod Detail |
---|
public abstract void execute(Agent agent)
agent
- the target agent.public void setScape(Scape scape)
setScape
in class AscapeObject
scape
- the scape that this rule 'belongs' topublic Scape getScape()
getScape
in class AscapeObject
public boolean isRandomExecution()
public boolean isCauseRemoval()
public boolean isIterateAll()
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |