| «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-» |
| public «owner.typeName()» «owner.getterName()»() { |
| return («owner.typeName()») getScape().getScape(); |
| } |
| «ENDIF-» |
| «IF parent != null && !((SContext) parent).projections.typeSelect(SNetwork).isEmpty-» |
| public java.util.List getNetwork() { |
| return ((Graph) «((SContext) parent).getterName()»().«((SContext) parent).projections.typeSelect(SNetwork).get(0).getterName()»().getSpace()).getNeighborsFor(this); |
| } |
| «ENDIF-» |
| «FOREACH ((AGroup) rootActivity).roots AS root-» |
| «IF root.metaType == ADiffuse» |
| private double «root.id()»Temp; |
| |
| public static final Rule «root.id().toUpperCase()»_RULE = new ExecuteThenUpdate("«root.label»") { |
| private static final long serialVersionUID = 6846144446402098983L; |
| /** |
| * Calculate and store diffusion value to neighbors. |
| * |
| * @param agent |
| * the playing agent |
| */ |
| 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; |
| } |
| /** |
| * Update diffusion value. Occurs only when all diffusion has been |
| * calculated. |
| * |
| * @param agent |
| * the agent |
| */ |
| 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()-» |
| /** |
| * 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. |
| */ |
| protected «agent.typeName()» create«agent.typeName()»Prototype() { |
| return new «agent.typeName()»(); |
| } |
| «ENDIF-» |
| «ENDFOREACH-» |
| |
| static int next_vm_id; |
| |
| int vm_unique_id; |
| |
| /** |
| * Creates the members of «label». |
| */ |
| 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 (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-» |
| «IF rootActivity != null-» |
| «EXPAND metaabm::tmpl::Java::Builder FOR rootActivity-» |
| «ENDIF-» |
| } |
| |
| /** |
| * Creates UI views for «label». |
| */ |
| public void createGraphicViews() { |
| super.createGraphicViews(); |
| «IF (rootActivity != null)-» |
| «EXPAND ViewBuilder FOR rootActivity-» |
| «ENDIF-» |
| } |
| |
| 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()-» |
| /** |
| * Returns the Scape containing «agent.pluralLabel». |
| */ |
| public org.ascape.model.Scape «agent.getterName()»Scape() { |
| return «agent.scape()»; |
| } |
| «ENDIF-» |
| «ENDFOREACH-» |
| «ENDDEFINE» |
| |
| «DEFINE NameAccessor FOR SAgent-» |
| 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 = 6846144446402098985L; |
| 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()-» |
| Location «selector().id()»Location = «findAgentStatement(path)»; |
| if («selector().id()»Location != null) { |
| «selector().typeName()» «selector().id()» = («selector().typeName()») «converted(selector().id() + "Location")»; |
| «ELSE-» |
| «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 BeginQuery (List[metaabm::act::AAct] path, Boolean inner) FOR AAct-» |
| «IF findIsList()-» |
| 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 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()».setSize(«agentCount.id()»); |
| «ENDIF-» |
| «ENDDEFINE» |
| «DEFINE Setup FOR IAct-»«ENDDEFINE» |
| «DEFINE Setup FOR AGroup-» |
| «EXPAND Setup FOREACH members-» |
| «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()».setSize(«agentCount.id()»); |
| «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()).setPeriodic(«projection.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 that.«ENDREM» |
| «spaceAgent.scape()».setSpace(new org.ascape.model.space.SubContinuous2D()); |
| «spaceAgent.scape()».setSuperScape(«projection.fieldName()»); |
| «ENDFOREACH» |
| add(«projection.fieldName()»); |
| «ENDIF-»«ENDDEFINE» |
| «DEFINE CreateScape(int stage) FOR ABuildNetwork-» |
| «IF stage == 0-» |
| «projection.fieldName()» = new Scape(new «projection.spaceClass()»()); |
| «projection.fieldName()».setName("«projection.pluralLabel»"); |
| add(«projection.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); |
| «projection.fieldName()».setPrototypeAgent(new «fillAgentType()»()); |
| «EXPAND SetDimension FOR (SNDimensional) projection» |
| «projection.fieldName()».setName("«projection.pluralLabel»"); |
| «IF projection.periodic() != ""-» |
| ((CollectionSpace) «projection.fieldName()».getSpace()).setPeriodic(«projection.periodic()»); |
| «ENDIF-» |
| add(«projection.fieldName()»); |
| «IF fillAgent != null-» |
| org.ascape.model.Scape «fillAgent.fieldName()» = «projection.id()»; |
| «ENDIF-» |
| «IF fillAgent.metaType == SContext-» |
| «projection.fieldName()».setAutoCreate(false); |
| «projection.fieldName()».createScape(); |
| «ENDIF-» |
| «ELSEIF stage == 1-» |
| «FOREACH agents AS agent-» |
| «agent.proto()».setHostScape(«projection.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()».setPrototypeAgent(«proto()»); |
| «scape()».setExecutionOrder(Scape.RULE_ORDER); |
| «ELSEIF stage == 1» |
| add(«scape()»); |
| «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-» |
| «ENDDEFINE» |
| «DEFINE CreateScape(int stage) FOR AGroup-» |
| «EXPAND CreateScape(stage) FOREACH members.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 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 = 6846144446402098985L; |
| «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 StatBuilder FOR SAgent-» |
| «IF genStats() != "none"-» |
| «scape()».addStatCollector(new org.ascape.util.data.StatCollectorCond(getName() + " Population") { |
| private static final long serialVersionUID = 684614444640209893L; |
| |
| @SuppressWarnings("unused") |
| public final boolean meetsCondition(Object object) {return true;} |
| }); |
| «EXPAND StatBuilder FOREACH attributes-» |
| «ENDIF-» |
| «ENDDEFINE» |
| |
| «DEFINE ChildBuilder FOR ARule-» |
| «reference.scape()».addRule(new Rule("«label»") { |
| private static final long serialVersionUID = 6846144446402098981L; |
| public void execute(Agent a) { |
| ((«reference.implementation.qualifiedName») a).«id()»(); |
| } |
| }); |
| «ENDDEFINE» |
| «DEFINE ChildBuilder FOR ADiffuse-» |
| «reference.scape()».addRule(«agent.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 = 6846144446402098982L; |
| public void execute(Agent a) { |
| ((«reference.implementation.qualifiedName») a).«id()»(); |
| } |
| }); |
| «ENDDEFINE» |
| «DEFINE ChildBuilder FOR AGroup-» |
| «EXPAND ChildBuilder FOREACH roots-» |
| «ENDDEFINE» |
| «DEFINE ChildBuilder FOR IAct-»«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()»().add(«selected.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» |