private void updateNeighborhood(final Node<T> n) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.NEIGHBORHOOD)) { updateReaction(handlers.get(r)); } } }
private void updateDependenciesForOperationOnNode(final Neighborhood<T> oldNeighborhood) { /* * A reaction in the neighborhood may have changed due to the content of * this new node. Must check. */ for (final Node<T> n : oldNeighborhood) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.NEIGHBORHOOD)) { updateReaction(handlers.get(r)); } } } /* * It is possible that some global reaction is changed due to the * creation of a new node. Checking. */ for (final Node<T> n : env) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.GLOBAL)) { updateReaction(handlers.get(r)); } } } }
private boolean mayInfluence(final Reaction<T> source, final Reaction<T> target) { final Context in = target.getInputContext(); final Context out = source.getOutputContext(); if (// Same node target.getNode().equals(source.getNode()) // If reaction writes something globally || out.equals(Context.GLOBAL) // If reaction reads something globally || in.equals(Context.GLOBAL)) { return true; } return influenceNeighborCheck(env, source, target, in, out); }
private void createDependencies(final DependencyHandler<T> newHandler, final Reaction<T> newReaction) { /* * Will contain the reactions potentially influencing the new one */ final Iterable<Reaction<T>> inputCandidates = initCandidates(newReaction, newReaction.getInputContext()); /* * Will contain the reactions possibly influenced by the new one */ final Iterable<Reaction<T>> outputCandidates = initCandidates(newReaction, newReaction.getOutputContext()); /* * keySet() is not guaranteed to preserve the ordering. This can lead to * bad behaviors, since may change the order by which the reactions are * updated, and consequently ruin the predictability */ for (final Reaction<T> r : inputCandidates) { if (mayInfluence(r, newReaction) && influences(r, newReaction.getInfluencingMolecules())) { final DependencyHandler<T> dep = hndlrs.get(r); dep.addOutDependency(newHandler); newHandler.addInDependency(dep); } } for (final Reaction<T> r : outputCandidates) { if (mayInfluence(newReaction, r) && influences(newReaction, r.getInfluencingMolecules())) { final DependencyHandler<T> dep = hndlrs.get(r); newHandler.addOutDependency(dep); dep.addInDependency(newHandler); } } }