@Override public double getProperty(final Node<Double> node, final Molecule mol, final String prop) { return node.getConcentration(mol); }
/** * @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(); }
@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 execute(final Node<Double> targetNode) { targetNode.setConcentration(mol, targetNode.getConcentration(mol) + delta); }
@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); } }
public Object runCycle() { final Node<Object> node = key.node.get(); if (node == null) { throw new IllegalStateException("The node should never be null"); } if (vm.isPresent()) { final ProtelisVM myVM = vm.get(); mutex.acquireUninterruptibly(); myVM.runCycle(); mutex.release(); return myVM.getCurrentValue(); } if (node instanceof NoNode) { return key.property; } return node.getConcentration(key.molecule); } }
/** * @return the propensity influence computed as max(0, T-[M]), where T is * the threshold chosen and [M] is the current concentration of the * molecule */ @Override public double getPropensityConditioning() { final double qty = getQuantity().doubleValue(); final double c = getNode().getConcentration(getMolecule()) .doubleValue(); return Math.max(0, qty - c); }
/** * @return true if the concentration of the molecule is lower the value. */ @Override public boolean isValid() { return getNode().getConcentration(getMolecule()).doubleValue() < getQuantity().doubleValue(); }
/** * Propensity influence is computed through the binomial coefficient. See * Bernardo, Degano, Zavattaro - Formal Methods for Computational Systems * Biology for the formulae. * * @return the propensity influence */ @Override public double getPropensityConditioning() { final int n = getNode().getConcentration(molecule).intValue(); final int k = qty.intValue(); if (k > n) { return 0; } return CombinatoricsUtils.binomialCoefficientDouble(n, k); }
@Override public Object get(final String id) { return shadow.get(id, node.getConcentration(new SimpleMolecule(id))); } @Override
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; }
@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)); } }
private void changeConcentrationInRandomNodes(final List<EnvironmentNode> envNodesSurrounding) { if (delta < 0) { double deltaTemp = delta; while (deltaTemp < 0) { final int index = getRandomGenerator().nextInt(envNodesSurrounding.size()); final EnvironmentNode pickedNode = envNodesSurrounding.get(index); final double nodeConcentration = pickedNode.getConcentration(biomolecule); // if nodeConcentration >= |deltaTemp|, remove the a delta quantity of the biomol only from this node if (nodeConcentration >= FastMath.abs(deltaTemp)) { pickedNode.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; pickedNode.removeConcentration(biomolecule); } envNodesSurrounding.remove(index); } } 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(getRandomGenerator().nextInt(envNodesSurrounding.size())); target.setConcentration(biomolecule, target.getConcentration(biomolecule) + delta); } } }
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); } }
@Override public void execute() { super.getNode().setConcentration(getMolecule(), super.getNode().getConcentration(getMolecule()) + deltaC); }
} 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) {
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; }