/**
   * Create a single {@link com.rackspacecloud.blueflood.service.SingleRollupWriteContext} from the
   * given {@link com.rackspacecloud.blueflood.types.IMetric} and Granularity.
   *
   * @param destGran
   * @param metric
   * @return
   * @throws IOException
   */
  protected SingleRollupWriteContext createSingleRollupWriteContext(
      Granularity destGran, IMetric metric) throws IOException {

    Locator locator = metric.getLocator();

    Points<SimpleNumber> points = new Points<SimpleNumber>();
    points.add(
        new Points.Point<SimpleNumber>(
            metric.getCollectionTime(), new SimpleNumber(metric.getMetricValue())));

    BasicRollup rollup = BasicRollup.buildRollupFromRawSamples(points);

    return new SingleRollupWriteContext(
        rollup,
        locator,
        destGran,
        CassandraModel.getBasicColumnFamily(destGran),
        metric.getCollectionTime());
  }
  /**
   * Convert a list of {@link com.rackspacecloud.blueflood.types.Points} into a list of {@link
   * com.rackspacecloud.blueflood.service.SingleRollupWriteContext} for the given Granularity and
   * Locator.
   *
   * @param locator
   * @param points
   * @param gran
   * @return
   */
  protected List<SingleRollupWriteContext> toWriteContext(
      Locator locator, Points<Rollup> points, Granularity gran) {

    List<SingleRollupWriteContext> resultList = new ArrayList<SingleRollupWriteContext>();

    for (Map.Entry<Long, Points.Point<Rollup>> entry : points.getPoints().entrySet()) {

      resultList.add(
          new SingleRollupWriteContext(
              entry.getValue().getData(),
              locator,
              gran,
              CassandraModel.getBasicColumnFamily(gran),
              entry.getKey()));
    }

    return resultList;
  }
Esempio n. 3
0
  // This method will construct the best possible path by using the A* search algorithm
  private static List<String> AStarSearch(Polygon[] finalPolygons) {

    List<String> completedPath = new ArrayList<String>();
    String[] Ender = ePoint.split(",");

    // The final goal point
    double endx = Double.parseDouble(Ender[0]);
    double endy = Double.parseDouble(Ender[1]);

    //////////////////////////////////////////////////
    // Correct path from the example map:
    // (1,3)  (2,6)  (14,8)  (22,19)  (28,19)  (31,19)  (34,19)
    //////////////////////////////////////////////////

    // set of points to be evaluated, initially only containing start point
    List<Points> openset = new ArrayList<Points>();
    // set of points already evaluated
    List<Points> closedset = new ArrayList<Points>();

    // The initial starting point
    GStartx = Startx;
    GStarty = Starty;

    // G-score is the calculated cost from the start to the current point

    // Calculating F score, which is the distance between the current starting point and the final
    // end point
    double F_Cost = distance(Startx, Starty, endx, endy);

    // initializing variables for each point

    // current x and y location, current "came from" x and y location
    int currX, currY, currCamex, currCamey;

    // current G-Score and F-Score
    double currG, currF;

    double tentGscore, tentFscore;
    openset.add(new Points((int) Startx, (int) Starty, 0, 0, F_Cost, -1, -1));
    boolean dummy = true;

    // while the openset is not empty
    while (openset.size() != 0) {

      // get the next Point to be evaluated in the openset with the lowest f-score

      // filling variables with the information from the point being evaluated
      currX = openset.get(0).XPoint;
      currY = openset.get(0).YPoint;
      currF = openset.get(0).costF;
      currG = openset.get(0).costG;
      currCamex = openset.get(0).camefromx;
      currCamey = openset.get(0).camefromy;
      Startx = currX;
      Starty = currY;

      // If the current point equals the goal point, start constructing a path back to the start
      if (currX == endx && currY == endy) {
        // add the last point to the closed set
        closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));
        for (int r = closedset.size() - 1; r >= 0; r--) {

          // Loop from the end to the start of the closed set
          // From the end point, look at the point that was "travelled from" and add that point to
          // the path
          if ((currX == closedset.get(r).XPoint) && (currY == closedset.get(r).YPoint)) {

            completedPath.add(" (" + currX + "," + currY + ") ");

            currX = closedset.get(r).camefromx;
            currY = closedset.get(r).camefromy;
          }
        }

        // Reverse the order from start to finish and print the path
        Collections.reverse(completedPath);
        System.out.print("Best path: ");
        for (String omg : completedPath) {
          // Final, constructed path
          System.out.print(omg);
        }

        // End the algorithm
        break;
      }

      // Check which points can be seen and travelled to from the current point
      List<Points> Seeable = visible(finalPolygons);

      // Before evaluating the current point, remove it from the openset and add it to the closed
      // set
      openset.remove(0);
      closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));

      // loop through all of the seeable points from the current point
      for (Points neighbor : Seeable) {
        int wanz = 0;

        // Tentative F-Score = current G Score and the distance between current point and the
        // neighbor point
        tentGscore = currG + neighbor.lineLength;
        tentFscore = tentGscore + distance(neighbor.XPoint, neighbor.YPoint, endx, endy);

        for (int j = 0; j < closedset.size() - 1; j++) {
          // if neighbor point is in closedset and the tentative FScore is >= the neighbor's FScore
          if ((neighbor.XPoint == closedset.get(j).XPoint)
              && (neighbor.YPoint == closedset.get(j).YPoint)) {

            // give the neighbor the F and G score it already has in the closed set
            neighbor.costF = closedset.get(j).costF;
            neighbor.costG = closedset.get(j).costG;
          }
        }

        // if the neighbor point is not in the open set, or the tentative FScore of the current
        // point is less than the FScore of the neighbor point
        if ((!openset.contains(neighbor)) || tentFscore < neighbor.costF) {

          // assign the current point as the "travelled from" point for the neighbor point
          neighbor.camefromx = currX;
          neighbor.camefromy = currY;

          // give the F and G scores of the current point to the neighbor point
          neighbor.costG = tentGscore;
          neighbor.costF = tentFscore;

          // Check to see if the current neighbor is in the open set
          for (int i = 0; i < openset.size() - 1; i++) {
            if ((neighbor.XPoint == openset.get(i).XPoint)
                && (neighbor.YPoint == openset.get(i).YPoint)) {
              wanz++;
            }
          }

          // If not, add to the open set
          if (wanz == 0) {
            openset = addStuff(openset, neighbor);
          }
        }
      }
    }
    return completedPath;
  }