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); } } } } }
/** * @return the device position, in form of {@link Position} */ public Position getDevicePosition() { return env.getPosition(node); }
/** * Computes the distance between two nodes, through * {@link Environment#getDistanceBetweenNodes(Node, Node)}. * * @param target * the target device * @return the distance */ public double distanceTo(final DeviceUID target) { assert target instanceof ProtelisNode; return env.getDistanceBetweenNodes(node, (ProtelisNode) target); }
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"); } }
final List<Node<Double>> l = env.getNeighborhood(thisNode).getNeighbors().stream() .filter(n -> n instanceof EnvironmentNode && n.contains(biomol)) .collect(Collectors.toList()); thisNode.addPolarization(new Continuous2DEuclidean(0, 0)); } else { final boolean isNodeOnMaxConc = env.getPosition(l.stream() .max((n1, n2) -> Double.compare(n1.getConcentration(biomol), n2.getConcentration(biomol))) .get()).equals(env.getPosition(thisNode)); if (isNodeOnMaxConc) { thisNode.addPolarization(new Continuous2DEuclidean(0, 0));
private double getTotalQuantity() { double quantityInEnvNodes = 0; if (!getEnviromentNodesSurrounding().isEmpty()) { quantityInEnvNodes = getEnviromentNodesSurrounding().stream() .parallel() .mapToDouble(n -> n.getConcentration(getBiomolecule())) .sum(); } double quantityInLayers = 0; final Optional<Layer<Double>> layer = environment.getLayer(getBiomolecule()); if (layer.isPresent()) { quantityInLayers = layer.get().getValue(environment.getPosition(getNode())); } return quantityInEnvNodes + quantityInLayers; }
this.status = ViewStatus.DELETING; for (final Node<T> n : selectedNodes) { currentEnv.removeNode(n); final Simulation<T> sim = currentEnv.getSimulation(); sim.schedule(() -> update(currentEnv, sim.getTime())); resetStatus(); bindKey(KeyEvent.VK_M, () -> setMarkCloserNode(!isCloserNodeMarked())); bindKey(KeyEvent.VK_L, () -> setDrawLinks(!paintLinks)); bindKey(KeyEvent.VK_P, () -> Optional.ofNullable(currentEnv.getSimulation()) .ifPresent(sim -> { if (sim.getStatus() == Status.RUNNING) {
private void finalizeConstructor() { for (final Node<T> n : env.getNodes()) { for (final Reaction<T> r : n.getReactions()) { scheduleReaction(r); } } }
@Override public Field nbrRange() { final boolean useRoutesAsDistances = env instanceof MapEnvironment<?> && node.contains(USE_ROUTES_AS_DISTANCES); return buildFieldWithPosition(p -> { if (useRoutesAsDistances) { if (node.contains(APPROXIMATE_NBR_RANGE)) { try { final double tolerance = (double) node.getConcentration(APPROXIMATE_NBR_RANGE); final double currTime = env.getSimulation().getTime().toDouble(); if (currTime > nbrRangeTimeout) { nbrRangeTimeout = currTime + tolerance; precalcdRoutingDistance = routingDistance(p); } assert !Double.isNaN(precalcdRoutingDistance); return precalcdRoutingDistance; } catch (final ClassCastException e) { throw new IllegalStateException(APPROXIMATE_NBR_RANGE + " should be associated with a double concentration", e); } } return routingDistance(p); } return getDevicePosition().getDistanceTo(p); }); }
/** * Computes the distance between two nodes, through * {@link Environment#getDistanceBetweenNodes(Node, Node)}. * * @param target * the target device * @return the distance */ public double distanceTo(final int target) { return distanceTo((ProtelisNode) env.getNodeByID(target)); }
@Override public void optimalZoom() { byte zoom = MAX_ZOOM; @SuppressWarnings("unchecked") final Environment<Object> env = (Environment<Object>) getEnvironment(); do { setZoom(zoom); zoom--; } while (zoom > 1 && !env.getNodes().parallelStream() .map(env::getPosition) .map(this::getViewPoint) .allMatch(this::isInsideView)); }
/** * Computes the distance along a map. Requires a {@link MapEnvironment}. * * @param dest * the destination, in form of {@link ProtelisNode} ID. Non * integer numbers will be cast to integers by * {@link Number#intValue()}. * @return the distance on a map */ public double routingDistance(final Number dest) { return routingDistance(env.getNodeByID(dest.intValue())); }
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); } } } }
/** * Computes the distance along a map. Requires a {@link MapEnvironment}. * * @param dest * the destination, in form of a destination node * @return the distance on a map */ public double routingDistance(final Node<Object> dest) { return routingDistance(env.getPosition(dest)); }
.mapToDouble(n -> env.getDistanceBetweenNodes(thisNode, n)) .distinct() .count() == 1; env.getDistanceBetweenNodes(thisNode, n1), env.getDistanceBetweenNodes(thisNode, n2)
@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 stepDone(final Environment<T> env, final Reaction<T> exec, final Time time, final long step) { if (exec == null || exec.getNode().equals(n)) { final StringBuilder sb = new StringBuilder(stringLength); sb.append(POSITION); sb.append('\n'); sb.append(env.getPosition(n)); sb.append("\n\n\n"); sb.append(CONTENT); sb.append('\n'); sb.append(n.getContents().entrySet().stream() .map(e -> e.getKey().getName() + " > " + e.getValue() + '\n') .sorted() .collect(Collectors.joining()) ); sb.append("\n\n\n"); sb.append(PROGRAM); sb.append("\n\n"); for (final Reaction<T> r : n.getReactions()) { sb.append(r.toString()); sb.append("\n\n"); } stringLength = sb.length() + MARGIN; SwingUtilities.invokeLater(() -> { txt.setText(sb.toString()); }); } } }
/** * * @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()); }
private Position weightedAverageVectors(final List<Node<Double>> list, final CellNode thisNode) { Position res = new Continuous2DEuclidean(0, 0); final Position thisNodePos = env.getPosition(thisNode); for (final Node<Double> n : list) { final Position nPos = env.getPosition(n); Position vecTemp = new Continuous2DEuclidean( nPos.getCoordinate(0) - thisNodePos.getCoordinate(0), nPos.getCoordinate(1) - thisNodePos.getCoordinate(1)); final double vecTempModule = FastMath.sqrt(FastMath.pow(vecTemp.getCoordinate(0), 2) + FastMath.pow(vecTemp.getCoordinate(1), 2)); vecTemp = new Continuous2DEuclidean( n.getConcentration(biomol) * (vecTemp.getCoordinate(0) / vecTempModule), n.getConcentration(biomol) * (vecTemp.getCoordinate(1) / vecTempModule)); res = new Continuous2DEuclidean( res.getCoordinate(0) + vecTemp.getCoordinate(0), res.getCoordinate(1) + vecTemp.getCoordinate(1)); } return res; }
/** * @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()); }