Class Model

java.lang.Object
  |
  +--swarm.BaseImpl
        |
        +--swarm.objectbase.SwarmImpl
              |
              +--Model
All Implemented Interfaces:
swarm.activity.ActionType, swarm.activity.ActionTypeS, swarm.defobj.Create, swarm.defobj.CreateS, swarm.defobj.Customize, swarm.defobj.CustomizeS, swarm.defobj.DefinedObject, swarm.defobj.DefinedObjectS, swarm.defobj.Drop, swarm.defobj.DropS, swarm.defobj.GetName, swarm.defobj.GetNameS, swarm.objectbase.Swarm, swarm.activity.SwarmProcess, swarm.activity.SwarmProcessS, swarm.objectbase.SwarmS, swarm.activity.SynchronizationType, swarm.activity.SynchronizationTypeS, swarm.defobj.Zone, swarm.defobj.ZoneS

public class Model
extends swarm.objectbase.SwarmImpl

The Model class has methods that build objects and it also tells them to do things. Please note the use of both Lists and Sets here. For each student, it creates a set of "contacts" that serves an important role in the Student class. Note also that when a crime occurs, a Policeman is created and told to investigate.


Constructor Summary
Model(swarm.defobj.Zone aZone, int n)
          Creates a new Model instance.
 
Method Summary
 swarm.activity.Activity activateIn(swarm.objectbase.Swarm swarmContext)
          Describe activateIn method here.
 java.lang.Object buildActions()
          We want to repeatedly process the list of agents.
 java.lang.Object buildObjects()
          Create a List and fill it with N student objects.
 void checkAgents()
          Tell the agents to sayHi
 java.lang.Object checkForCrime()
          Randomly designate some student as the criminal, give his fingerprint to a policeman, and tell the policeman to conduct the investigation.
 java.lang.Object getStudentList()
           
 java.lang.Object go()
          A go method is needed because we need to run the activity structure that was created in buildActions() and put into the time scheme by activateIn().
 
Methods inherited from class swarm.objectbase.SwarmImpl
allocIVars, allocIVarsComponent, compare, copyIVars, copyIVarsComponent, describe, describeForEach, describeForEachID, describeID, drop, freeIVars, freeIVarsComponent, getActivity, getCompleteProbeMap, getComponentZone, getDisplayName, getInternalZone, getName, getPageSize, getPopulation, getProbeForVariable, getProbeMap, getSynchronizationType, getTypeName, getZone, perform, perform$with, perform$with$with, perform$with$with$with, respondsTo, setDisplayName, xfprint, xfprintid, xprint, xprintid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model(swarm.defobj.Zone aZone,
             int n)
Creates a new Model instance.
Parameters:
aZone - a Zone value
n - an int value
Method Detail

buildObjects

public java.lang.Object buildObjects()
Create a List and fill it with N student objects. Then, for each student, create a container for contacts, and randomly choose agents from the agentList to go into the contact list Swarm class requires the return type be Object, so we have to change the return type and add a "return this"
Overrides:
buildObjects in class swarm.objectbase.SwarmImpl
Returns:
an Object value

checkAgents

public void checkAgents()
Tell the agents to sayHi

checkForCrime

public java.lang.Object checkForCrime()
Randomly designate some student as the criminal, give his fingerprint to a policeman, and tell the policeman to conduct the investigation. The results are announced in a printout to System.out.
Returns:
an Object value

buildActions

public java.lang.Object buildActions()
We want to repeatedly process the list of agents. Instead of a simple for loop, we will use a Swarm schedule setup. This is a "bare" "empty" schedule, and you add actions to it by giving a "time", an agent to do the action, and a "selector" that represents the method to be executed. The term Selector is from Objective-C. It refers to the "symbolic handle" (my term) that the compiler has for a method. For example, we want the agents to run their step method, so we get a "handle" for it by creating a Selector. Then when we throw the action onto the schedule, we use the Selector because the schedule mechanism knows how to handle that. In order to create Selector objects, we are required to use Java exception handling mechanisms. That requires a pair, try {}catch(){}. I don't know much about that, just what Bruce Eckle's Thinking in Java covers. This seems like a lot of trouble. A "for loop" is as good in the simplest case, but not in the complicated case, so we want to build up power.
Overrides:
buildActions in class swarm.objectbase.SwarmImpl
Returns:
an Object value

activateIn

public swarm.activity.Activity activateIn(swarm.objectbase.Swarm swarmContext)
Describe activateIn method here.
Overrides:
activateIn in class swarm.objectbase.SwarmImpl
Parameters:
swarmContext - a Swarm value
Returns:
an Activity value

go

public java.lang.Object go()
A go method is needed because we need to run the activity structure that was created in buildActions() and put into the time scheme by activateIn(). You may see some Swarm models with a graphical interface in which a go method need not be explicitly created, and they get away with that by using a top level swarm from the GUISwarm class. Here, were are just using Swarm, and no GUI controls are available.
Returns:
an Object value

getStudentList

public java.lang.Object getStudentList()