private void addExtendedNeighborhoodReactions(final Set<Reaction<T>> list, final Reaction<T> r) { for (final Node<T> n : env.getNeighborhood(r.getNode())) { for (final Node<T> neigh : env.getNeighborhood(n)) { for (final Reaction<T> or : neigh) { /* * If the reaction is not the current and it is already in this * graph */ if (or != r && hndlrs.containsKey(or)) { // NOPMD by danysk on 8/20/13 2:37 PM list.add(or); } } } } }
private void addNeighborhoodReactions(final Set<Reaction<T>> list, final Reaction<T> r) { for (final Node<T> n : env.getNeighborhood(r.getNode())) { for (final Reaction<T> or : n) { /* * If the reaction is already in this graph */ if (hndlrs.containsKey(or)) { list.add(or); } } } }
@Override public boolean isValid() { if (neigh.isEmpty()) { return false; } else { final Neighborhood<Double> neighborhood = environment.getNeighborhood(getNode()); return neigh.entrySet().stream() .filter(n -> n.getKey() instanceof CellNode) .allMatch(n -> neighborhood.contains(n.getKey()) && n.getKey().getConcentration(mol) >= conc); } }
/** * * @return a list containing the environment nodes around */ protected List<EnvironmentNode> getEnvironmentNodesSurrounding() { return (List<EnvironmentNode>) env.getNeighborhood(getNode()).getNeighbors().stream() .parallel() .flatMap(n -> n instanceof EnvironmentNode ? Stream.of((EnvironmentNode) n) : Stream.empty()) .collect(Collectors.toList()); }
@Override public boolean isValid() { return environment.getNeighborhood(getNode()).getNeighbors().stream() .parallel() .filter(n -> n instanceof EnvironmentNode) .findAny() .isPresent(); }
@Override public boolean isValid() { return env.getNeighborhood(getNode()).getNeighbors().stream() .parallel() .filter(n -> n instanceof CellNode) .findAny() .isPresent(); }
/** * @return a list of EnvironmentNodes near to the node where this condition is located. */ protected final List<Node<Double>> getEnviromentNodesSurrounding() { return environment.getNeighborhood(getNode()).getNeighbors().stream() .parallel() .filter(n -> n instanceof EnvironmentNode) .collect(Collectors.toList()); }
private static <T> boolean commonNeighbor(final Environment<T> env, final Neighborhood<T> sl, final Node<T> t) { for (final Node<T> n : sl) { if (env.getNeighborhood(n).getNeighbors().contains(t)) { return true; } } return false; }
/** * Searches in the whole neighborhood of the current node which neighbors satisfy the condition, and * returns a list of this neighbors. * @return a map of neighbors which satisfy the condition and their propensity */ public Map<Node<T>, Double> getValidNeighbors() { return getValidNeighbors(env.getNeighborhood(getNode()).getNeighbors()); }
@Override protected void updateInternalStatus(final Time curTime, final boolean executed, final Environment<Double> env) { if (neighborConditionsPresent) { validNeighbors.clear(); validNeighbors = env.getNeighborhood(node).getNeighbors().stream().collect(Collectors.<Node<Double>, Node<Double>, Double>toMap( n -> n, n -> 0d)); for (final Condition<Double> cond : getConditions()) { if (cond instanceof AbstractNeighborCondition) { validNeighbors = intersectMap(validNeighbors, ((AbstractNeighborCondition<Double>) cond).getValidNeighbors(validNeighbors.keySet())); if (validNeighbors.isEmpty()) { // maybe speedup the check break; } } } } super.updateInternalStatus(curTime, executed, env); }
@Override public void execute() { final Neighborhood<Double> neighborhood = env.getNeighborhood(getNode()); final List<Integer> validTargetsIds = new ArrayList<>(); if (delta < 0) { neighborhood.getNeighbors().stream() .filter(n -> n instanceof CellNode && n.getConcentration(mol) >= delta) .mapToInt(n -> n.getId()) .forEach(i -> validTargetsIds.add(i)); } else { neighborhood.getNeighbors().stream() .filter(n -> n instanceof CellNode && n.getConcentration(mol) >= delta) .mapToInt(n -> n.getId()) .forEach(i -> validTargetsIds.add(i)); } if (!validTargetsIds.isEmpty()) { final int targetId = validTargetsIds.get(getRandomGenerator().nextInt(validTargetsIds.size())); execute(neighborhood.getNeighborByNumber(targetId)); } }
private void update(final Environment<T> env, final Time time) { if (Thread.holdsLock(env)) { if (envHasMobileObstacles(env)) { loadObstacles(env); } lasttime = time.toDouble(); currentEnv = env; accessData(); positions.clear(); neighbors.clear(); env.getNodes().parallelStream().forEach(node -> { positions.put(node, env.getPosition(node)); try { neighbors.put(node, env.getNeighborhood(node).clone()); } catch (Exception e) { L.error("Unable to clone neighborhood for " + node, e); } }); releaseData(); repaint(); } else { throw new IllegalStateException("Only the simulation thread can dictate GUI updates"); } }
/** * Simulates the arrival of the message to other nodes. * * @param currentTime * the current simulation time (used to understand when a message * should get dropped). */ public void simulateMessageArrival(final double currentTime) { assert toBeSent != null; Objects.requireNonNull(toBeSent); if (!toBeSent.isEmpty()) { final MessageInfo msg = new MessageInfo(currentTime, node, toBeSent); env.getNeighborhood(node).forEach(n -> { if (n instanceof ProtelisNode) { final AlchemistNetworkManager destination = ((ProtelisNode) n).getNetworkManager(prog); if (destination != null) { /* * The node is running the program. Otherwise, the * program is discarded */ destination.receiveMessage(msg); } } }); } toBeSent = null; }
@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)); } }
/** * Execute the action on a random neighbor if the node has a neighborhood. Otherwise do nothing. */ @Override public void execute() { final Neighborhood<T> neighborhood = env.getNeighborhood(node); if (!neighborhood.isEmpty()) { execute(neighborhood.getNeighborByNumber(getRandomGenerator().nextInt(neighborhood.size()))); } }
/** * This method checks if there may be a dependency considering the * neighborhoods */ private static <T> boolean influenceNeighborCheck(final Environment<T> env, final Reaction<T> source, final Reaction<T> target, final Context in, final Context out) { final Neighborhood<T> sn = env.getNeighborhood(source.getNode()); final boolean scn = in.equals(Context.NEIGHBORHOOD); // If source reads from neighborhood and target is within if (scn && sn.contains(target.getNode())) { return true; } // If target writes in neighborhood and source is within final Neighborhood<T> tn = env.getNeighborhood(target.getNode()); final boolean tcn = out.equals(Context.NEIGHBORHOOD); if (tcn && tn.contains(source.getNode())) { return true; } // If source writes on the neighborhood, target reads on its // neighborhood and there is at least one common node return scn && tcn && commonNeighbor(env, sn, target.getNode()); }
final List<Node<Double>> l = env.getNeighborhood(thisNode).getNeighbors().stream() .filter(n -> n instanceof EnvironmentNode && n.contains(biomol)) .collect(Collectors.toList());