Ejemplo n.º 1
0
  public Pair<Area, Point2D> getEntrancePoint(Area dest) {
    if (dest == null) {
      log.error("why try to move to " + dest + "?????");
      return null;
    }
    Path path = agent.move.getPathTo(Collections.singleton(dest), PoliceMove.class);
    ArrayList<EntityID> pathArray = path.getIds();
    if (pathArray.isEmpty()) {
      log.error("path is empty. why????");
      return null;
    }

    Edge inComingEdge;
    if (pathArray.size() == 1) {
      inComingEdge = dest.getEdgeTo(agent.location());
    } else {
      inComingEdge = dest.getEdgeTo(pathArray.get(pathArray.size() - 2));
    }
    if (inComingEdge == null) return new Pair<Area, Point2D>(dest, dest.getPositionPoint());
    Line2D wallLine =
        inComingEdge
            .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                        // edge.getStartX(), edge.getEndY() - edge.getStartY());

    Vector2D offset;
    if (AliGeometryTools.havecorrectDirection(dest)) {
      offset = wallLine.getDirection().getNormal().normalised().scale(10);
    } else {
      offset = wallLine.getDirection().getNormal().normalised().scale(-10);
    }
    Point2D destXY = inComingEdge.getMidPoint().plus(offset);
    return new Pair<Area, Point2D>(dest, destXY);
  }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
