| package sdl.SIR.sd; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.Collections; |
| |
| import org.eclipse.core.runtime.IAdapterFactory; |
| import org.eclipse.amp.agf.IGraphicsAdapted; |
| import org.eclipse.amp.agf.IGraphicsAdapter; |
| |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.jface.viewers.IColorProvider; |
| |
| import org.ascape.model.Agent; |
| import org.ascape.model.Cell; |
| import org.ascape.model.CellOccupant; |
| import org.ascape.model.HostCell; |
| import org.ascape.model.LocatedAgent; |
| import org.ascape.model.Scape; |
| import org.ascape.model.event.ScapeEvent; |
| import org.ascape.model.rule.Rule; |
| import org.ascape.model.rule.ExecuteThenUpdate; |
| import org.ascape.model.space.CollectionSpace; |
| import org.ascape.model.space.Coordinate; |
| import org.ascape.model.space.Coordinate2DDiscrete; |
| import org.ascape.model.space.Graph; |
| import org.ascape.model.space.Location; |
| import org.ascape.model.space.Singleton; |
| import org.ascape.runtime.NonGraphicRunner; |
| import org.ascape.util.Conditional; |
| import org.ascape.util.data.DataPoint; |
| import org.ascape.util.data.DataPointConcrete; |
| import org.ascape.util.vis.ColorFeature; |
| import org.ascape.util.vis.ColorFeatureConcrete; |
| import org.ascape.view.vis.ChartView; |
| import org.ascape.view.vis.GEFView; |
| import org.ascape.view.vis.GraphView; |
| |
| import org.eclipse.amp.escape.runtime.extension.IAgentChild; |
| import org.eclipse.amp.escape.runtime.extension.IAgentChildProvider; |
| |
| import sdl.SIR.sd.sir_SD.SD; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * SIR Java Implementation. |
| * |
| * Generated by AMF for model: SIR.metaabm in project: org.eclipse.amp.amf.examples.sd |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public class SIR extends Scape implements IGraphicsAdapted, IAgentChildProvider { |
| |
| /** |
| * <!-- begin-user-doc --> |
| * The number of sir agents to create. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private int sIRAgentCount = 0; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private List<IAgentChild> children; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public List<IAgentChild> getChildren() { |
| return children; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Constructs a new SIR. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public SIR() { |
| |
| children = new ArrayList<IAgentChild>(); |
| |
| children.add(new SD()); |
| |
| children = new ArrayList<IAgentChild>(); |
| |
| children.add(new SD()); |
| |
| } |
| |
| //todo, make this a useful value for evaluating compatibility of different versions of generated classes |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private static final long serialVersionUID = 89989998L; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private static long nextUniqueID; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private long uniqueID; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public long getUID() { |
| if (uniqueID == 0) { |
| uniqueID = nextUniqueID++; |
| } |
| return uniqueID; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Clones the agent, ensuring that a unique id is assigned. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public Object clone() { |
| try { |
| SIR clone = (SIR) super.clone(); |
| clone.uniqueID = 0; |
| return clone; |
| } catch (Exception e) { |
| throw new RuntimeException("Unexpected cloning exception: " + e); |
| } |
| } |
| |
| org.ascape.model.Scape sIRAgentScape; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Create an instance of SIR Agent that will be used to populate the sIRAgentScape. |
| * Overide to customize the prototype, for example to change the views created for a member scape. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected SIRAgent createSIRAgentPrototype() { |
| SIRAgent sIRAgent = new SIRAgent(); |
| return sIRAgent; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| static int next_vm_id; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| int vm_unique_id; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Creates the members of SIR. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void createScape() { |
| super.createScape(); |
| |
| setName("SIR"); |
| SIRAgent sIRAgentProto = createSIRAgentPrototype(); |
| sIRAgentScape = new Scape(); |
| sIRAgentScape.setName("SIR Agents"); |
| sIRAgentScape.setPrototypeAgent(sIRAgentProto); |
| sIRAgentScape.setExecutionOrder(Scape.RULE_ORDER); |
| |
| createExtensions(sIRAgentProto); |
| |
| sIRAgentScape.setSize(getSIRAgentCount()); |
| |
| add(sIRAgentScape); |
| |
| createExtensions(sIRAgentProto); |
| |
| sIRAgentScape |
| .addStatCollector(new org.ascape.util.data.StatCollectorCond( |
| sIRAgentScape.getName() + " Population") { |
| private static final long serialVersionUID = 1L; |
| @SuppressWarnings("unused") |
| public final boolean meetsCondition(Object object) { |
| return true; |
| } |
| }); |
| |
| createExtensions(sIRAgentProto); |
| |
| createExtensions(this); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Creates UI views for SIR. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void createGraphicViews() { |
| super.createGraphicViews(); |
| createChartViews(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void scapeSetup(ScapeEvent scapeEvent) { |
| //Set the size of the scape populations, e.g. for mutable scapes that need to have their size reset |
| |
| sIRAgentScape.setSize(getSIRAgentCount()); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Returns the Scape containing SIR Agents. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public org.ascape.model.Scape getSIRAgentScape() { |
| return sIRAgentScape; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected void createChartViews() { |
| ChartView chart = new ChartView(); |
| |
| final SIR sIRAgentScape = new SIR(); |
| sIRAgentScape.setRunner(new NonGraphicRunner()); |
| SIRAgent sIRAgent = new SIRAgent() { |
| public void requestUpdate() { |
| } |
| public SIR getSIR() { |
| return sIRAgentScape; |
| } |
| }; |
| sIRAgentScape.add(sIRAgent); |
| HostCell sIRAgentHost = new HostCell() { |
| public void requestUpdate() { |
| } |
| }; |
| sIRAgentHost.setOccupant((CellOccupant) sIRAgent); |
| |
| IColorProvider sIRAgentStyle2DColorProvider = new SIRAgentStyle2DColorProvider(); |
| addView(chart); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected void create2DViews() { |
| addView(new GEFView()); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected void createGraphViews() { |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public IGraphicsAdapter getGraphicsAdapter() { |
| return SIRGraphicsAdapter.getDefault(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| private Color getInferredChartColor(Object agent, |
| IColorProvider colorProvider) { |
| Color color = colorProvider.getForeground(agent); |
| if (color == ColorFeature.BLACK) { |
| color = ColorFeatureConcrete.createHSB( |
| (float) java.lang.Math.random() * 360f, 1.0f, 0.8f); |
| } |
| return color; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public static void main(String[] args) { |
| (new NonGraphicRunner()).openInstance("sdl.SIR.sd.SIR"); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| |
| @Override |
| public void executeOnMembers() { |
| int timeStep = getRunner().getPeriod(); |
| startSimulationAgentChild(timeStep); |
| |
| //A normal movable agent |
| ((SIRAgent) sIRAgentScape.getPrototypeAgent()) |
| .startSimulationAgentChild(timeStep); |
| |
| super.executeOnMembers(); |
| calculateTimeStep(timeStep); |
| |
| //A normal movable agent |
| ((SIRAgent) sIRAgentScape.getPrototypeAgent()) |
| .calculateTimeStep(timeStep); |
| |
| } |
| |
| public void createExtensions(Object object) { |
| if (object instanceof IAgentChildProvider) { |
| for (IAgentChild tmp : ((IAgentChildProvider) object).getChildren()) { |
| tmp.addDataCollectors(this); |
| } |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| |
| public void startSimulationAgentChild(int timeStep) { |
| if (timeStep == getRoot().getRunner().getEarliestPeriod()) { |
| for (IAgentChild tmp : children) { |
| tmp.startSimulation(timeStep); |
| } |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| |
| public void calculateTimeStep(int timeStep) { |
| for (IAgentChild tmp : children) { |
| tmp.calculate(timeStep); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Gets the SIR Agent Count property for SIR. |
| * @return The number of sir agents to create. |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public int getSIRAgentCount() { |
| return sIRAgentCount; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * Sets the SIR Agent Count property for SIR. |
| * The number of sir agents to create. |
| * @param _sIRAgentCount the new SIR Agent Count value |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void setSIRAgentCount(int _sIRAgentCount) { |
| sIRAgentCount = _sIRAgentCount; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public String getName() { |
| if (name == null) { |
| return "SIR " + getUID(); |
| } else { |
| return name; |
| } |
| } |
| } |