@Override public Number getCurrentTime() { return react.getTau().toDouble(); }
@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 void execute() { final AlchemistNetworkManager mgr = getNode().getNetworkManager(prog); Objects.requireNonNull(mgr); mgr.simulateMessageArrival(reaction.getTau().toDouble()); prog.prepareForComputationalCycle(); }
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"); } }
@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); }); }