1. We delete the groovy files because we want to build a JAVA model;
2. After creating the first agent - bug - we create a private pointer to the gris - the projection.
Note: Projection vs. Context vs. Agent
Context represent a "soup" where the agents have no concept of space or relation. But it provides the basic infrastructure to define a population and the interactions of the population. A context can have a state with behaviors associated with it (e.g. A crop model for a context representing a framing village). More complex or adaptive behaviors can be applied giving to the context an agent-like quality. Moreover contexts can have sub-contexts. In a farming village a family can be a sub-context. A member of a sub-context is a member of the parent context.
A Context contains Agents.
A Context contains Agents.
Projections are data estrutures designed to define and enfoque relationships between proto-agents within a given context. PRojections are added to a Context to allow the proto-agents to interact with one another. They have a many-to-one relationships with Contexts. Switching between Projections is simple. No changes are required with respect to the proto-agent code for a Projection to be able to work with that proto-agent.
3. To define the Context, the "StupidModelContextBuilder" class is created. It implements the ContextBuilder<Object>. We add an ID to the Context. This class creates the context itself. We just have to define a projection.
It defines the type of the projection (continuous space) and uses a pointer to the context.
4. When adding an agent to the context, it receives a random value of X and Y because the function used to add the agents is the RandomCartesianAdder. But, additionally, a grid is added (another projection). The agents are not added the Grid automatically. They use the class SimpleGridAdder.
5. We create a context with two projections: A 2D space and a Grid projections. The visualization is selected only for the Grid.
3. To define the Context, the "StupidModelContextBuilder" class is created. It implements the ContextBuilder<Object>. We add an ID to the Context. This class creates the context itself. We just have to define a projection.
final ContinuousSpace<Object> space = ContinuousSpaceFactoryFinder .createContinuousSpaceFactory(null) .createContinuousSpace( Constants.SPACE_ID, context, new RandomCartesianAdder<Object>(), new repast.simphony.space.continuous.WrapAroundBorders(), Constants.GRID_SIZE, Constants.GRID_SIZE);
It defines the type of the projection (continuous space) and uses a pointer to the context.
4. When adding an agent to the context, it receives a random value of X and Y because the function used to add the agents is the RandomCartesianAdder. But, additionally, a grid is added (another projection). The agents are not added the Grid automatically. They use the class SimpleGridAdder.
for (int i = 0; i < Constants.BUG_COUNT; ++i) { final Bug bug = new Bug(grid); context.add(bug); final NdPoint pt = space.getLocation(bug); grid.moveTo(bug, (int) pt.getX(), (int) pt.getY()); } return context;
5. We create a context with two projections: A 2D space and a Grid projections. The visualization is selected only for the Grid.