/** * @return the device position, in form of {@link Position} */ public Position getDevicePosition() { return env.getPosition(node); }
/** * 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)); }
@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()); }); } } }
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; }
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"); } }
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 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; }