@Override public Number getCurrentTime() { return react.getTau().toDouble(); }
private void down(final Reaction<T> r, final int i) { int index = i; final Time newTime = r.getTau(); do { int minIndex = 2 * index + 1; if (minIndex > tree.size() - 1) { return; } Time minTime = times.get(minIndex); Reaction<T> min = tree.get(minIndex); final int right = minIndex + 1; if (right < tree.size()) { final Time rr = times.get(right); if (rr.compareTo(minTime) < 0) { min = tree.get(right); minIndex = right; minTime = rr; } } if (newTime.compareTo(minTime) > 0) { swap(index, r, minIndex, min); index = minIndex; } else { return; } } while (true); }
@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); }
@Override public synchronized void goToTime(final Time t) { runUntil(() -> getTime().compareTo(t) < 0); }
private boolean up(final Reaction<T> r, final int i) { int index = i; int parentIndex = getParent(index); final Time newTime = r.getTau(); if (parentIndex == -1) { return false; } else { Reaction<T> parent = tree.get(parentIndex); if (newTime.compareTo(times.get(parentIndex)) >= 0) { return false; } else { do { swap(index, r, parentIndex, parent); index = parentIndex; parentIndex = getParent(index); if (parentIndex == -1) { return true; } parent = tree.get(parentIndex); } while (newTime.compareTo(times.get(parentIndex)) < 0); return true; } } }
@Override public void execute() { final AlchemistNetworkManager mgr = getNode().getNetworkManager(prog); Objects.requireNonNull(mgr); mgr.simulateMessageArrival(reaction.getTau().toDouble()); prog.prepareForComputationalCycle(); }
@Override public int compareTo(final DependencyHandler<T> o) { return reaction.getTau().compareTo(o.getReaction().getTau()); }
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"); } }
idleProcessSingleCommand(); while (status != Status.TERMINATED && curStep < steps && currentTime.compareTo(finalTime) < 0) { while (!commands.isEmpty()) { commands.poll().run();
@Override public Field nbrRange() { final boolean useRoutesAsDistances = env instanceof MapEnvironment<?> && node.contains(USE_ROUTES_AS_DISTANCES); return buildFieldWithPosition(p -> { if (useRoutesAsDistances) { if (node.contains(APPROXIMATE_NBR_RANGE)) { try { final double tolerance = (double) node.getConcentration(APPROXIMATE_NBR_RANGE); final double currTime = env.getSimulation().getTime().toDouble(); if (currTime > nbrRangeTimeout) { nbrRangeTimeout = currTime + tolerance; precalcdRoutingDistance = routingDistance(p); } assert !Double.isNaN(precalcdRoutingDistance); return precalcdRoutingDistance; } catch (final ClassCastException e) { throw new IllegalStateException(APPROXIMATE_NBR_RANGE + " should be associated with a double concentration", e); } } return routingDistance(p); } return getDevicePosition().getDistanceTo(p); }); }
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 + "\nProblem occurred at step " + curStep);