private Stream<Operation> lostNeighbors(final Node<T> center, final Neighborhood<T> oldNeighborhood, final Neighborhood<T> newNeighborhood) { return Optional.ofNullable(oldNeighborhood) .map(Neighborhood::getNeighbors) .orElse(Collections.emptyList()) .stream() .filter(neigh -> !newNeighborhood.contains(neigh)) .filter(neigh -> getNeighborhood(neigh).contains(center)) .map(n -> new Operation(center, n, 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)); }
@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); } }
@Override public void moveNode(final Node<Double> node, final Position direction) { if (node instanceof CellNode) { super.moveNode(node, direction); final CellNode nodeToMove = (CellNode) node; final Neighborhood<Double> neigh = getNeighborhood(nodeToMove); final Map<Junction, Map<CellNode, Integer>> jun = nodeToMove.getJunctions(); jun.entrySet().stream().forEach(e -> e.getValue().entrySet().forEach(e2 -> { if (!neigh.contains(e2.getKey())) { // there is a junction that links a node which isn't in the neighborhood after the movement for (int i = 0; i < e2.getValue(); i++) { nodeToMove.removeJunction(e.getKey(), e2.getKey()); e2.getKey().removeJunction(e.getKey().reverse(), nodeToMove); } } })); } }
/** * 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()); }