Package eas.simulation.spatial.sim2D.standardEnvironments

Examples of eas.simulation.spatial.sim2D.standardEnvironments.AbstractEnvironment2D


   * @return Entry<Color,Double>
   */
  @SuppressWarnings("rawtypes")
  public Entry<Integer, Color> getSensedColor() {
   
    AbstractEnvironment2D env = body.getEnvironment();
    Vector2D bodyPos = env.getAgentPosition(body.id());
   
    //add all AbstractAgent2D except body to check list
    List<Integer> agentsToCheck = new ArrayList<Integer>();
    for (Object o : env.getAgents()) {
      if (o instanceof AbstractAgent2D && env.isCollidingAgent(((AbstractAgent2D<?>) o).id())
          && !((AbstractAgent2D<?>) o).equals(body)) {
        AbstractAgent2D<?> agent = (AbstractAgent2D<?>) o;
        agentsToCheck.add(agent.id());
      }
    }
   
    //construct sensor LOV
    Vector2D sensorLOV = env.getNormalizedLOV(body.id());
    sensorLOV.rotate(Vector2D.NULL_VECTOR, angleToAgent);
    sensorLOV.setLength(cSensorReach);
   
    LineSegment2D sensorLine = new LineSegment2D(
        new Vector2D(bodyPos),
        new Vector2D(bodyPos).translate(sensorLOV));

    //find closest agent
    Double minDistance = Double.POSITIVE_INFINITY;
    AbstractAgent2D closestAgent = null;
    for (Iterator<Integer> iterator = agentsToCheck.iterator(); iterator.hasNext();) {
      Integer agentID = iterator.next();
      //for all remaining agents check for intersection
      List<Vector2D> isPoints = env.getAgentShapeInEnvironment(agentID).intersectAll(sensorLine);
     
      if(!isPoints.isEmpty()){       
        //find intersection point with least distance
        for (Vector2D isPoint : isPoints) {
          isPoint.sub(bodyPos);
          if(Double.compare(isPoint.length(), minDistance) < 0){
             minDistance = isPoint.length();
             closestAgent = env.getAgent(agentID);
          }         
        }
      }

    }
View Full Code Here


   * @return TreeMap<Abstand, Agent>
   */
  @SuppressWarnings("rawtypes")
  public TreeMap<Double, AbstractAgent2D> getAgentsInSensorField() {
   
    AbstractEnvironment2D env = body.getEnvironment();
    TreeMap<Double, AbstractAgent2D> agentsInSensorField = new TreeMap<Double, AbstractAgent2D>();
    Random rand = new Random();
   
    //add all AbstractAgent2D except body to check list
    List<Integer> agentsToCheck = new ArrayList<Integer>();
    for (Object o : env.getAgents()) {
      if (o instanceof AbstractAgent2D && !((AbstractAgent2D<?>) o).equals(body)) {
        AbstractAgent2D<?> agent = (AbstractAgent2D<?>) o;
        agentsToCheck.add(agent.id());
      }
    }

    for (Iterator<Integer> iterator = agentsToCheck.iterator(); iterator.hasNext();) {
      Integer agentID = iterator.next();
      // Vector von Agent zu Body
      Vector2D vecAgentToThis = new Vector2D(env.getAgentPosition(agentID));
      vecAgentToThis.sub(env.getAgentPosition(body.id()));
      double distance = vecAgentToThis.length();
     
      if(distance <= cSensorReach){
       
        while(agentsInSensorField.containsKey(distance)){
          // dieser fall sollte sehr selten eintreten
          distance += + cEpsilon * rand.nextDouble();
        }
        //add agent to sensor field
        agentsInSensorField.put(distance, env.getAgent(agentID));
        //it doesn't need to be checked anymore
        iterator.remove();
      }

    }
View Full Code Here

  @SuppressWarnings("rawtypes")
  public WandaRadioMessage receiveRadioMessage() {

    TreeMap<Double, AbstractAgent2D> agents = getAgentsInSensorField();
    WandaRadioMessage msg = null;
    AbstractEnvironment2D env = body.getEnvironment();
   
    Entry<Double, AbstractAgent2D> agent = agents.pollFirstEntry();
    while(agent != null && !env.isCollidingAgent(agent.getValue().id()))
        agent = agents.pollFirstEntry();

    if (agent != null && agent.getValue() instanceof WandaAgent) {
      // nur Wanda Agents koennen Nachricht senden
      WandaAgent wanda = (WandaAgent) agent.getValue();
View Full Code Here

   * @return true wenn Agent in Sensorfeld
   */
  @SuppressWarnings("rawtypes")
  public boolean agentReachable(AbstractAgent2D agent) {

    AbstractEnvironment2D env = body.getEnvironment();

    // Vector von Agent zu Body
    Vector2D vecAgentToThis = new Vector2D(env.getAgentPosition(agent.id()));
    vecAgentToThis.sub(env.getAgentPosition(body.id()));

    // Agent ist innerhalb der Reichweite des Sensors
    if (vecAgentToThis.length() < cSensorReach)
        return true;

View Full Code Here

        double akt;
        Integer markedID = null;
       
        AbstractAgent<?> agent2D = null;
        try {
            @SuppressWarnings("rawtypes")
            AbstractEnvironment2D env2D = (AbstractEnvironment2D) this.currentEnv;
            agent2D = env2D.getAgentAtPosition(env2D.getRealPosFromScreenPos(new Vector2D(x, y)));
        } catch (Exception e) {
        }

        if (agent2D != null) {
            this.markedAgentId = agent2D.id();
View Full Code Here

        this.follow = followMarkedAgent;
    }
   
    public void setZoom2DPlus() {
        try {
            @SuppressWarnings("rawtypes")
            AbstractEnvironment2D env = (AbstractEnvironment2D) this.environment;
            double scale = 1 / 1.2;
            env.setZoomScale(scale);
        } catch (Exception e) {
        }
    }
View Full Code Here

        }
    }

    public void setZoom2DMinus() {
        try {
            @SuppressWarnings("rawtypes")
            AbstractEnvironment2D env = (AbstractEnvironment2D) this.environment;
            double scale = 1.2;
            env.setZoomScale(scale);
        } catch (Exception e) {
        }
    }
View Full Code Here

        }
    }

    public double getScale() {
        try {
            @SuppressWarnings("rawtypes")
            AbstractEnvironment2D env = (AbstractEnvironment2D) this.environment;
            return env.globalScale();
        } catch (Exception e) {
            return 1;
        }
    }
View Full Code Here

TOP

Related Classes of eas.simulation.spatial.sim2D.standardEnvironments.AbstractEnvironment2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.