コード例 #1
0
ファイル: SOSShape.java プロジェクト: jpollo/rcrss
  public SOSShape(int[] apexes) {
    super();
    if (apexes.length <= 4) {
      errorReason = ("a shape with just 2 point???? what is the advantages?");
      valid = false;
    }

    int count = apexes.length / 2;
    int[] xs = new int[count];
    int[] ys = new int[count];
    for (int i = 0; i < count; ++i) {
      xs[i] = apexes[i * 2];
      ys[i] = apexes[i * 2 + 1];
    }

    this.xpoints = xs;
    this.ypoints = ys;
    this.npoints = count;

    if (apexes.length == 0) {
      errorReason = ("sos shape has error in defination!!!!!!apexes.length should be >0");
      valid = false;
    } else computeCenter(apexes);

    if (!contains(centerX, centerY)) {
      errorReason = ("[sos shape] center point not in shape!!!!!!");
      valid = false;
    }
    if (SOSGeometryTools.computeArea(apexes) < 100) {
      errorReason = ("[sos shape]Too Small Area....=" + SOSGeometryTools.computeArea(apexes));
      valid = false;
    }
  }
コード例 #2
0
ファイル: Move.java プロジェクト: jpollo/rcrss
  private void checkAlakiStock(Path path) throws SOSActionException {
    log().info("checking alaki stock");
    CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
    CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
    CycleInformations cycleinfo3 = me.informationStacker.getInformations(3);
    // Move Stock Move Stock Stock Stock
    log().trace("cycleinfo1:" + cycleinfo1);
    log().trace("cycleinfo2:" + cycleinfo2);
    log().trace("cycleinfo3:" + cycleinfo3);
    if (!(cycleinfo1.getAct() instanceof MoveAction)
        || cycleinfo1.getAct() instanceof StockMoveAction) return;
    if (
    /* !(cycleinfo2.getAct() instanceof MoveAction) || */ !(cycleinfo2.getAct()
        instanceof StockMoveAction)) return;
    if (!(cycleinfo3.getAct() instanceof MoveAction)
        || cycleinfo3.getAct() instanceof StockMoveAction) return;

    log()
        .debug(
            "cycleinfo1:"
                + cycleinfo1.getPositionPair()
                + "cycleinfo2:"
                + cycleinfo2.getPositionPair()
                + " cycleinfo3:"
                + cycleinfo3.getPositionPair());
    if (SOSGeometryTools.getDistance(
                cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
            < MoveConstants.TRAFFIC_CHECKING_DISTANCE
        && SOSGeometryTools.getDistance(
                cycleinfo1.getPositionPair().second(), cycleinfo3.getPositionPair().second())
            < MoveConstants.TRAFFIC_CHECKING_DISTANCE) {
      Path randomPath = bfs.getDummyRandomWalkPath();

      me.send(
          new AKMove(
              me.getID(),
              me.time(),
              randomPath.getIds(),
              randomPath.getDestination().second().getIntX(),
              randomPath.getDestination().second().getIntY()));
      sendStockMessage(path);
      me.informationStacker.addInfo(me.model(), new StockMoveAction(randomPath));
      throw new SOSActionException("Move Stock Random Walk(" + randomPath + ")");
    }
  }
コード例 #3
0
ファイル: SOSFireProbability.java プロジェクト: jpollo/rcrss
 public static double distance(Building b1, Building b2) {
   double distance = Integer.MAX_VALUE;
   for (int i = 0; i < b1.getApexes().length / 2; i += 2) {
     for (int j = 0; j < b2.getApexes().length / 2; j += 2) {
       double dis =
           SOSGeometryTools.distance(
               b1.getApexes()[i], b1.getApexes()[i + 1], b2.getApexes()[j], b2.getApexes()[j + 1]);
       if (dis < distance) distance = dis;
     }
   }
   return distance;
 }
コード例 #4
0
ファイル: Move.java プロジェクト: jpollo/rcrss
 @SuppressWarnings("unused")
 private void check4CycleStock() throws SOSActionException {
   CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
   CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
   CycleInformations cycleinfo3 = me.informationStacker.getInformations(3);
   CycleInformations cycleinfo4 = me.informationStacker.getInformations(4);
   if (cycleinfo2.getAct() instanceof StockMoveAction) return;
   if (cycleinfo1.getAct() instanceof MoveAction
       && cycleinfo2.getAct() instanceof MoveAction
       && cycleinfo3.getAct() instanceof MoveAction
       && cycleinfo4.getAct() instanceof MoveAction) {
     //			Path path1 = ((MoveAction) cycleinfo1.getAct()).getPath();
     //			Path path2 = ((MoveAction) cycleinfo2.getAct()).getPath();
     //			Path path3 = ((MoveAction) cycleinfo3.getAct()).getPath();
     //			Path path4 = ((MoveAction) cycleinfo4.getAct()).getPath();
     log().debug("Four(4) cycle move ....");
     log().debug("1 cycle ago position:" + cycleinfo1.getPositionPair());
     log().debug("2 cycle ago position:" + cycleinfo2.getPositionPair());
     log().debug("3 cycle ago position:" + cycleinfo3.getPositionPair());
     log().debug("4 cycle ago position:" + cycleinfo4.getPositionPair());
     if (cycleinfo1.getPositionPair().first().equals(cycleinfo2.getPositionPair().first())
         && cycleinfo1.getPositionPair().first().equals(cycleinfo3.getPositionPair().first())
         && cycleinfo1.getPositionPair().first().equals(cycleinfo4.getPositionPair().first())) {
       if (SOSGeometryTools.getDistance(
                   cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
               < MoveConstants.TRAFFIC_CHECKING_DISTANCE
           && SOSGeometryTools.getDistance(
                   cycleinfo1.getPositionPair().second(), cycleinfo3.getPositionPair().second())
               < MoveConstants.TRAFFIC_CHECKING_DISTANCE
           && SOSGeometryTools.getDistance(
                   cycleinfo1.getPositionPair().second(), cycleinfo4.getPositionPair().second())
               < MoveConstants.TRAFFIC_CHECKING_DISTANCE) {
         //////////////////// DO TRAFFIC/////////////////////////////
         log().warn("4 cycle stock!--> do random walk");
         move(bfs.getDummyRandomWalkPath(), false);
       }
     }
   }
 }
コード例 #5
0
ファイル: Move.java プロジェクト: jpollo/rcrss
 // TODO add stopped time to 3 cycles
 private void checkTraffic() throws SOSActionException {
   log().info("Checking traffic");
   if (me.time() < 4) {
     log().debug("No Traffic! Beacuse time is less than 4");
     return;
   }
   CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
   CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
   CycleInformations cycleinfo3 = me.informationStacker.getInformations(3);
   if (cycleinfo1.getAct() instanceof MoveAction
       && cycleinfo2.getAct() instanceof MoveAction
       && cycleinfo3.getAct() instanceof MoveAction) {
     //		Path path1 = ((MoveAction) cycleinfo1.getAct()).getPath();
     Path path2 = ((MoveAction) cycleinfo2.getAct()).getPath();
     //		Path path3 = ((MoveAction) cycleinfo3.getAct()).getPath();
     log().info("Three(3) cycle move ....");
     log().debug("1 cycle ago position:" + cycleinfo1.getPositionPair());
     log().debug("2 cycle ago position:" + cycleinfo2.getPositionPair());
     log().debug("3 cycle ago position:" + cycleinfo3.getPositionPair());
     if (cycleinfo1.getPositionPair().first().equals(cycleinfo2.getPositionPair().first())
         && cycleinfo1.getPositionPair().first().equals(cycleinfo3.getPositionPair().first())) {
       if (SOSGeometryTools.getDistance(
                   cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
               < MoveConstants.TRAFFIC_CHECKING_DISTANCE
           && SOSGeometryTools.getDistance(
                   cycleinfo1.getPositionPair().second(), cycleinfo3.getPositionPair().second())
               < MoveConstants.TRAFFIC_CHECKING_DISTANCE) {
         if (path2.getEdges() != null && !path2.getEdges()[0].haveTraffic()) {
           this.traffic.add(new Pair<GraphEdge, Integer>(path2.getEdges()[0], me.time()));
           path2.getEdges()[0].setHaveTraffic();
           log().info("Traffic added to " + path2.getEdges()[0]);
         }
       }
     }
   }
 }
コード例 #6
0
ファイル: SOSShape.java プロジェクト: jpollo/rcrss
  private void computeCenter(int[] apexes) {

    rescuecore2.geometry.Point2D p = SOSGeometryTools.computeCentroid(apexes);
    centerX = (int) p.getX();
    centerY = (int) p.getY();
    if (apexes.length < 6) return;
    try {
      Point2D point1 = null, point2 = null, middlePoint = null;
      ArrayList<rescuecore2.geometry.Point2D> twoPointOutOfLine = null;
      if (!contains(centerX, centerY)) { // if the point is not inside the polygon
        /////////////////////// finding a point inside polygon////////////////
        FOR:
        for (int i = 0; i < apexes.length - 2; i += 2) {
          point1 = new rescuecore2.geometry.Point2D(apexes[i], apexes[i + 1]);
          point2 = new rescuecore2.geometry.Point2D(apexes[i + 2], apexes[i + 3]);
          middlePoint =
              new rescuecore2.geometry.Point2D(
                  (apexes[i] + apexes[i + 2]) / 2, (apexes[i + 1] + apexes[i + 3]) / 2);
          twoPointOutOfLine =
              Utility.get2PointsAroundAPointOutOfLine(point1, point2, middlePoint, 2);
          for (rescuecore2.geometry.Point2D point2d : twoPointOutOfLine) {
            if (contains(point2d.getX(), point2d.getY())) {
              centerX = (int) point2d.getX();
              centerY = (int) point2d.getY();
              break FOR;
            }
          }
        }
        /*
        if (!contains(centerX, centerY)) {
        	debug.show("SOS Shape", new ShapeDebugFrame.AWTShapeInfo(this, "apexes=" + Arrays.toString(apexes), Color.blue, false),
        			new ShapeDebugFrame.Point2DShapeInfo(point1, "Point 1", Color.red, true),
        			new ShapeDebugFrame.Point2DShapeInfo(point2, "Point 2", Color.green, true),
        			new ShapeDebugFrame.Point2DShapeInfo(middlePoint, "middlePoint", Color.pink, true),
        			new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(0), "twoPointOutOfLine 1", Color.magenta, true),
        			new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(1), "twoPointOutOfLine 2", Color.black, true),
        			new ShapeDebugFrame.DetailInfo("area:" + SOSGeometryTools.computeAreaUnsigned(apexes))
        			);
        }
        */
        ///////////////////////////////////////////////////////////////////////
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(this.getClass().getSimpleName() + " have error" + e.getMessage());
    }
  }
コード例 #7
0
ファイル: Move.java プロジェクト: jpollo/rcrss
  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 + ")");
  }
コード例 #8
0
ファイル: Move.java プロジェクト: jpollo/rcrss
  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 + ")");
      }
    }
  }