@Override public Neighborhood<T> getNeighborhood(@Nonnull final Node<T> center) { return neighCache.get(Objects.requireNonNull(center).getId()); }
@Override public ComputationalRoundComplete cloneCondition(final Node<Object> n, final Reaction<Object> r) { final List<RunProtelisProgram> possibleRefs = n.getReactions().stream() .map(Reaction::getActions) .flatMap(List::stream) .filter(a -> a instanceof RunProtelisProgram) .map(a -> (RunProtelisProgram) a) .collect(Collectors.toList()); if (possibleRefs.size() == 1) { return new ComputationalRoundComplete((ProtelisNode) n, possibleRefs.get(0)); } throw new IllegalStateException("There must be one and one only unconfigured " + RunProtelisProgram.class.getSimpleName()); }
@Override public void execute(final Node<Double> targetNode) { targetNode.setConcentration(mol, targetNode.getConcentration(mol) + delta); }
@Override public double getProperty(final Node<Double> node, final Molecule mol, final String prop) { return node.getConcentration(mol); }
@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)); } }
.filter(n -> n instanceof EnvironmentNode && n.contains(biomol)) .collect(Collectors.toList()); if (l.isEmpty()) { } 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) {
@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()); }); } } }
@Override public boolean has(final String id) { return shadow.has(id) || node.contains(new SimpleMolecule(id)); } @Override
@SuppressWarnings("unchecked") private void buildActionListeners() { concentration.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { concentration.selectAll(); } }); molecule.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { molecule.selectAll(); } }); apply.addActionListener((event) -> { final String mol = molecule.getText(); final String conc = concentration.getText(); final Incarnation<T> currentInc = incarnation.getCurrent(); for (final Node<T> n : affectedNodes) { try { n.setConcentration(currentInc.createMolecule(mol), currentInc.createConcentration(conc)); } catch (Exception | AbstractMethodError e) { L.error("Unable to set new concentration: ", e); } } }); selectedIncr.addActionListener((event) -> incarnation.setCurrent((Incarnation<T>) (selectedIncr.getSelectedItem()))); } }
private CacheKey(final Node<Object> node, final Molecule mol, final String prop) { this.node = new WeakReference<>(node); molecule = mol; property = prop; hash = molecule.hashCode() ^ property.hashCode() ^ (node == null ? 0 : node.hashCode()); } @Override
.map(neighbors::get) .flatMap(neigh -> neigh.getNeighbors().parallelStream() .map(node -> node.compareTo(neigh.getCenter()) > 0 ? new Pair<>(neigh.getCenter(), node) : new Pair<>(node, neigh.getCenter())))
/** * @return true if the concentration of the molecule is higher or equal the * value. */ @Override public boolean isValid() { return getNode().getConcentration(molecule).doubleValue() >= qty .doubleValue(); }
if (!molFilter || (molecule != null && n.contains(molecule))) { final double ks = (scaleFactor.getVal() - MIN_SCALE) * 2 / (double) (SCALE_DIFF); final int sizex = size.getVal();
@Override public SendToNeighbor cloneAction(final Node<Object> n, final Reaction<Object> r) { final List<RunProtelisProgram> possibleRefs = n.getReactions().stream() .map(Reaction::getActions) .flatMap(List::stream) .filter(a -> a instanceof RunProtelisProgram) .map(a -> (RunProtelisProgram) a) .collect(Collectors.toList()); if (possibleRefs.size() == 1) { return new SendToNeighbor((ProtelisNode) n, reaction, possibleRefs.get(0)); } throw new IllegalStateException("There must be one and one only unconfigured " + RunProtelisProgram.class.getSimpleName()); }
@Override public void execute() { super.getNode().setConcentration(getMolecule(), super.getNode().getConcentration(getMolecule()) + deltaC); }
/** * * @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()); } }
@Override public Map<Node<Double>, Double> getValidNeighbors(final Collection<? extends Node<Double>> neighborhood) { propensity = 0; neigh = neighborhood.stream() .filter(n -> n instanceof CellNode && n.getConcentration(mol) >= conc) .collect(Collectors.<Node<Double>, Node<Double>, Double>toMap( n -> n, n -> CombinatoricsUtils.binomialCoefficientDouble(n.getConcentration(mol).intValue(), conc.intValue()))); if (!neigh.isEmpty()) { propensity = neigh.values().stream().max((d1, d2) -> d1.compareTo(d2)).get(); } return new LinkedHashMap<>(neigh); }
@Override public void nodeMoved(final Node<T> node) { checkCaller(); for (final Reaction<T> r : node.getReactions()) { updateReaction(handlers.get(r)); } }
private void changeConcentrationInSortedNodes(final List<EnvironmentNode> envNodesSurrounding) { if (delta < 0) { double deltaTemp = delta; for (final EnvironmentNode n : envNodesSurrounding) { final double nodeConcentration = n.getConcentration(biomolecule); // if nodeConcentration >= |deltaTemp|, remove the a delta quantity of the biomol only from this node if (nodeConcentration >= FastMath.abs(deltaTemp)) { n.setConcentration(biomolecule, nodeConcentration + deltaTemp); break; // else, remove all molecule of that species from that node and go on till deltaTemp is smaller than nodeConcetration } else { deltaTemp = deltaTemp + nodeConcentration; n.removeConcentration(biomolecule); } } } else { // if delta > 0, simply add delta to the first node of the list (which has been sorted randomly) final Node<Double> target = envNodesSurrounding.get(0); target.setConcentration(biomolecule, target.getConcentration(biomolecule) + delta); } }
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); }