@Override
  public int compare(Distance o1, Distance o2) {
    if (o1.getCosine_similarity() < o2.getCosine_similarity()) return 1;
    else if (o1.getCosine_similarity() > o2.getCosine_similarity()) return -1;

    return 0;
  }
 /**
  * Identify segments of continuous walls in a vertical direction
  *
  * @param sl
  */
 private void generateSegmentsForVerticalWalls(ArrayList<Seg> sl) {
   int x;
   int y;
   // we search for vertical walls, so for each row
   for (x = 0; x != width; x++) {
     y = 0;
     while (y < height) {
       // find the beginning of a segment
       if (cells.hasNoWallOnLeft(x, y)) {
         y++;
         continue;
       }
       int starty = y;
       // find the end of a segment
       while (cells.hasWallOnLeft(x, y)) {
         y++;
         if (y == height) break;
         if (cells.hasWallOnTop(x, y)) break;
       }
       // create segment with (x,starty) being being the actual start position of the segment,
       // y-starty being the positive length
       sl.add(
           new Seg(
               x * Constants.MAP_UNIT,
               starty * Constants.MAP_UNIT,
               0,
               (y - starty) * Constants.MAP_UNIT,
               dists.getDistance(x, starty),
               colchange));
     }
     y = 0;
     while (y < height) {
       // find the beginning of a segment
       if (cells.hasNoWallOnRight(x, y)) {
         y++;
         continue;
       }
       int starty = y;
       // find the end of a segment
       while (cells.hasWallOnRight(x, y)) {
         y++;
         if (y == height) break;
         if (cells.hasWallOnTop(x, y)) break;
       }
       // create segment with (x+1,y) being being one off in both directions from the last cell in
       // this segment, starty-y being the negative length
       // since we are looking at right walls, one off in the right direction (x+1) are then cells
       // that have this segment on its left hand side
       sl.add(
           new Seg(
               (x + 1) * Constants.MAP_UNIT,
               y * Constants.MAP_UNIT,
               0,
               (starty - y) * Constants.MAP_UNIT,
               dists.getDistance(x, starty),
               colchange));
     }
   }
 }
  private void testStrategy(Strategy distanceStrategy) throws UDFArgumentException, HiveException {
    Distance distance = new Distance();

    Object result = distance.evaluate(distanceStrategy.getName(), "hello", "hello");
    Assert.assertNotNull(result);
    Float dist = (Float) result;
    Assert.assertEquals(1.0, dist, 0f);
  }
  /**
   * Call back method for MazeBuilder to communicate newly generated maze as reaction to a call to
   * build()
   *
   * @param root node for traversals, used for the first person perspective
   * @param cells encodes the maze with its walls and border
   * @param dists encodes the solution by providing distances to the exit for each position in the
   *     maze
   * @param startx current position, x coordinate
   * @param starty current position, y coordinate
   */
  public void newMaze(BSPNode root, Cells c, Distance dists, int startx, int starty) {
    if (Cells
        .deepdebugWall) { // for debugging: dump the sequence of all deleted walls to a log file
      // This reveals how the maze was generated
      c.saveLogFile(Cells.deepedebugWallFileName);
    }
    // adjust internal state of maze model
    showMaze = showSolution = solving = false;
    mazecells = c;
    mazedists = dists;
    seencells = new Cells(mazew + 1, mazeh + 1);
    rootnode = root;
    setCurrentDirection(1, 0);
    setCurrentPosition(startx, starty);
    walkStep = 0;
    viewdx = dx << 16;
    viewdy = dy << 16;
    angle = 0;
    mapMode = false;

    cleanViews();

    // Set up the robot and the robot driver.
    setUpRobotDriver();

    // register views for the new maze
    // mazew and mazeh have been set in build() method before mazebuider was called to generate a
    // new maze.
    // reset map_scale in mapdrawer to a value of 18 ///// WAS 10////
    addView(
        new FirstPersonDrawer(
            Constants.VIEW_WIDTH,
            Constants.VIEW_HEIGHT,
            Constants.MAP_UNIT,
            Constants.STEP_SIZE,
            mazecells,
            seencells,
            18,
            mazedists.getDists(),
            mazew,
            mazeh,
            root,
            this));
    // order of registration matters, code executed in order of appearance!
    addView(
        new MapDrawer(
            Constants.VIEW_WIDTH,
            Constants.VIEW_HEIGHT,
            Constants.MAP_UNIT,
            Constants.STEP_SIZE,
            mazecells,
            seencells,
            18,
            mazedists.getDists(),
            mazew,
            mazeh,
            this));
  }
  @Test
  public void testEvaluateWithStrategyNotFound() throws HiveException {
    Distance distance = new Distance();

    try {
      distance.evaluate("dd", "dd", "dd");
      Assert.fail();
    } catch (HiveException ex) {

    }
  }
  @Test
  public void testEvaluateWithNullValues() throws HiveException {
    Distance distance = new Distance();

    try {
      distance.evaluate(null, null, null);
      Assert.fail();
    } catch (HiveException ex) {

    }
  }
 public SlidePuzzle(int width, int height, String puzzle) {
   history = new History();
   this.width = width;
   this.height = height;
   this.puzzle = puzzle;
   correctPuzzle = Util.createAnswerPanel(puzzle);
   distance = new Distance(width, height, correctPuzzle);
   char[][] chars = Util.createBoard(width, height, puzzle);
   board = new Board(width, height, puzzle);
   int distInt = distance.getAllDistance(chars);
   int maxDistInt = distance.getMaxDistance(chars);
   history.putHistory(puzzle, "", distInt, maxDistInt);
   answerBoard = new AnswerBoard();
   answerBoard.put(puzzle, distInt, distance.getMaxDistance(chars));
 }
  public static void main(String[] args) {
    point newPoint = new point();

    System.out.println("Please enter your starting X point.");
    Scanner input = new Scanner(System.in);
    double startInputX = input.nextDouble();

    System.out.println("Please enter your starting Y point.");
    double startInputY = input.nextDouble();

    newPoint.x = startInputX;
    newPoint.y = startInputY;

    System.out.println(
        "What would you like to do? \n"
            + "Calculate your distance to another point? \t\t\t\t\t\t\t Please Press 1 \n"
            + "Calculate your distance to the origin? \t\t\t\t\t\t\t\t Please Press 2 \n"
            + "Change the co-ordinates of your current point? \t\t\t\t\t\t\t Please Press 3 \n"
            + "Find out the co-ordinates of your current point? \t\t\t\t\t\t Please Press 4 \n"
            + "Reverse the cartesian plane of your point (negative to positive co-ordinates or vice versa)? \t Please Press 5 \n");

    Distance A = new Distance();

    int Choice = input.nextInt();
    if (Choice == 1) {
      A.distanceTo(newPoint.x, newPoint.y);
    }
    if (Choice == 2) {
      A.distanceToOrigin();
    }
    if (Choice == 3) {
      System.out.println("Please enter your move-to-X point.");
      double startInput2X = input.nextDouble();

      System.out.println("Please enter your move-to-Y point.");
      double startInput2Y = input.nextDouble();

      A.moveTo(startInput2X, startInput2Y);
    }
    if (Choice == 4) {
      point newPoint1 = new point();
      newPoint1.Clone();
    }
    if (Choice == 5) {
      point newPoint2 = new point();
      newPoint2.opposite(newPoint.x, newPoint.y);
    }
  }
