/** * @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()); }
/** * * @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(); }
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; }
private Stream<Operation> foundNeighbors(final Node<T> center, final Neighborhood<T> oldNeighborhood, final Neighborhood<T> newNeighborhood) { return newNeighborhood.getNeighbors().stream() .filter(neigh -> oldNeighborhood == null || !oldNeighborhood.contains(neigh)) .filter(neigh -> !getNeighborhood(neigh).contains(center)) .map(n -> new Operation(center, n, true)); }
/** * 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 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)); } }
@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); }
onView.keySet().parallelStream() .map(neighbors::get) .flatMap(neigh -> neigh.getNeighbors().parallelStream() .map(node -> node.compareTo(neigh.getCenter()) > 0 ? new Pair<>(neigh.getCenter(), node)
final List<Node<Double>> l = env.getNeighborhood(thisNode).getNeighbors().stream() .filter(n -> n instanceof EnvironmentNode && n.contains(biomol)) .collect(Collectors.toList());