Beispiel #1
0
 private Pair<Point2D, Point2D> getAPointInReachblePartEdges(Area area, Edge relatedEdge) {
   Point2D point = null;
   Edge rEdge = null;
   if (area instanceof Road) {
     Road road = (Road) area;
     FOR:
     for (SOSArea reachablePart : road.getReachableParts()) {
       for (Edge edge : reachablePart.getEdges()) {
         if (edge.getReachablityIndex() >= 0
             && area.getEdges().get(edge.getReachablityIndex()).equals(relatedEdge)) {
           point = edge.getMidPoint();
           rEdge = edge;
           break FOR;
         }
       }
     }
   }
   if (point == null) {
     point = relatedEdge.getMidPoint();
     rEdge = relatedEdge;
   }
   ArrayList<Point2D> twoPointForCheckContain =
       Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 10);
   ArrayList<Point2D> twoPoint =
       Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 3000);
   if (area.getShape().contains(twoPointForCheckContain.get(0).toGeomPoint()))
     return new Pair<Point2D, Point2D>(twoPoint.get(0), twoPoint.get(1));
   else return new Pair<Point2D, Point2D>(twoPoint.get(1), twoPoint.get(0));
 }
Beispiel #2
0
  public static Blockade hasIntersectionWithBlockades(Pair<Integer, Integer> point, Area a) {
    double size = ReachablityConstants.AGENT_WIDTH * 1 * 6;
    if (!(a instanceof Road)) return null;
    Road road = (Road) a;
    if (!road.isBlockadesDefined()) return null;
    if (road.getBlockades().size() == 0) return null;

    Ellipse2D.Double expandHuman =
        new Ellipse2D.Double(a.getX() - size / 2, a.getY() - size / 2, size, size);
    java.awt.geom.Area area = new java.awt.geom.Area(expandHuman);
    for (Blockade b : road.getBlockades()) {
      area.intersect(new java.awt.geom.Area(b.getShape()));
      if (!area.isEmpty()) return b;
    }
    return null;
  }
Beispiel #3
0
  private void chooseRoadMessages() { // TODO choose to spread it over time
    if (!(agent instanceof SOSAgent<?>)) return;

    PriorityQueue<Road> roads =
        new PriorityQueue<Road>(
            agent.model().roads().size(),
            new Comparator<Road>() {

              @Override
              public int compare(Road o1, Road o2) {
                return o2.updatedtime() - o1.updatedtime();
              }
            });
    FOR:
    for (Road road : agent.model().roads()) {
      if (road.updatedtime() <= 1) continue;
      boolean haveAnOpenEdge = false;
      for (int j = 0; j < road.getGraphEdges().length; j++) {
        GraphEdge ge = model().graphEdges().get(road.getGraphEdges()[j]);
        //				if (ge.getState() == GraphEdgeState.FoggyBlock ||
        //						ge.getState() == GraphEdgeState.FoggyOpen)
        //					continue FOR;
        if (ge.getState() == GraphEdgeState.Open) haveAnOpenEdge = true;
      }
      if (haveAnOpenEdge) roads.add(road);
    }
    int priority = 6;
    int count = 0;
    SOSAgent<?> agent = (SOSAgent<?>) this.agent;
    for (Road rd : roads) {

      count++;
      if (priority > 0 && count % 10 == 0) priority--;
      boolean isAllOpen = true;
      for (Short ind : rd.getGraphEdges()) {
        GraphEdge ge = agent.model().graphEdges().get(ind);
        if (ge instanceof WorldGraphEdge && ge.getState() != GraphEdgeState.Open) {
          isAllOpen = false;
          break;
        }
      }
      if (isAllOpen) {
        MessageBlock messageBlock = new MessageBlock(HEADER_OPEN_ROAD);
        messageBlock.addData(DATA_ROAD_INDEX, rd.getRoadIndex());
        sayMessages.add(messageBlock);
      } else {
        SOSBitArray states = new SOSBitArray(rd.getWorldGraphEdgesSize());
        for (int i = 0; i < rd.getWorldGraphEdgesSize(); i++) {
          states.set(
              i,
              agent.model().graphEdges().get(rd.getGraphEdges()[i]).getState()
                  != GraphEdgeState.Open);
        }
        MessageBlock messageBlock = new DynamicSizeMessageBlock(HEADER_ROAD_STATE, states);
        messageBlock.addData(DATA_ROAD_INDEX, rd.getRoadIndex());
        sayMessages.add(messageBlock);
      }
    }
  }