Beispiel #9
0
 /**
  * Adds a new distance functor for the given attribute data type.
  *
  * @param type the attribute data type
  * @param d the distance functor to use on the data type
  */
 public static final void putDistanceFunctorFor(String type, Distance d) {
   Map<String, Distance> fs = distanceMap.get(type);
   if (fs == null) {
     fs = new HashMap<String, Distance>();
   }
   fs.put(d.toString(), d);
   distanceMap.put(type, fs);
 }
 public String toString() {
   return "Distance mirror of "
       + source.comment()
       + " "
       + source.atom1().number()
       + " "
       + source.atom2().number()
       + " "
       + distance()
       + " "
       + dDistanceDx()
       + " "
       + dDistanceDy()
       + " "
       + dDistanceDz()
       + " ";
 }
  /**
   * * 移動とその距離をhistoryに加える処理。
   *
   * @param operation
   * @param position
   * @param currentDistance
   * @param currentMaxDistance
   */
  private void move(
      String operation, MovedPosition position, int currentDistance, int currentMaxDistance) {
    String boardStr = board.getBoardString();
    char changedChar = position.getC();
    int oldX = position.getOldX();
    int oldY = position.getOldY();
    int newX = position.getNewX();
    int newY = position.getNewY();
    if (history.getOperationHistory(boardStr) == null) {
      char[][] c = Util.createBoard(width, height, boardStr);
      int newDistance =
          distance.getNewDistance(changedChar, oldX, oldY, newX, newY, currentDistance);
      int newMaxDistance = distance.getMaxDistance(c);

      answerBoard.put(boardStr, newDistance, newMaxDistance);
      history.putHistory(boardStr, operation, newDistance, newMaxDistance);
    }
  }
