private static boolean influences(final Reaction<?> source, final List<? extends Molecule> target) { final List<? extends Molecule> sl = source.getInfluencedMolecules(); if (sl == null || target == null) { return true; } for (final Molecule m : sl) { for (final Molecule mol : target) { if (m == null || mol == null || m.dependsOn(mol)) { return true; } } } return false; }
/** * @return the device position, in form of {@link Position} */ public Position getDevicePosition() { return env.getPosition(node); }
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 PointAdapter(final Position pos) { assert pos.getDimensions() == 2; this.pos = pos; x = pos.getCoordinate(0); y = pos.getCoordinate(1); }
@Override public void nodeAdded(final Node<T> node) { checkCaller(); if (status != Status.INIT) { for (final Reaction<T> r : node.getReactions()) { scheduleReaction(r); } updateDependenciesForOperationOnNode(env.getNeighborhood(node)); } }
private void updateNeighborhood(final Node<T> n) { for (final Reaction<T> r : n.getReactions()) { if (r.getInputContext().equals(Context.NEIGHBORHOOD)) { updateReaction(handlers.get(r)); } } }
private void finalizeConstructor() { for (final Node<T> n : env.getNodes()) { for (final Reaction<T> r : n.getReactions()) { scheduleReaction(r); } } }
@Override public void execute(final Node<Double> targetNode) { targetNode.setConcentration(mol, targetNode.getConcentration(mol) + delta); }
@Override public Double load(final Position dest) { if (env instanceof MapEnvironment<?>) { return ((MapEnvironment<Object>) env).computeRoute(node, dest).length(); } return getDevicePosition().getDistanceTo(dest); } });
/** * Initialize a gradient layer which grows in concentration proportionaly in space. * * @param direction the {@link Position} representing the direction in which the gradient grows (here the positions is considered as a vector) * @param unitVariation unit variation of the gradient * @param offset minimum value of concentration reached by this spatial distribution */ public BiomolGradientLayer(final Position direction, final double unitVariation, final double offset) { this(direction.getCoordinate(0), direction.getCoordinate(1), unitVariation, offset); }
@Override public Double getValue(final Position p) { final double[] cord = p.getCartesianCoordinates(); return (cord[0] * a) + (cord[1] * b) + c; }
/** * Parses a {@link String}, and depending on the incarnation provides a * {@link Molecule}. * * @param s * the {@link String} to parse * @return an {@link Molecule} created parsing the passed {@link String} */ public Molecule createMolecule(final String s) { return incarnation.createMolecule(s); }
/** * 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 double getDiameterFromCell(final Optional<? extends CellWithCircularArea> biggest) { return biggest .transform(n -> n instanceof CircularDeformableCell ? ((CircularDeformableCell) n).getMaxDiameter() : n.getDiameter()) .or(0d); } }
/** * @param env * the current environment * @param <N> * positions * @param <D> * distances * @return true if env is subclass of {@link Environment2DWithObstacles} * and has mobile obstacles */ protected static <N extends Number, D extends Number> boolean envHasMobileObstacles(final Environment<?> env) { return env instanceof Environment2DWithObstacles && ((Environment2DWithObstacles<?, ?>) env).hasMobileObstacles(); }
private double getEnvRatio() { final double[] size = model.getSize(); return size[0] / size[1]; }
/** * 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 protected boolean isAllowed(final Position p) { return (p.getCoordinate(0) < maxX && p.getCoordinate(0) > minX && p.getCoordinate(1) < maxY && p.getCoordinate(1) > minY); }