@Override public synchronized void play() { newStatus(Status.RUNNING); }
@Override public void nodeAdded(final Node<T> node) { checkCaller(); if (status != Status.INIT) { for (final Reaction<T> r : node.getReactions()) { scheduleReaction(r); } updateDependenciesForOperationOnNode(env.getNeighborhood(node)); } }
@Override public void neighborRemoved(final Node<T> node, final Node<T> n) { checkCaller(); dg.removeNeighbor(node, n); updateNeighborhood(node); updateNeighborhood(n); }
@Override public void nodeRemoved(final Node<T> node, final Neighborhood<T> oldNeighborhood) { checkCaller(); for (final Reaction<T> r : node.getReactions()) { removeReaction(r); } }
@Override public void nodeMoved(final Node<T> node) { checkCaller(); for (final Reaction<T> r : node.getReactions()) { updateReaction(handlers.get(r)); } }
/** * Builds a simulation for a given environment. By default it uses a * DependencyGraph and an IndexedPriorityQueue internally. If you want to * use your own implementations of {@link DependencyGraph} and * {@link ReactionManager} interfaces, don't use this constructor. * * @param e * the environment at the initial time * @param maxSteps * the maximum number of steps to do * @param t * the maximum time to reach */ public Engine(final Environment<T> e, final long maxSteps, final Time t) { L.trace("Engine created"); env = e; env.setSimulation(this); dg = new MapBasedDependencyGraph<T>(env, handlers); ipq = new ArrayIndexedPriorityQueue<>(); this.steps = maxSteps; this.finalTime = t; }
@Override public void createDependencies(final DependencyHandler<T> rh) { createDependencies(rh, rh.getReaction()); }
/** * Checks whether it makes sense or not to continue executing this * simulation in order to evaluate this property. If not, stops the * simulation flow. * * @param env * the environment */ protected void checkForStop(final IEnvironment<?> env) { if (!canChange()) { Simulation.stop(env); } }
@Override public synchronized void schedule(final CheckedRunnable r) { if (getStatus().equals(Status.TERMINATED)) { throw new IllegalStateException("This simulation is terminated and can not get resumed."); } commands.add(r); }
private void finalizeConstructor() { for (final Node<T> n : env.getNodes()) { for (final Reaction<T> r : n.getReactions()) { scheduleReaction(r); } } }
@Override public void moveNodeToPosition(final Node<T> node, final Position newpos) { includeObject(newpos); setPosition(node, newpos); updateNeighborhood(node); Engine.nodeMoved(this, node); }
@Override protected final void nodeAdded(final Node<T> node, final Position p) { assert node != null; assert p != null; /* * Neighborhood computation */ updateNeighborhood(node); /* * Reaction and dependencies creation on the engine. This must be * executed only when the neighborhoods have been correctly computed. */ Engine.nodeAdded(this, node); /* * Call the subclass method. */ nodeAdded(node, p, getNeighborhood(node)); }
@Override public void neighborAdded(final Node<T> node, final Node<T> n) { checkCaller(); dg.addNeighbor(node, n); updateNeighborhood(node); /* * This is necessary, see bug #43 */ updateNeighborhood(n); }
@Override public synchronized void terminate() { newStatus(Status.TERMINATED); }
@Override public synchronized void pause() { newStatus(Status.PAUSED); }