@Override public Neighborhood<T> getNeighborhood(@Nonnull final Node<T> center) { return neighCache.get(Objects.requireNonNull(center).getId()); }
/** * * @param x x coord * @param y y coord */ protected void setDist(final int x, final int y) { if (wormhole != null) { mousex = x; mousey = y; final Position envMouse = wormhole.getEnvPoint(new Point(mousex, mousey)); final StringBuilder sb = new StringBuilder(); sb.append(envMouse); if (nearest != null) { sb.append(" -- "); sb.append(LocalizedResourceBundle.getString("nearest_node_is")); sb.append(": "); sb.append(nearest.getId()); } setToolTipText(sb.toString()); } }
private Queue<Operation> recursiveOperation(final Node<T> origin) { final Neighborhood<T> newNeighborhood = rule.computeNeighborhood(Objects.requireNonNull(origin), this); final Neighborhood<T> oldNeighborhood = neighCache.put(origin.getId(), newNeighborhood); return toQueue(origin, oldNeighborhood, newNeighborhood); }
@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 final void nodeRemoved(final Node<T> node, final Position pos) { assert node != null; /* * Neighborhood update */ final Neighborhood<T> neigh = neighCache.remove(node.getId()); for (final Node<T> n : neigh) { neighCache.get(n.getId()).removeNeighbor(node); } /* * Update all the reactions which may have been affected by the node * removal */ Engine.nodeRemoved(this, node, neigh); /* * Call subclass remover */ nodeRemoved(node, neigh); }
private Queue<Operation> recursiveOperation(final Node<T> origin, final Node<T> destination, final boolean isAdd) { if (isAdd) { Engine.neighborAdded(this, origin, destination); } else { Engine.neighborRemoved(this, origin, destination); } final Neighborhood<T> newNeighborhood = rule.computeNeighborhood(Objects.requireNonNull(destination), this); final Neighborhood<T> oldNeighborhood = neighCache.put(destination.getId(), newNeighborhood); return toQueue(destination, oldNeighborhood, newNeighborhood); }
final Neighborhood<T> oldNeighborhood = neighCache.put(node.getId(), newNeighborhood); if (oldNeighborhood != null) { final Iterator<Node<T>> iter = oldNeighborhood.iterator(); final Neighborhood<T> neighborsNeighborhood = neighCache.get(neighbor.getId()); neighborsNeighborhood.removeNeighbor(node); Engine.neighborRemoved(this, node, neighbor); neighCache.get(n.getId()).addNeighbor(node); Engine.neighborAdded(this, node, n); final Queue<Operation> operations = recursiveOperation(node); final TIntSet processed = new TIntHashSet(getNodesNumber()); processed.add(node.getId()); while (!operations.isEmpty()) { final Operation next = operations.poll(); final Node<T> dest = next.destination; final int destId = dest.getId(); if (!processed.contains(destId)) { operations.addAll(recursiveOperation(next.origin, next.destination, next.isAdd));