blob: 8fa59e9df3d6f4af81762ea4366c42807fb0e6ef [file] [log] [blame]
«IMPORT emf»
«IMPORT metaabm»
«IMPORT metaabm::act»
«IMPORT metaabm::function»
«EXTENSION metaabm::tmpl::types»
«EXTENSION metaabm::tmpl::names»
«EXTENSION metaabm::tmpl::infer»
«EXTENSION metaabm::tmpl::util»
«EXTENSION metaabm::tmpl::projections»
«EXTENSION metaabm::ascape::tmpl::namesascape»
«EXTENSION metaabm::ascape::tmpl::inferascape»
«DEFINE AgentBody FOR SAgent
«IF owner != null
«EXPAND metaabm::tmpl::Java::GenerateComment»
public «owner.typeName()» «owner.getterName()»() {
return owner.typeName()») getScape().getScape();
}
«ENDIF
«IF parent != null && !((SContext) parent).projections.typeSelect(SNetwork).isEmpty»
«EXPAND metaabm::tmpl::Java::GenerateComment»
public List getNetwork() {
«IF buildGraphs().size > 0
List network = new ArrayList();
«FOREACH buildGraphs() AS graph
network.addAll(((Graph) «((SContext) parent).getterName()»().«graph.projection.getterName()»().getSpace()).getNeighborsFor(this));
«ENDFOREACH
return network;
«ELSE
return Collections.emptyList();
«ENDIF
}
«ENDIF
«FOREACH ((AGroup) rootActivity).roots AS root
«IF root.metaType == ADiffuse»
«EXPAND metaabm::tmpl::Java::GenerateComment»
private double «root.id()»Temp;
«EXPAND metaabm::tmpl::Java::GenerateComment»
public static final Rule «root.id().toUpperCase()»_RULE = new ExecuteThenUpdate("«root.label»") {
«EXPAND metaabm::tmpl::Java::GenerateComment»
private static final long serialVersionUID = 6846144446402098983L;
/**
* <!-- begin-user-doc -->
* Calculate and store diffusion value to neighbors.
*
* @param agent the playing agent
* <!-- end-user-doc -->
* @generated
*/
public void execute(Agent agent) {
«typeName()» «id()» = typeName()») agent;
double valueSum = 0.0f;
List neighbors = ((Cell) agent).findNeighbors();
for (Object neighbor : neighbors) {
«typeName()» «id()»Neighbor = typeName()») neighbor;
valueSum += «id()»Neighbor.get«((ADiffuse) root).diffused.id().toFirstUpper()»();
}
valueSum -= neighbors.size() * «id()».get«((ADiffuse) root).diffused.id().toFirstUpper()»();
valueSum /= neighbors.size();
«IF ((ADiffuse) root).diffusionRate != null
valueSum = «id()».get«((ADiffuse) root).diffused.id().toFirstUpper()»() + valueSum * «id()».«root.getterPath(((ADiffuse) root).diffusionRate, false)»;
«ELSE
valueSum = «id()».get«((ADiffuse) root).diffused.id().toFirstUpper()»() + valueSum;
«ENDIF
«IF ((ADiffuse) root).evaporationRate != null
valueSum *= 1.0f - «id()».«root.getterPath(((ADiffuse) root).evaporationRate, false)»;
«ELSE
valueSum *= 1.0f;
«ENDIF
«id()».«root.id()»Temp = valueSum;
}
/**
* <!-- begin-user-doc -->
* Update diffusion value. Occurs only when all diffusion has been
* calculated.
*
* @param agent the agent
* <!-- end-user-doc -->
* @generated
*/
public void update(Agent agent) {
«typeName()» «id()» = typeName()») agent;
«id()».set«((ADiffuse) root).diffused.id().toFirstUpper()»(«id()».«root.id()»Temp);
}
};
«ENDIF
«ENDFOREACH
«ENDDEFINE»
«DEFINE ScapeBody FOR SContext
«EXPAND metaabm::tmpl::Java::UtilBody
«FOREACH agents AS agent
«IF !agent.isHost()-»
org.ascape.model.Scape «agent.scape()»;
«ENDIF
«ENDFOREACH
«FOREACH agents AS agent
«IF !agent.isHost()-»
/**
* <!-- begin-user-doc -->
* Create an instance of «agent.label» that will be used to populate the «agent.scape()».
* Overide to customize the prototype, for example to change the views created for a member scape.
* <!-- end-user-doc -->
* @generated
*/
protected «agent.typeName()» create«agent.typeName()»Prototype() {
«agent.typeName()» «agent.id()» = new «agent.typeName()»();
«IF agent.buildGrid().exists(e|((SGrid) e.projection).dimensionality == 2)-»
«agent.id()».setCoordinate(new Coordinate2DDiscrete(0, 0));
«ELSEIF agent.buildSpace().exists(e|((SContinuousSpace) e.projection).dimensionality == 2)-»
«agent.id()».setCoordinate(new Coordinate2DContinuous(0, 0));
«ENDIF
return «agent.id()»;
}
«ENDIF
«ENDFOREACH
«EXPAND metaabm::tmpl::Java::GenerateComment»
static int next_vm_id;
«EXPAND metaabm::tmpl::Java::GenerateComment»
int vm_unique_id;
/**
* <!-- begin-user-doc -->
* Creates the members of «label».
* <!-- end-user-doc -->
* @generated
*/
public void createScape() {
super.createScape();
«IF parent != null
vm_unique_id = next_vm_id;
setName("«label» " + vm_unique_id);
next_vm_id++;
«ELSE»
setName("«label»");
«ENDIF
«IF parent != null
setAutoCreate(false);
setPrototypeAgent(new org.ascape.model.Scape());
«ENDIF
«IF acts().exists(e| e.metaType == ARule || e.metaType == AInitialize) || attributes.exists(e | e.gatherData)-»
//A manager scape provides rule execution and stat collection for itself.
if (isRoot()) {
Scape «scape()» = new Scape(new Singleton());
addscape()»);
«EXPAND ChildBuilderProxy FOR (AGroup) rootActivity
«IF attributes.exists(e | e.gatherData)-»
«EXPAND StatBuilder
«ENDIF
}
«ENDIF
«IF (rootActivity != null)-»
«EXPAND CreateScape (0) FOREACH agents
«EXPAND CreateScape (0) FOR rootActivity
«ENDIF
«IF (rootActivity != null)-»
«EXPAND CreateScape (1) FOREACH agents
«EXPAND CreateScape (1) FOR rootActivity
«ENDIF
«IF (rootActivity != null)-»
«EXPAND CreateScape (2) FOREACH agents
«EXPAND CreateScape (2) FOR rootActivity
«ENDIF
«EXPAND metaabm::tmpl::Java::Builder FOREACH projections
«EXPAND metaabm::tmpl::Java::Builder FOREACH agents
createExtensions(this);
}
/**
* <!-- begin-user-doc -->
* Creates UI views for «label».
* <!-- end-user-doc -->
* @generated
*/
public void createGraphicViews() {
super.createGraphicViews();
«IF (rootActivity != null)-»
«EXPAND ViewBuilder FOR rootActivity
«ENDIF
}
«EXPAND metaabm::tmpl::Java::GenerateComment»
public void scapeSetup(ScapeEvent scapeEvent) {
//Set the size of the scape populations, e.g. for mutable scapes that need to have their size reset
«EXPAND metaabm::tmpl::Java::ProtectedRegion("ScapeSetup"
«IF (rootActivity != null)-»
«EXPAND Setup FOR rootActivity
«ENDIF
}
«FOREACH agents AS agent
«IF !agent.isHost()-»
/**
* <!-- begin-user-doc -->
* Returns the Scape containing «agent.pluralLabel».
* <!-- end-user-doc -->
* @generated
*/
public org.ascape.model.Scape «agent.getterName()»Scape() {
return «agent.scape()»;
}
«ENDIF
«ENDFOREACH
«ENDDEFINE»
«DEFINE NameAccessor FOR SAgent
«EXPAND metaabm::tmpl::Java::GenerateComment»
public String getName() {
if (name == null) {
return "«label» " + getUID();
} else {
return name;
}
}
«ENDDEFINE»
«DEFINE Conditional (List[metaabm::act::AAct] path, Boolean inner) FOR AAct
«IF conditionForAscape()-»
Conditional «selector().id()»Condition = new Conditional() {
private static final long serialVersionUID = 1L;
public boolean meetsCondition(Object «selector().id()»Cell) {
«IF findFromHost()-»
«selector().id()»Cell = «converted(selector().id() + "Cell")»;
«ENDIF
if selector().id()»Cell instanceof «selector().typeName()») {
«IF conditionForState().size > 0
«selector().typeName()» «selector().id()» = selector().typeName()») «selector().id()»Cell;
«EXPAND metaabm::tmpl::Java::InnerEvaluation(path, false)-»
return «conditionForState().toList().expressionSink(path, false)»;
«ELSE
return true;
«ENDIF
} else {
return false;
}
}
};
«ENDIF-»«ENDDEFINE»
«DEFINE BeginQuerySingle (List[metaabm::act::AAct] path, Boolean inner) FOR AAct
«IF convert()-»
final Location «selector().id()»Location = «findAgentStatement(path)»;
if selector().id()»Location != null) {
final «selector().typeName()» «selector().id()» = selector().typeName()») «converted(selector().id() + "Location")»;
«ELSE
final «selector().typeName()» «selector().id()» = selector().typeName()») «findAgentStatement(path)»;
«ENDIF
if selector().id()» «metaType != ANone ? "!=" : "=="» null) {
«IF expression(path, inner) != "" && hasControl("here") && !selector().isRoot()-»
if expression(path, inner)») {
«ENDIF
«ENDDEFINE»
«DEFINE BeginQuerySingle (List[metaabm::act::AAct] path, Boolean inner) FOR ANone
«ENDDEFINE»
«DEFINE BeginQuery (List[metaabm::act::AAct] path, Boolean inner) FOR AAct
«IF findIsList()-»
final List «selector().id()»List = «findStatement(path)»;
for(Object next«selector().id().toFirstUpper()» : «selector().id()»List) {
«ENDIF
«EXPAND BeginQuerySingle(path, inner)-»
«ENDDEFINE»
«DEFINE EndQuery (List[metaabm::act::AAct] path, Boolean inner) FOR AAct
«IF findIsList()-»}«ENDIF
«IF convert()-»}«ENDIF
«IF expression(path, inner) != "" && hasControl("here") && !selector().isRoot()-»}«ENDIF
}
«ENDDEFINE»
«DEFINE EndQuerySingle (List[metaabm::act::AAct] path, Boolean inner) FOR ANone
«ENDDEFINE»
«DEFINE BeginSerial(List[AAct] path, Boolean inner) FOR AControl
«IF selector().isRoot() && selector().agent.isHost() && !controlFunctions({"available", "withinBoundaries"}).isEmpty
if EXPAND metaabm::tmpl::Java::FunctionInnerBlock(path, false) FOREACH controlFunctions({"available", "withinBoundaries"}) SEPARATOR "&&"-») {
«ENDIF-»«ENDDEFINE»
«DEFINE EndSerial(List[AAct] path, Boolean inner) FOR AControl
«IF selector().isRoot() && selector().agent.isHost() && !controlFunctions({"available", "withinBoundaries"}).isEmpty-»}
«ENDIF
«ENDDEFINE»
«DEFINE Setup FOR ACreateAgents
«IF !agent.isHost()-»
«agent.scape()».setSizeagentCount.bind({}, false)»);
«ENDIF
«ENDDEFINE»
«DEFINE Setup FOR IAct-»«ENDDEFINE»
«DEFINE Setup FOR AGroup
«EXPAND Setup FOREACH roots.typeSelect(ABuild).targets
«ENDDEFINE»
«DEFINE SetDimension FOR SNDimensional
«IF dimensionality == 1
«fieldName()».setExtent(new «coordinateType()»(«getterName()»Length()));
«ELSEIF dimensionality == 2
«fieldName()».setExtent(new «coordinateType()»(«getterName()»Width(), «getterName()»Height()));
«ELSEIF dimensionality == 3
«fieldName()».setExtent(new «coordinateType()»(«getterName()»XExtent(), «getterName()»YExtent(), «getterName()»ZExtent()));
«ENDIF
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR ACreateAgents
«IF stage == 0
«IF !agent.isHost()-»
«agent.scape()».setSizeagentCount.bind({}, false)»);
«ENDIF
«ENDIF
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR ABuildSpace
«IF stage == 0
«projection.fieldName()» = new Scape(new «projection.spaceClass()»());
«projection.fieldName()».setName("«projection.pluralLabel»");
«EXPAND SetDimension FOR (SNDimensional) projection»
((CollectionSpace) «projection.fieldName()».getSpace()).setPeriodicprojection.periodic()»);
«projection.fieldName()».setPrototypeAgent(new «agents.get(0).typeName()»());
«FOREACH agents AS spaceAgent»
«REM»NOTE: if agent belongs to more than one space Ascape cannot support thatENDREM»
«spaceAgent.scape()».setSpace(new org.ascape.model.space.SubContinuous2D());
«spaceAgent.scape()».setSuperScapeprojection.fieldName()»);
«ENDFOREACH»
addprojection.fieldName()»);
«ENDIF-»«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR ABuildNetwork
«IF stage == 0
«projection.fieldName()» = new Scape(new «projection.spaceClass()»());
«projection.fieldName()».setName("«projection.pluralLabel»");
addprojection.fieldName()»);
«ENDIF
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR ABuildGrid
«IF stage == 0
«projection.fieldName()» = new Scape(new «projection.spaceClass()»());
«projection.fieldName()».setExecutionOrder(Scape.RULE_ORDER);
«fillAgentType()» proto«fillAgentType()» = new «fillAgentType()»();
«projection.fieldName()».setPrototypeAgent(proto«fillAgentType()»);
«EXPAND SetDimension FOR (SNDimensional) projection»
«projection.fieldName()».setName("«projection.pluralLabel»");
«IF projection.periodic() != ""
((CollectionSpace) «projection.fieldName()».getSpace()).setPeriodicprojection.periodic()»);
«ENDIF
addprojection.fieldName()»);
«IF fillAgent != null
org.ascape.model.Scape «fillAgent.fieldName()» = «projection.id()»;
createExtensions(proto«fillAgentType()»);
«ENDIF
«IF fillAgent.metaType == SContext
«projection.fieldName()».setAutoCreate(false);
«projection.fieldName()».createScape();
«ENDIF
«ELSEIF stage == 1
«FOREACH agents AS agent
«agent.proto()».setHostScapeprojection.fieldName()»);
«ENDFOREACH
«IF fillAgent == null || ((AGroup) fillAgent.rootActivity).members.isEmpty
«projection.fieldName()».getRules().clear();
«ENDIF
«ENDIF
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR SAgent
«IF !isHost()-»
«IF stage == 0
«typeName()» «proto()» = create«typeName()»Prototype();
«scape()» = new Scape();
«scape()».setName("«pluralLabel»");
«scape()».setPrototypeAgentproto()»);
«scape()».setExecutionOrder(Scape.RULE_ORDER);
«ELSEIF stage == 1»
addscape()»);
«ELSEIF stage == 2»
«EXPAND StatBuilder
«IF metaType == SContext
«scape()».setAutoCreate(false);
«scape()».createScape();
«ENDIF
«ENDIF
«ELSE»
«IF stage == 2
«EXPAND StatBuilder FOREACH attributes
«ENDIF
«ENDIF
«IF !isHost()»
createExtensionsproto()»);
«ENDIF»
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR AGroup
«EXPAND CreateScape(stage) FOREACH roots.typeSelect(ABuild).targets.orderBuild()-»
«ENDDEFINE»
«DEFINE CreateScape(int stage) FOR IAct-»«ENDDEFINE»
«DEFINE StatBuilderBody(SAttribute outer, String mod) FOR SAttribute
public final «statSig()»(Object «parent().id()») {
return «mod» «expression((List[AAct]) {}, true)»;
}
«ENDDEFINE»
«DEFINE StatBuilderInner(SAttribute outer) FOR SAttribute
«IF outer.sType == SAttributeType::Boolean
«EXPAND StatBuilderAdd (outer, "", "")-»
«EXPAND StatBuilderAdd (outer, "!", "Not")-»
«ENDIF
«ENDDEFINE»
«DEFINE StatBuilderInner(SState outer) FOR SAttribute
«FOREACH outer.options AS option
«EXPAND StatBuilderAdd (outer, option.typeName() + " == ", option.label)-»
«ENDFOREACH»
«ENDDEFINE»
«DEFINE StatBuilder FOR SAgent
«IF genStats() != "none"
«IF parent != null
«scape()».addStatCollector(new org.ascape.util.data.StatCollectorCondscape()».getName() + " Population") {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
public final boolean meetsCondition(Object object) {return true;}
});
«ENDIF
«EXPAND StatBuilder FOREACH attributes
«ENDIF
«ENDDEFINE»
«DEFINE StatBuilderBody(SAttribute outer, String mod, String name) FOR SAttribute
«((SAgent) parent()).fieldName()».addStatCollector(new org.ascape.util.data.StatCollector«outer(outer).statCondTerm()»(«name») {
private static final long serialVersionUID = 1L;
«IF outer != this
«EXPAND StatBuilderBody (outer, mod) FOR outer
«ENDIF
«EXPAND StatBuilderBody (outer, !sType.numeric() ? mod : "")-»
});
«ENDDEFINE»
«DEFINE StatBuilderAdd(SAttribute outer, String mod, String desc) FOR SAttribute
«EXPAND StatBuilderBody(outer, mod, statLabel(outer, desc))»
«IF genStats() == "cross"
«EXPAND StatBuilderInner(this) FOREACH parent().attributes.select(a | a.numeric() && a.gatherData)-»
«ENDIF
«ENDDEFINE»
«DEFINE StatBuilder FOR SAttribute
«IF gatherData
«IF numeric()-»
«EXPAND StatBuilderAdd (this, "", "")-»
«ELSEIF boolean()»
«EXPAND StatBuilderAdd (this, "", "is")-»
«EXPAND StatBuilderAdd (this, "!", "is not")-»
«ENDIF
«ENDIF
«ENDDEFINE»
«DEFINE StatBuilder FOR SState
«IF gatherData
«FOREACH options AS option
«EXPAND StatBuilderAdd (this, option.typeName() + " == ", option.label)-»
«ENDFOREACH
«ENDIF
«ENDDEFINE»
«DEFINE ChildBuilder FOR ARule
«reference.scape()».addRule(new Rule("«label»") {
private static final long serialVersionUID = 1L;
«EXPAND metaabm::tmpl::Java::GenerateComment»
public void execute(Agent a) {
((«reference.implementation.qualifiedName») a).«id()»();
}
});
«ENDDEFINE»
«DEFINE ChildBuilderProxy FOR ARule
«reference.fieldName()».addRule(new Rule("«label»") {
private static final long serialVersionUID = 1L;
public void execute(Agent a) {
((«this.typeName()») a.getScape()).«id()»();
}
});
«ENDDEFINE»
«DEFINE ChildBuilder FOR ADiffuse
«reference.scape()».addRuleagent.typeName()».«label.toUpperCase()»_RULE);
«ENDDEFINE»
«DEFINE ChildBuilder FOR AInitialize
«REM»Initialize is automatically invoked by default from framework«ENDREM»
«reference.scape()».addInitialRule(new Rule("«label»") {
private static final long serialVersionUID = 1L;
«EXPAND metaabm::tmpl::Java::GenerateComment»
public void execute(Agent a) {
((«reference.implementation.qualifiedName») a).«id()»();
}
});
«ENDDEFINE»
«DEFINE ChildBuilderProxy FOR AInitialize
«reference.scape()».addInitialRule(new Rule("«label»") {
private static final long serialVersionUID = 6846144446402098981L;
public void execute(Agent a) {
((«this.typeName()») a.getScape()).«id()»();
}
});
«ENDDEFINE»
«DEFINE ChildBuilder FOR AGroup
«EXPAND ChildBuilder FOREACH roots
«ENDDEFINE»
«DEFINE ChildBuilder FOR IAct-»«ENDDEFINE»
«DEFINE ChildBuilderProxy FOR IAct-»«ENDDEFINE»
«DEFINE ChildBuilderProxy FOR AGroup
«EXPAND ChildBuilderProxy FOREACH roots
«ENDDEFINE»
«DEFINE ViewBuilder FOR IAct-»«ENDDEFINE»
«DEFINE ViewBuilder FOR AGroup
«EXPAND ViewBuilder FOREACH members
«ENDDEFINE»
«DEFINE ViewBuilder FOR ABuildGrid
«ENDDEFINE»
«DEFINE InnerBlockCall(List[metaabm::act::AAct] path, Boolean inner) FOR AMove
«IF destination.space.metaType == SGrid && (destination.agent == null || destination.agent.isHost())-»
if selected.asAgent().pre()»getHostScape() != ((Agent) «destination.selid().expl()»).getScape()) {
die();
«selected.agent.owner.getterName()»().get«selected.agent.scape().toFirstUpper()»().addselected.asAgent().expl()»);
}
«ENDIF-»«call(path, inner
«ENDDEFINE»
«REM»«AROUND metaabm::tmpl::Java::Evaluation(*) FOR Object»«LET timesec() AS start»«targetDef.proceed()»//«timelapse(start)»«ENDLET»«ENDAROUND»«ENDREM»