Example #1
0
 public void update() {
   if (world.getSelf() instanceof MrlPlatoonAgent) {
     //            checkIsLockedByBlockade();
     if (world.getTime() > world.getIgnoreCommandTime()) {
       updateSelfHealthyValue();
     }
   }
 }
Example #2
0
  private boolean buildingIsIsolated(Building position) {
    Graph graph = world.getPlatoonAgent().getPathPlanner().getGraph();

    for (Entrance entrance : world.getMrlBuilding(position.getID()).getEntrances()) {
      if (graph.getNodeBetweenAreas(position.getID(), entrance.getID(), null).isPassable()) {
        return false;
      }
    }
    return true;
  }
Example #3
0
 private void createEntrance(Road road) {
   Entrance entrance = entrancesMap.get(road.getID());
   if (entrance == null) {
     List<Building> buildings =
         world.getHelper(RoadHelper.class).getBuildingsOfThisEntrance(road.getID());
     entrance = new Entrance(road, buildings);
     entrancesMap.put(road.getID(), entrance);
     for (Area area : buildings) {
       world.getMrlBuilding(area.getID()).addEntrance(entrance);
     }
   }
 }
Example #4
0
  /** find the cluster paths */
  private void clusterPaths() {
    List<Road> roadList = new ArrayList<Road>();
    for (StandardEntity entity : world.getRoads()) {
      if (entity instanceof Road) {
        if (polygon.contains(((Road) entity).getX(), ((Road) entity).getY())) {
          roadList.add((Road) entity);
        }
      }
    }

    for (Road r : roadList) {
      paths.add(world.getPath(r.getID()).getId());
    }
  }
Example #5
0
  private Path getNearestPath(Road road, List<Path> paths) {
    int range = 10000;
    int minDistance = Integer.MAX_VALUE;
    EntityID nearestPath = null;

    while (nearestPath == null) {
      Collection<StandardEntity> entities = world.getObjectsInRange(road, range);

      for (StandardEntity entity : entities) {
        if (entity instanceof Road) {
          EntityID pathId = roadHelper.getPathId(entity.getID());

          if (pathId != null) {
            int distance = Util.distance((Area) entity, road);
            if (distance < minDistance) {
              nearestPath = pathId;
              minDistance = distance;
            }
          }
        }
      }
      range += 10000;
    }

    for (Path path : paths) {
      if (path.getId().equals(nearestPath)) {
        return path;
      }
    }
    return null;
  }
Example #6
0
 private void findOrphanRoads() {
   for (StandardEntity road : world.getRoads()) {
     if (roadHelper.getPathId(road.getID()) == null) {
       orphanRoads.add((Road) road);
     }
   }
 }
Example #7
0
 public List<Human> getBlockedAgents() {
   List<Human> blockedAgents = new ArrayList<Human>();
   for (EntityID id : stuckAgents) {
     blockedAgents.add((Human) world.getEntity(id));
   }
   return blockedAgents;
 }
Example #8
0
 public void updateSelfHealthyValue() {
   Human human = world.getSelfHuman();
   if (repeatHealthyMessageCount == null && human.getBuriedness() == 0) {
     repeatHealthyMessageCount = 3;
   } else if (repeatHealthyMessageCount != null && human.getBuriedness() != 0) {
     repeatHealthyMessageCount = null;
   }
 }
Example #9
0
 /** * find the cluster buildings */
 private void clusterBuildings() {
   for (StandardEntity entity : world.getBuildings()) {
     if (entity instanceof Building) {
       if (polygon.contains(((Building) entity).getX(), ((Building) entity).getY())) {
         this.buildings.add((Building) entity);
       }
     }
   }
 }
Example #10
0
 /** find the cluster roads */
 private void clusterRoad() {
   for (StandardEntity entity : world.getRoads()) {
     if (entity instanceof Road) {
       if (polygon.contains(((Road) entity).getX(), ((Road) entity).getY())) {
         this.roads.add((Road) entity);
       }
     }
   }
 }
Example #11
0
  public Polygon scalePolygon(Polygon polygon) {
    int xs[] = new int[polygon.npoints];
    int ys[] = new int[polygon.npoints];
    math.geom2d.Point2D p;
    math.geom2d.Point2D p1;
    int sumX = 0;
    int sumY = 0;

    for (int i = 0; i < polygon.npoints; i++) {
      p = new math.geom2d.Point2D(polygon.xpoints[i], polygon.ypoints[i]);
      p1 = p.scale(0.5);
      sumX += p1.getX();
      sumY += p1.getY();

      xs[i] = (int) p1.getX();
      ys[i] = (int) p1.getY();
      p.clone();
    }

    Polygon poly = new Polygon(xs, ys, polygon.npoints);
    poly.translate(sumX / polygon.npoints, sumY / polygon.npoints);

    Polygon scalePolygon = new Polygon();

    for (int i = 0; i < poly.npoints; i++) {
      p = new math.geom2d.Point2D(poly.xpoints[i], poly.ypoints[i]);
      if (i + 1 < poly.npoints) {
        if (p.distance(poly.xpoints[i + 1], poly.ypoints[i + 1]) > (0.1 * world.getMapWidth())) {
          scalePolygon.addPoint(poly.xpoints[i], poly.ypoints[i]);
        } else {
          continue;
        }
      } else if (i + 1 == poly.npoints) {
        if (p.distance(poly.xpoints[0], poly.ypoints[0]) > (0.1 * world.getMapWidth())) {
          scalePolygon.addPoint(poly.xpoints[i], poly.ypoints[i]);
        } else {
          continue;
        }
      }
    }

    return scalePolygon;
  }