Beispiel #12
0
 /**
  * @param P indeks analizowanego pixela
  * @param eps promień sąsiedztwa
  * @return lista sąsiadów danego pixela w zadanym promieniu eps
  */
 private List<Integer> regionQuery(int P, double eps) {
   List<Integer> neighbours = new ArrayList<>();
   double tmp;
   for (int i = 0; i < colors.length; i++) {
     if (P != i) {
       tmp = dist.compute(colors[P], colors[i]);
       if (tmp <= eps) neighbours.add(i);
     }
   }
   return neighbours;
 }
  public void calculate(View view) {
    EditText flyingDistanceTextBox =
        (EditText) findViewById(R.id.flyingdistancecourseFlyingDistanceOutput);
    EditText courseTextBox = (EditText) findViewById(R.id.flyingdistancecourseCourse_2);

    double flyingDistance = 0;
    double course = 0;
    Distance d = new Distance();
    flyingDistance = Calculation.calcFlyDis(airportOneChoice, airportTwoChoice);
    course = Calculation.calcCourBwAir(airportOneChoice, airportTwoChoice);

    if (distanceUnitChoice.equalsIgnoreCase("SM")) {
      flyingDistance = d.kilomToStat(flyingDistance);
      flyingDistanceTextBox.setText((String.format("%.2f", flyingDistance)));
    } else if (distanceUnitChoice.equalsIgnoreCase("NM")) {
      flyingDistance = d.kilomToNaut(flyingDistance);
      flyingDistanceTextBox.setText((String.format("%.2f", flyingDistance)));
    } else {
      flyingDistanceTextBox.setText((String.format("%.2f", flyingDistance)));
    }

    courseTextBox.setText(String.format("%.2f", course));
  }
Beispiel #14
0
 /**
  * Print a trip for the request on the standard input to the standard output, using the map data
  * in MAPFILENAME.
  */
 private static void trip(String mapFileName) {
   createMap(mapFileName);
   Scanner requests = new Scanner(System.in);
   requests.useDelimiter("\\n+");
   while (requests.hasNext()) {
     String request = requests.next().trim();
     String[] locations = request.split("\\s*,\\s+");
     if (locations.length > 1) {
       System.out.printf("From %s:%n%n", locations[0]);
       Graph<Location, Distance>.Vertex startV, endV, currV;
       String start, end, currentLocation;
       for (int j = 1; j < locations.length; j++) {
         currentLocation = start = locations[j - 1];
         end = locations[j];
         _destinations.add(end);
         currV = startV = findVertex(start);
         endV = findVertex(end);
         for (Graph<Location, Distance>.Edge road :
             Graphs.shortestPath(_map, startV, endV, new Length())) {
           Distance currentRoad = road.getLabel();
           String roadName = currentRoad.toString();
           String direction = currentRoad.getDirection(currentLocation);
           String len = String.valueOf(currentRoad.weight());
           currV = road.getV(currV);
           currentLocation = currV.getLabel().toString();
           _data.add(new String[] {roadName, len, direction, currentLocation});
         }
         addInstruction();
       }
       finallyPrintInstructions();
     } else {
       System.err.printf("User must provide more than one location in" + " one line.");
     }
   }
   requests.close();
 }
