private boolean mayInfluence(final Reaction<T> source, final Reaction<T> target) { final Context in = target.getInputContext(); final Context out = source.getOutputContext(); if (// Same node target.getNode().equals(source.getNode()) // If reaction writes something globally || out.equals(Context.GLOBAL) // If reaction reads something globally || in.equals(Context.GLOBAL)) { return true; } return influenceNeighborCheck(env, source, target, in, out); }
@Override public Number getCurrentTime() { return react.getTau().toDouble(); }
private static List<RunProtelisProgram> getIncomplete(final ProtelisNode pNode, final List<RunProtelisProgram> alreadyDone) { return pNode.getReactions().parallelStream() /* * Get the actions */ .flatMap(r -> r.getActions().parallelStream()) /* * Get only the ProtelisPrograms */ .filter(a -> a instanceof RunProtelisProgram) .map(a -> (RunProtelisProgram) a) /* * Retain only those ProtelisPrograms that have no associated ComputationalRoundComplete. * * Only one should be available. */ .filter(prog -> !alreadyDone.contains(prog)) .collect(Collectors.toList()); }
@Override public Reaction<Object> createReaction(final RandomGenerator rand, final Environment<Object> env, final Node<Object> node, final TimeDistribution<Object> time, final String param) { LangUtils.requireNonNull(node, time); final boolean isSend = "send".equalsIgnoreCase(param); final Reaction<Object> result = isSend ? new ChemicalReaction<>(node, time) : new Event<>(node, time); if (param != null) { result.setActions(Lists.newArrayList(createAction(rand, env, node, time, result, param))); } if (isSend) { result.setConditions(Lists.newArrayList(createCondition(rand, env, node, time, result, null))); } return result; }
} else { mu = root; final Time t = mu.getTau(); if (t.compareTo(currentTime) < 0) { throw new IllegalStateException(mu + "\nis scheduled in the past at time " + t + ", current time is " + currentTime if (mu.canExecute()) { mu.execute(); for (final DependencyHandler<T> r : deps) { updateReaction(r); mu.update(currentTime, true, env); ipq.updateReaction(root); monitorLock.read();
private void addLocalReactions(final Set<Reaction<T>> list, final Reaction<T> r) { for (final Reaction<T> or : r.getNode()) { /* * 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); } } }
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; }
.flatMap(r -> r.getConditions().parallelStream()) .filter(c -> c instanceof ComputationalRoundComplete) .map(c -> (ComputationalRoundComplete) c)
@Override public ProtelisNode cloneNode(final Time currentTime) { final ProtelisNode result = new ProtelisNode(environment); getContents().forEach((mol, conc) -> { result.setConcentration(mol, conc); }); getReactions().forEach(r -> result.addReaction(r.cloneOnNewNode(result, currentTime))); return result; }
@Override public Reaction<Double> visitJunctionReaction(final BiochemistrydslParser.JunctionReactionContext ctx) { visit(ctx.junctionReactionLeft()); visit(ctx.junctionReactionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } junctionList.forEach((j -> { if (node instanceof CellNode) { actionList.add(new RemoveJunctionInCell(env, (CellNode) node, j, rand)); actionList.add(new RemoveJunctionInNeighbor(env, (CellNode) node, reverseJunction(j), rand)); } else { throw new UnsupportedOperationException("Junctions are supported ONLY in CellNodes, not in " + node.getClass().getName()); } })); reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }
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); } } } }
@Override public Reaction<Double> visitCreateJunction(final BiochemistrydslParser.CreateJunctionContext ctx) { visit(ctx.createJunctionLeft()); visit(ctx.createJunctionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }
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); } } } } }
final List<RunProtelisProgram> alreadyDone = pNode.getReactions() .parallelStream() .flatMap(r -> r.getActions().parallelStream()) .filter(a -> a instanceof SendToNeighbor) .map(c -> (SendToNeighbor) c)
@Override public Reaction<Double> visitBiochemicalReaction(final BiochemistrydslParser.BiochemicalReactionContext ctx) { visit(ctx.biochemicalReactionLeft()); visit(ctx.biochemicalReactionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } /* * if the reaction has at least one neighbor action but no neighbor condition * add the neighborhoodPresent condition. * This is necessary because if the node which contain this reaction don't have * a neighborhood and the reaction is valid (all conditions are valid) the neighbor action * is undefined, and can lead to unwanted behavior. */ if (neighborActionPresent && biomolConditionsInNeighbor.isEmpty()) { conditionList.add(new NeighborhoodPresent<>(env, node)); } if (envActionPresent && !envConditionPresent) { conditionList.add(new EnvPresent(env, node)); } reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }
@Override public void addReaction(final Reaction<T> r) { tree.add(r); times.add(r.getTau()); final int index = tree.size() - 1; indexes.put(r, index); updateEffectively(r, index); }
@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 Map<DeviceUID, Map<CodePath, Object>> getNeighborState() { /* * If retentionTime is a number, use it. Otherwise clean all messages */ if (msgs.isEmpty()) { return Collections.emptyMap(); } if (Double.isNaN(retentionTime)) { final Map<DeviceUID, Map<CodePath, Object>> res = convertMessages(m -> true); msgs = new LinkedHashMap<>(); return res; } final double currentTime = event.getTau().toDouble(); return convertMessages(m -> currentTime - m.time < retentionTime); }