Example #12
0
 private void createPathsNeighbours() {
   Set<Path> neighbours;
   for (Path path : this) {
     neighbours = new FastSet<Path>();
     for (Road road : path) {
       for (EntityID entityID : road.getNeighbours()) {
         if (world.getEntity(entityID) instanceof Road) {
           for (Path p : this) {
             if (!path.equals(p) && p.contains((Road) world.getEntity(entityID))) {
               if (!neighbours.contains(p)) {
                 neighbours.add(p);
               }
             }
           }
         }
       }
     }
     path.setNeighbours(neighbours);
   }
 }
Example #13
0
  private void getRoadsAndEntrances() {

    for (StandardEntity standardEntity : world.getRoads()) {
      Road road = (Road) standardEntity;
      if (isEntrance(road) && !entrances.contains(road)) {
        entrances.add(road);
        createEntrance(road);
      } else {
        roads.add(road);
      }
    }
  }
Example #14
0
  public Paths(MrlWorld world) {

    this.world = world;
    roadHelper = world.getHelper(RoadHelper.class);
    this.addAll(createPaths());

    // test if we have any orphan road yet or not
    createMappingFromRoadToPath();

    // TODO: General Test - Pooya      It is just used in Federated coordination Strategy
    createPathsNeighbours();
  }
Example #15
0
  public Set<EntityID> getBordersOf(Set<EntityID> allEntities, double scale) {
    ConvexHull convexHull = new ConvexHull();

    for (EntityID id : allEntities) {
      Pair<Integer, Integer> location = world.getEntity(id).getLocation(world);
      convexHull.addPoint(location.first(), location.second());
    }

    Set<EntityID> borderEntities = getBorderEntities(convexHull, allEntities, scale);

    return borderEntities;
  }
Example #16
0
  /**
   * this method calculates the border entities, using entities and convexHull of the entities
   *
   * @param convex is the convex of all Entities
   * @param entities are the self entities
   * @param scale is the scale for making smaller convex hull
   */
  public Set<EntityID> getBorderEntities(ConvexHull convex, Set<EntityID> entities, double scale) {
    if (scale >= 1.0) {
      System.err.println(
          "scale should not be over 1.0! check it in border entities, border entities doesn't work now!");
      return null;
    }

    Building building;
    Polygon convexObject = convex.convex();
    Set<EntityID> borderEntities = new FastSet<EntityID>();

    if (convexObject.npoints
        == 0) { // I don't know why this happens, report me if this error writes usually! TODO check
      // this if something comes wrong here
      System.out.println("Something gone wrong in setting border entities for Firebrigade!!!");
      return null;
    }

    Polygon smallBorderPolygon = scalePolygon(convexObject, scale);
    //        Polygon bigBorderPolygon = scalePolygon(convexObject, 1.1);

    if (MRLConstants.LAUNCH_VIEWER) {
      //            MrlConvexHullLayer.BIG_Whole_BORDER_HULL = convex;
      //            MrlConvexHullLayer.SMALL_Whole_BORDER_HULL = smallBorderPolygon;
    }

    for (EntityID entityID : entities) {

      StandardEntity entity = world.getEntity(entityID);

      if (entity instanceof Refuge) continue;
      if (!(entity instanceof Building)) continue;
      building = (Building) entity;
      int vertexes[] = building.getApexList();
      for (int i = 0; i < vertexes.length; i += 2) {

        if ((convexObject.contains(vertexes[i], vertexes[i + 1]))
            && !(smallBorderPolygon.contains(vertexes[i], vertexes[i + 1]))) {
          borderEntities.add(building.getID());
          break;
        }
      }
    }

    return borderEntities;
  }
Example #17
0
  private boolean isInPreviousArea(EntityID areaId) {
    String lastCommand = world.getPlatoonAgent().getLastCommand();

    if (lastCommand == null) {
      return false;
    }
    if (lastCommand.equalsIgnoreCase("Move") || lastCommand.equalsIgnoreCase("Move To Point")) {
      if (areaId.equals(previousPosition)) {
        stayInSamePositionCounter++;
        if (stayInSamePositionCounter > 6) {
          //                    world.printData(" i Am in isolated are.....");
          return true;
        }
      } else {
        stayInSamePositionCounter = 0;
        previousPosition = areaId;
      }
    }
    return false;
  }
Example #18
0
 public void init() {
   for (StandardEntity entity : world.getPlatoonAgents()) {
     humanInfoMap.put(entity.getID(), new HumanInfo(false, false));
   }
 }
Example #19
0
 public Boolean isBuried(EntityID id) {
   Human human = world.getEntity(id, Human.class);
   return human.isBuriednessDefined() && human.getBuriedness() > 0;
 }