Beispiel #15
0
 public Location[] findLocationsInRadius(String json, double radius) {
   JSONArray locationPool = new JSONArray(json);
   for (int i = 0; i <= locationPool.length() - 1; ++i) {
     latitude = locationPool.getJSONObject(i).getDouble("Longitude");
     longitude = locationPool.getJSONObject(i).getDouble("Latitude");
     boolean inRadius =
         Distance.isInRadius(
             ownLocation.buildCoordinate(), new Point2D.Double(latitude, longitude), radius);
     if (inRadius) {
       String name = locationPool.getJSONObject(i).getString("Name");
       Location result = new Location(name, longitude, latitude);
       locationInRadius[i] = result;
     }
   }
   return locationInRadius;
 }
Beispiel #16
0
 /**
  * Wyznacza reprezentanta danej grupy
  *
  * @param colors Lista kolorów należących do danej grupy
  * @return Kolor reprezentuący daną grupę
  */
 public Color findRep(List<Color> colors) {
   double r = 0.0, g = 0.0, b = 0.0, dst = Double.POSITIVE_INFINITY, tmp;
   double s = (double) colors.size();
   Color ret = new Color(0, 0, 0);
   for (Color c : colors) {
     r += c.vec[0];
     g += c.vec[1];
     b += c.vec[2];
   }
   r /= s;
   g /= s;
   b /= s;
   Color crep = new Color((int) r, (int) g, (int) b);
   for (Color c : colors) {
     tmp = dist.compute(c, crep);
     if (tmp < dst) {
       dst = tmp;
       ret = c;
     }
   }
   return ret;
 }
 public boolean isSimilar(String name1, String name2) {
   return distance.LD(name1, name2) <= maximumDistance;
 }
Beispiel #18
0
  public PointsDouble calc(Vector[] x, Vector[] mu, Vector[] sigma2, double[][] uebergangsw) {
    double[][] s = new double[x.length][mu.length];
    int[][] r = new int[x.length][mu.length];

    // ---Erste Spalte---
    s[0][0] = 1; // d.calcDistance(mu[0], x[0], sigma2[0]);
    for (int j = 1; j < mu.length; j++) {
      s[0][j] = Double.POSITIVE_INFINITY;
    }

    // ---Iteriere über Spalten---
    for (int i = 1; i < x.length; i++) {
      for (int j = 0; j < mu.length; j++) {

        // k=0
        // System.out.println("i-1 " + (i-1) + " j " + j);
        double min = s[i - 1][j] + uebergangsw[j][j];
        // double distance = s[i-1][j];
        int k = j;
        // k=1
        if (j > 0) {
          if (s[i - 1][j - 1] + uebergangsw[j - 1][j] < min) {
            min = s[i - 1][j - 1] + uebergangsw[j - 1][j];
            k = j - 1;
          }
        }
        // k=2
        if (j > 1) {
          if (s[i - 1][j - 2] + uebergangsw[j - 2][j] < min) {
            min = s[i - 1][j - 2] + uebergangsw[j - 2][j];
            k = j - 2;
          }
        }

        r[i][j] = k;
        s[i][j] = min + d.calcDistance(x[i], mu[j], sigma2[j]);
      }
    }

    /*System.out.println("\nRückwärtszeiger");
    for(int i = 0; i < r.length; i++){
        for(int j = 0; j < r[i].length; j++){
            System.out.print(r[i][j] + " ");
        }
        System.out.println("");
    }
    System.out.println("");*/

    // ---Rückwärtszeiger verfolgen---
    // TODO: hier
    Point[] p = new Point[x.length];
    int j = mu.length - 1; // Endzustand
    for (int i = x.length - 1; i >= 0; i--) {
      p[i] = new Point(i, j);
      // j -= r[i][j];
      j = r[i][j];
    }

    /*System.out.println("a x");
    for (Point p1 : p) {
        System.out.println(p1.x + " " + p1.y);
    }
    System.out.println("");*/

    // todo: Überprüfung ob n-1 m-1 Knoten Minimum ist??? Vermutlich nicht, man nimmt einfach den
    // n-1 m-1 Knoten?
    /*for (j = model.length - 1; j >= 0; j--) {
        for (int i = 0; i < x.length; i++) {
            System.out.print(s[i][j] + " ");
        }
        System.out.println("");
    }*/

    return new PointsDouble(p, s[x.length - 1][mu.length - 1]);
  }
 @Override
 public double Compute(double[] u, double[] v) {
   return Distance.Manhattan(u, v);
 }
 @Override
 public double Compute(double[] u, double[] v) {
   return Distance.Canberra(u, v);
 }
 public final double dz() {
   return 0 - source.dz();
 }
 public final double dDistanceDz() {
   return 0 - source.dDistanceDz();
 }
