Example #1
0
 public static void main(String argv[]) {
   System.out.println("Alas");
   int max = 100;
   double averate = 0;
   double avedelta = 0;
   for (int i = 0; i < max; i++) {
     Color c1 = GetRandomColor();
     Color c2 = GetRandomColor();
     double Altitude1 = GetAltitude(c1);
     double Altitude2 = GetAltitude(c2);
     double dealtaltitude = Math.abs(Altitude1 - Altitude2);
     double dist = ColorDistCalculator.CalDist(c1, c2);
     double rate = Math.abs((dealtaltitude - dist) / dist);
     double delta = Math.abs((dealtaltitude - dist));
     averate += rate;
     avedelta += delta;
     System.out.println(
         c1.toHexString()
             + " "
             + c2.toHexString()
             + " "
             + Altitude1
             + " "
             + Altitude2
             + " "
             + dist);
   }
   averate /= max;
   avedelta /= max;
   System.out.println("Final " + averate + " " + avedelta);
 }
  public static void process(TreeMap<Double, Double> points, double threshold) {
    double[] sol;
    while (true) {
      sol = solve(points);

      double maxError = 0;
      double maxErrorPoint = 0;
      for (double s : points.keySet()) {
        double dist = Math.abs(s * sol[0] + sol[1] - points.get(s));
        if (dist > maxError) {
          maxError = dist;
          maxErrorPoint = s;
        }
      }

      points.remove(maxErrorPoint);
      if (maxError < threshold) break;
    }

    System.out.println(
        "solution: "
            + sol[0]
            + ", "
            + sol[1]
            + "; fix: "
            + sol[1] / (1 - sol[0])
            + "; "
            + points.size()
            + " points");
  }
  public void valueIteration(int i) {
    double delta;
    double v;
    List<State> states = mdp.getStates();
    State win = states.get(3);
    State death = states.get(7);
    State blocked = states.get(5);
    states.remove(win);
    states.remove(death);
    states.remove(blocked);
    while (true) {
      delta = 0;
      for (State s : states) {
        v = values.get(s);
        double vdelta = maxa(s);
        values.put(s, vdelta);
        //				System.out.println("vdelta: "+vdelta);
        delta = Math.max(delta, Math.abs(v - vdelta));
        //				System.out.println("delta:" + delta);

      }
      if (delta < EPS || i == 0) {
        //				values.put(mdp.getStates().get(3), 0.00);
        //				values.put(mdp.getStates().get(7), 0.00);
        return;
      }
      i--;
    }
  }
Example #4
0
 private void loop() {
   speed = Math.min(speed + DELAY / 1000d / RAMP, targetPower);
   if (Math.abs(angleError(targetAngle)) > Math.PI) System.out.println(angleError(targetAngle));
   if (Math.abs(angleError(targetAngle)) > Math.PI / 2) {
     steer.set(
         Math.max(
             -STEER_CAP, Math.min(STEER_CAP, STEER_GAIN * angleError(targetAngle - Math.PI))));
     drive.set(-speed);
   } else {
     steer.set(Math.max(-STEER_CAP, Math.min(STEER_CAP, STEER_GAIN * angleError(targetAngle))));
     drive.set(speed);
   }
   if (driveEncoder != null) {
     double enc = driveEncoder.get();
     double angle = getAngle() - gyro.getAngle() * Math.PI / 180 + Math.PI / 2;
     x += (enc - encLast) * Math.cos(angle);
     y += (enc - encLast) * Math.sin(angle);
     encLast = enc;
   }
   try {
     Thread.sleep(DELAY);
   } catch (Exception e) {
   }
 }