Tabnine Logo
Environment.getNeighborhood
Code IndexAdd Tabnine to your IDE (free)

How to use
getNeighborhood
method
in
it.unibo.alchemist.model.interfaces.Environment

Best Java code snippets using it.unibo.alchemist.model.interfaces.Environment.getNeighborhood (Showing top 17 results out of 315)

origin: it.unibo.alchemist/alchemist-engine

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);
        }
      }
    }
  }
}
origin: it.unibo.alchemist/alchemist-engine

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);
      }
    }
  }
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

@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);
  }
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

/**
 * 
 * @return a list containing the environment nodes around
 */
protected List<EnvironmentNode> getEnvironmentNodesSurrounding() {
  return (List<EnvironmentNode>) env.getNeighborhood(getNode()).getNeighbors().stream()
      .parallel()
      .flatMap(n -> n instanceof EnvironmentNode ? Stream.of((EnvironmentNode) n) : Stream.empty())
      .collect(Collectors.toList());
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

@Override
public boolean isValid() {
  return environment.getNeighborhood(getNode()).getNeighbors().stream()
      .parallel()
      .filter(n -> n instanceof EnvironmentNode)
      .findAny()
      .isPresent();
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

@Override
public boolean isValid() {
  return env.getNeighborhood(getNode()).getNeighbors().stream()
      .parallel()
      .filter(n -> n instanceof CellNode)
      .findAny()
      .isPresent();
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

/**
 * @return a list of EnvironmentNodes near to the node where this condition is located.
 */
protected final List<Node<Double>> getEnviromentNodesSurrounding() {
  return environment.getNeighborhood(getNode()).getNeighbors().stream()
      .parallel()
      .filter(n -> n instanceof EnvironmentNode)
      .collect(Collectors.toList());
}
origin: it.unibo.alchemist/alchemist-engine

private static <T> boolean commonNeighbor(final Environment<T> env, final Neighborhood<T> sl, final Node<T> t) {
  for (final Node<T> n : sl) {
    if (env.getNeighborhood(n).getNeighbors().contains(t)) {
      return true;
    }
  }
  return false;
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

/**
 * Searches in the whole neighborhood of the current node which neighbors satisfy the condition, and
 * returns a list of this neighbors.
 * @return a map of neighbors which satisfy the condition and their propensity
 */
public Map<Node<T>, Double> getValidNeighbors() {
  return getValidNeighbors(env.getNeighborhood(getNode()).getNeighbors());
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

@Override 
protected void updateInternalStatus(final Time curTime, final boolean executed, final Environment<Double> env) {
  if (neighborConditionsPresent) {
    validNeighbors.clear();
    validNeighbors = env.getNeighborhood(node).getNeighbors().stream().collect(Collectors.<Node<Double>, Node<Double>, Double>toMap(
        n -> n,
        n -> 0d));
    for (final Condition<Double> cond : getConditions()) {
      if (cond instanceof AbstractNeighborCondition) {
        validNeighbors = intersectMap(validNeighbors, ((AbstractNeighborCondition<Double>) cond).getValidNeighbors(validNeighbors.keySet()));
        if (validNeighbors.isEmpty()) { // maybe speedup the check
          break;
        }
      }
    }
  }
  super.updateInternalStatus(curTime, executed, env);
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

@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));
  }
}
origin: it.unibo.alchemist/alchemist-swingui

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");
  }
}
origin: it.unibo.alchemist/alchemist-incarnation-protelis

/**
 * Simulates the arrival of the message to other nodes.
 * 
 * @param currentTime
 *            the current simulation time (used to understand when a message
 *            should get dropped).
 */
public void simulateMessageArrival(final double currentTime) {
  assert toBeSent != null;
  Objects.requireNonNull(toBeSent);
  if (!toBeSent.isEmpty()) {
    final MessageInfo msg = new MessageInfo(currentTime, node, toBeSent);
    env.getNeighborhood(node).forEach(n -> {
      if (n instanceof ProtelisNode) {
        final AlchemistNetworkManager destination = ((ProtelisNode) n).getNetworkManager(prog);
        if (destination != null) {
          /*
           * The node is running the program. Otherwise, the
           * program is discarded
           */
          destination.receiveMessage(msg);
        }
      }
    });
  }
  toBeSent = null;
}
origin: it.unibo.alchemist/alchemist-engine

@Override
public void nodeAdded(final Node<T> node) {
  checkCaller();
  if (status != Status.INIT) {
    for (final Reaction<T> r : node.getReactions()) {
      scheduleReaction(r);
    }
    updateDependenciesForOperationOnNode(env.getNeighborhood(node));
  }
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

/**
 * Execute the action on a random neighbor if the node has a neighborhood. Otherwise do nothing.
 */
@Override
public void execute() {
  final Neighborhood<T> neighborhood = env.getNeighborhood(node);
  if (!neighborhood.isEmpty()) {
    execute(neighborhood.getNeighborByNumber(getRandomGenerator().nextInt(neighborhood.size())));
  }
}
origin: it.unibo.alchemist/alchemist-engine

/**
 * This method checks if there may be a dependency considering the
 * neighborhoods
 */
private static <T> boolean influenceNeighborCheck(final Environment<T> env, final Reaction<T> source, final Reaction<T> target, final Context in, final Context out) {
  final Neighborhood<T> sn = env.getNeighborhood(source.getNode());
  final boolean scn = in.equals(Context.NEIGHBORHOOD);
  // If source reads from neighborhood and target is within
  if (scn && sn.contains(target.getNode())) {
    return true;
  }
  // If target writes in neighborhood and source is within
  final Neighborhood<T> tn = env.getNeighborhood(target.getNode());
  final boolean tcn = out.equals(Context.NEIGHBORHOOD);
  if (tcn && tn.contains(source.getNode())) {
    return true;
  }
  // If source writes on the neighborhood, target reads on its
  // neighborhood and there is at least one common node
  return scn && tcn && commonNeighbor(env, sn, target.getNode());
}
origin: it.unibo.alchemist/alchemist-incarnation-biochemistry

final List<Node<Double>> l = env.getNeighborhood(thisNode).getNeighbors().stream()
    .filter(n -> n instanceof EnvironmentNode && n.contains(biomol))
    .collect(Collectors.toList());
it.unibo.alchemist.model.interfacesEnvironmentgetNeighborhood

Popular methods of Environment

  • getPosition
  • getDistanceBetweenNodes
  • getNodes
  • getSimulation
  • getLayer
  • getNodeByID
  • getOffset
  • getSize
  • isTerminated
  • removeNode
  • setSimulation
  • setSimulation

Popular in Java

  • Updating database using SQL prepared statement
  • getSystemService (Context)
  • setScale (BigDecimal)
  • getSharedPreferences (Context)
  • String (java.lang)
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now