Beispiel #23
0
 public double centroidDifference() {
   return Distance.euclidian(oldCentroid, centroid);
 }
 public final double distance2() {
   return source.distance2();
 }
 public final Atom atom2() {
   return source.atom2();
 }
 public final double invDistance() {
   return source.invDistance();
 }
 /**
  * Identify segments of continuous walls in a horizontal direction
  *
  * @param sl
  */
 private void generateSegmentForHorizontalWalls(ArrayList<Seg> sl) {
   int x;
   int y;
   // we search for horizontal walls, so for each column
   for (y = 0; y != height; y++) {
     // first round through rows
     x = 0;
     while (x < width) {
       // find the beginning of a segment
       if (cells.hasNoWallOnTop(x, y)) {
         x++;
         continue;
       }
       // found one
       int startx = x;
       // find the end of a segment
       // follow segment with wall on top till
       // x is the first index of a cell that has no wall on top
       // stop at outer bound or when hitting a wall (cell has wall on left)
       // such that length of the segment is startx-x, which is a negative value btw
       while (cells.hasWallOnTop(x, y)) {
         x++;
         if (x == width) break;
         if (cells.hasWallOnLeft(x, y)) break;
       }
       // create segment with (x,y) being the end positions, startx-x being the negative length
       // note the (x,y) is not part of the segment
       sl.add(
           new Seg(
               x * Constants.MAP_UNIT,
               y * Constants.MAP_UNIT,
               (startx - x) * Constants.MAP_UNIT,
               0,
               dists.getDistance(startx, y),
               colchange));
     }
     // second round through rows, same for bottom walls
     x = 0;
     while (x < width) {
       // find the beginning of a segment
       if (cells.hasNoWallOnBottom(x, y)) {
         x++;
         continue;
       }
       int startx = x;
       // find the end of a segment
       while (cells.hasWallOnBottom(x, y)) {
         x++;
         if (x == width) break;
         if (cells.hasWallOnLeft(x, y)) break;
       }
       // create segment with (startx,y+1) being one below the start position, x-startx being the
       // positive length
       // so this may represent a bottom wall segment as a top wall segment one below
       sl.add(
           new Seg(
               startx * Constants.MAP_UNIT,
               (y + 1) * Constants.MAP_UNIT,
               (x - startx) * Constants.MAP_UNIT,
               0,
               dists.getDistance(startx, y),
               colchange));
     }
   }
 }