0
  private void sendStockMessage(Path path) {
    if (me instanceof PoliceForceAgent) return;

    if (!(me.me() instanceof Human)) return;

    if (me.time() < 50) return;

    Human meEntity = (Human) me.me();

    if (meEntity.isBuriednessDefined() && meEntity.getBuriedness() > 0) return;

    if (meEntity.getImReachableToEdges().isEmpty()) return;

    if (me.isTimeToActFinished()) return;

    if (me.lastException != null) return;

    try {
      //			if (me.getMyClusterData().isCoverer())
      //				return;

      if (me.me().getAreaPosition().isBlockadesDefined()
          && me.me().getAreaPosition().getBlockadesID().isEmpty()) {
        boolean haveBlock = false;
        for (Area neighbour : me.me().getAreaPosition().getNeighbours()) {
          if (neighbour.isBlockadesDefined() && !neighbour.getBlockadesID().isEmpty())
            haveBlock = true;
        }
        if (!haveBlock) return;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    log().debug("Sending Stock Message");
    me.messageBlock = new MessageBlock(MessageXmlConstant.HEADER_AGENT_STOCK);
    me.messageBlock.addData(
        MessageXmlConstant.DATA_AREA_INDEX, me.me().getAreaPosition().getAreaIndex());
    me.messages.add(me.messageBlock);
    me.lowCommunicationMessages.add(me.messageBlock);
  }
Ejemplo n.º 5
0
 @Override
 public int getWeightFromXYToXY(Area area, Point2D start, Point2D end) {
   int dstlength = ((int) start.distance(end)) / MoveConstants.DIVISION_UNIT;
   if (area instanceof Building || !area.isBlockadesDefined()) return dstlength;
   ReachablityState rs = Reachablity.isReachable((Road) area, start, end);
   switch (rs) {
     case Close:
       return MoveConstants.UNREACHABLE_COST_FOR_GRAPH_WEIGTHING;
     case FoggyClose:
       return dstlength * 5;
     case FoggyOpen:
       return dstlength * 2;
     default:
       return dstlength;
   }
 }
Ejemplo n.º 6
0
  @Override
  public int getOpenWeight(Area insideArea, WorldGraphEdge wge) {
    //		if (((FireBrigadeAgent) model().sosAgent()).targetFireZone() != null) {
    //			SOSFireZone fz = ((FireBrigadeAgent)
    // model().sosAgent()).targetFireZone().generalFireZone();
    //			if (fz != null)
    //				if (fz.convexHull.isInConvex(fz.convex, new Point(insideArea.getX(), insideArea.getY())))
    //					//				return (wge.getLenght() / MoveConstants.DIVISION_UNIT) * 8;
    //					return MoveConstants.UNREACHABLE_COST;
    //		}
    //		//		return MoveConstants.UNREACHABLE_COST;
    //		return (wge.getLenght() / MoveConstants.DIVISION_UNIT);
    if (insideArea.getSOSGroundArea() < 4000000) return getBlockWeight(insideArea, wge);

    return (wge.getLenght() / MoveConstants.DIVISION_UNIT);
  }
Ejemplo n.º 7
0
 @Override
 public int getWeightToXY(Area area, Edge edge, Point2D dst) {
   int dstlength = ((int) edge.getMidPoint().distance(dst)) / MoveConstants.DIVISION_UNIT;
   if (area instanceof Building || !area.isBlockadesDefined()) return dstlength;
   ReachablityState rs = Reachablity.isReachable((Road) area, edge, dst);
   switch (rs) {
     case Close:
       return MoveConstants.UNREACHABLE_COST_FOR_GRAPH_WEIGTHING;
     case FoggyClose:
       //			return dstlength * 2;
     case FoggyOpen:
     case Open:
     default:
       return dstlength;
   }
 }
Ejemplo n.º 8
0
 public long getWeightTo(Area target, Class<? extends MoveType> type) {
   long weightTo = moves.get(type.hashCode()).getWeightTo(target, target.getX(), target.getY());
   if (weightTo < 0) log().error(new Error("why it become negetive here???"));
   return weightTo;
 }
Ejemplo n.º 9
0
  private void check2CycleStock() throws SOSActionException {
    CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
    CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
    if (!(cycleinfo1.getAct() instanceof MoveAction)
        || cycleinfo1.getAct() instanceof StockMoveAction) return;
    if (!(cycleinfo2.getAct() instanceof MoveAction)
        || cycleinfo1.getAct() instanceof StockMoveAction) return;

    Path path1 = ((MoveAction) cycleinfo1.getAct()).getPath();
    //			Path path2 = ((MoveAction) cycleinfo2.getAct()).getPath();
    log().info("Two(2) cycle move ....");
    log().debug("current position:" + me.me().getAreaPosition());
    log().debug("1 cycle ago position:" + cycleinfo1.getPositionPair());
    log().debug("2 cycle ago position:" + cycleinfo2.getPositionPair());
    if (!cycleinfo1.getPositionPair().first().equals(cycleinfo2.getPositionPair().first())) return;
    if (!cycleinfo1.getPositionPair().first().equals(me.me().getAreaPosition())) return;
    if (SOSGeometryTools.getDistance(
            cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
        > MoveConstants.TRAFFIC_CHECKING_DISTANCE) return;

    //////////////// Stock Occured
    log().debug("2 cycle stock occured!!!!!!!");

    ArrayList<EntityID> entityPath = new ArrayList<EntityID>();
    Area area = me.me().getAreaPosition();
    log().debug("Current Position:" + area);
    entityPath.add(area.getID());
    Edge ed;
    Area ne;
    if (path1.getIds().size() > 0 && !path1.getIds().get(0).equals(area.getID())) {
      ne = (Area) me.model().getEntity(path1.getIds().get(0));
      ed = area.getEdgeTo(ne);
    } else if (path1.getIds().size() > 1 && path1.getIds().get(0).equals(area.getID())) {
      ne = (Area) me.model().getEntity(path1.getIds().get(1));
      ed = area.getEdgeTo(ne);
    } else {
      ne = area.getNeighbours().get(0);
      ed = area.getEdgeTo(ne);
    }
    log().debug("ne:" + ne + " ed:" + ed + " last move path:" + path1);
    if (ed == null) {
      log().error("[Move]edge is null!!!!!some problem!!!!");
      ne = area.getNeighbours().get(0);
      ed = area.getEdgeTo(ne);
      log().debug("changed!!!! ne:" + ne + " ed:" + ed + " last move path:" + path1);
    }
    Point2D destXYAPointNearEdge;
    if (ed != null) {
      //			if (area instanceof Road) {
      Pair<Point2D, Point2D> points = getAPointInReachblePartEdges(area, ed);
      destXYAPointNearEdge = points.second();
      //			} else {
      //				Line2D wallLine = ed.getLine();// new Line2D(edge.getStartX(), edge.getStartY(),
      // edge.getEndX() - edge.getStartX(), edge.getEndY() - edge.getStartY());
      //				// ppp.add(new ShapeDebugFrame.Line2DShapeInfo(wallLine, "edge", Color.white.darker(),
      // false, false));
      //				Vector2D offset;
      //				if (lastStockTime < me.time() - 4) {
      //					if (AliGeometryTools.havecorrectDirection(area)) {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(1500);
      //					} else {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(-1500);
      //					}
      //				} else {
      //					if (!AliGeometryTools.havecorrectDirection(area)) {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(1500);
      //					} else {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(-1500);
      //					}
      //				}
      //				destXYAPointNearEdge = ed.getMidPoint().plus(offset);
      //			}
    } else {
      log().error("[Move]edge is null!!!!!some problem!!!!");
      destXYAPointNearEdge = area.getPositionPair().second();
    }
    log().debug("dest area for stock:" + area + " dst point:" + destXYAPointNearEdge);
    me.send(
        new AKMove(
            me.getID(),
            me.time(),
            entityPath,
            (int) destXYAPointNearEdge.getX(),
            (int) destXYAPointNearEdge.getY()));
    Path path =
        new Path(
            null,
            null,
            entityPath,
            me.me().getPositionPair(),
            new Pair<Area, Point2D>(area, destXYAPointNearEdge),
            false);
    me.informationStacker.addInfo(me.model(), new StockMoveAction(path));
    //		log().warn("Traffic Handeling should be change due to server doesn't support AKMotion");
    lastStockTime = me.time();
    throw new SOSActionException("Move Stock(" + area + " " + destXYAPointNearEdge + ")");
  }
Ejemplo n.º 10
0
  private void checkEarlyStock(Path path) throws SOSActionException {
    Area source = me.me().getAreaPosition();
    if (me.informationStacker.getInformations(1).getAct() instanceof MoveAction
        && me.informationStacker.getInformations(1).getPositionPair().first() instanceof Building) {
      log()
          .debug(
              "last act is move and current position is in building ==> don't check early stock");
      return;
    }
    if (me.informationStacker.getInformations(1).getAct() instanceof StockMoveAction) {
      log().debug("last act is stock move ==> don't check early stock");
      return;
    }

    if (source instanceof Building) {
      log().debug("early stock detected!!! agent is in " + source);
      ArrayList<EntityID> entityPath = new ArrayList<EntityID>();
      entityPath.add(source.getID());
      Area second = null;
      Area third = null;

      if (path.getIds().size() > 0 && !path.getIds().get(0).equals(source.getID())) {
        second = (Area) me.model().getEntity(path.getIds().get(0));
        if (path.getIds().size() > 1) third = (Area) me.model().getEntity(path.getIds().get(1));
      } else if (path.getIds().size() > 1 && path.getIds().get(0).equals(source.getID())) {
        second = (Area) me.model().getEntity(path.getIds().get(1));
        if (path.getIds().size() > 2) third = (Area) me.model().getEntity(path.getIds().get(2));
      } else {
        log().warn("move path size is 0 can't checkEarlyStock!!!");
        return;
      }
      if (second == null) {
        log().warn("second is null can't checkEarlyStock!!!");
        return;
      } else {
        ArrayList<Edge> edges = second.getEdgesTo(source);
        int minDistance = Integer.MAX_VALUE;
        for (Edge edge : edges) {
          minDistance =
              (int)
                  Math.min(
                      minDistance, SOSGeometryTools.distance(edge, me.me().getPositionPoint()));
        }
        //				Edge fedge = second.getEdgeTo(source);
        //				if (SOSGeometryTools.distance(fedge, me.me().getPositionPoint()) <
        // MoveConstants.ENTRACE_DISTANCE_MM+1000)
        //					return;
        if (minDistance < MoveConstants.ENTRACE_DISTANCE_MM + 1000) {
          log().debug("I'm too neat to edge in building... no need to check early stock");
          return;
        }
        entityPath.add(second.getID());
      }
      if (third == null) {
        log().debug("Move path is too small!!! no need to early stock handle");
        return;
      } else {
        Edge ed = second.getEdgeTo(third);
        Point2D destXYAPointNearEdge;
        if (ed != null) {
          Line2D wallLine =
              ed
                  .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                              // edge.getStartX(), edge.getEndY() - edge.getStartY());
          // ppp.add(new ShapeDebugFrame.Line2DShapeInfo(wallLine, "edge", Color.white.darker(),
          // false, false));
          Vector2D offset;
          if (AliGeometryTools.havecorrectDirection(second)) {
            offset = wallLine.getDirection().getNormal().normalised().scale(15);
          } else {
            offset = wallLine.getDirection().getNormal().normalised().scale(-15);
          }
          destXYAPointNearEdge = ed.getMidPoint().plus(offset);
        } else {
          log().error("[Move]edge is null!!!!!some problem!!!!");
          destXYAPointNearEdge = second.getPositionPair().second();
        }
        log()
            .debug(
                "source:"
                    + source
                    + " dest area for stock:"
                    + second
                    + " dst point:"
                    + destXYAPointNearEdge);
        me.send(
            new AKMove(
                me.getID(),
                me.time(),
                entityPath,
                (int) destXYAPointNearEdge.getX(),
                (int) destXYAPointNearEdge.getY()));
        path =
            new Path(
                null,
                null,
                entityPath,
                me.me().getPositionPair(),
                new Pair<Area, Point2D>(second, destXYAPointNearEdge),
                false);
        me.informationStacker.addInfo(me.model(), new StockMoveAction(path));
        throw new SOSActionException(
            "Move Stock(" + source + "," + second + " " + destXYAPointNearEdge + ")");
      }
    }
  }