import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.network.NetworkFactory; import uchicago.src.sim.network.Node; import uchicago.src.sim.network.Edge; import uchicago.src.sim.network.DefaultNode; import uchicago.src.sim.network.DefaultEdge; import uchicago.src.sim.network.DefaultDrawableEdge; import uchicago.src.sim.network.DefaultDrawableNode; import uchicago.src.sim.util.Random; import uchicago.src.sim.util.SimUtilities; import uchicago.src.sim.space.*; import uchicago.src.sim.engine.*; import uchicago.src.sim.analysis.*; import uchicago.src.sim.gui.NetworkDrawable; import uchicago.src.sim.gui.Drawable; import uchicago.src.sim.gui.Drawable2DNode; // contains Drawable2DNode interface import uchicago.src.sim.gui.SimGraphics; import java.util.Vector; import java.util.ArrayList; import uchicago.src.sim.gui.OvalNetworkItem; import uchicago.src.sim.gui.RectNetworkItem; // Network spaces are handled differently from spatial (discrete/grid or continuous space) models. // Unlike spatial models, the agents are not situated upon spaces, and so do not need to be passed a // reference to a space object in their constructor. // The basic classes of network models are DefaultNode and DefaultEdge. However, to produce displays // for a non-grid network one would use the Network2DDisplay class for the creating the display along // with a List of DrawableNonGridNodes whose edges are of the DrawableEdge type. // Rather than having you implement the DrawableNonGridNode interface, RePast provides the // DefaultDrawableNode class. This class extends DefaultNode, so it contains all the network // functionality described above, but since it also implements DrawableNonGridNode, it can be drawn // with a Network2DDisplay. The actual drawing (as a rectangle, oval or whatever) of a DefaultDrawableNode // is handled by a NetworkDrawable. RePast provide two sorts of NetworkDrawables: a OvalNetworkItem, // and a RectNetworkItem. These will draw your DefaultDrawableNodes as ovals or rectangles respectively. // However, it is *supposed* to be possible to combine both types (i.e. network models and spatial models) // using DrawableNetwork2DGridDisplay displays with Drawable2DNodes and DrawableEdges. Such a node must // extend DefaultDrawable meaning that it is both a DefaultNode and can be Drawable in a Network2DDisplay. // This ID network model does not use spaces so we shall just extend DefaultDrawableNode class to display // our network of firms. public class Firm extends DefaultDrawableNode { private int x_coord, y_coord; // Clients and Subcontractors private ArrayList clients; private ArrayList subcontractors; // Constructor for graph model which creates its own network drawable and sets it public Firm(int x, int y) { this.x_coord = x; this.y_coord = y; RectNetworkItem rect = new RectNetworkItem(x, y); setDrawable(rect); // create the client and subcontractor Vectors clients = new ArrayList(); subcontractors = new ArrayList(); } public void addSubcontractor (DefaultNode node, DefaultEdge edge) { addOutEdge(edge); subcontractors.add(node); } public void addClient (DefaultNode node, DefaultEdge edge) { addInEdge (edge); clients.add(node); } public ArrayList getSubcontractors () { return subcontractors; } public ArrayList getClients () { return clients; } public void removeSubcontractor (DefaultNode node) { subcontractors.remove(node); removeEdgesTo(node); } public void removeClient (DefaultNode node) { clients.remove(node); removeEdgesFrom(node); } }