示例#1
0
 public java.lang.Object application(java.lang.String testcase) {
   int seed = Integer.parseInt(testcase);
   queue = new java.util.Vector();
   ccr.app.Coordinates location = null;
   java.util.Random rand = new java.util.Random(seed);
   ccr.app.CCRScenarios scenarios = new ccr.app.CCRScenarios(seed);
   long t;
   ccr.app.Coordinates actLoc;
   ccr.app.Coordinates estLoc;
   ccr.app.Coordinates lastLoc;
   double dist;
   double displace;
   double error;
   int c = 0;
   int bPos = -1;
   int cPos = -1;
   int stay = 0;
   int lastPos = -1;
   timestamp = System.currentTimeMillis();
   counter = 0;
   int moved = 0;
   int reliable = 0;
   ccr.app.Coordinates lastLocation = new ccr.app.Coordinates(0, 0);
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   t = 0;
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (++location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   while (cPos == -1
       || cPos == bPos
       || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
           < WALK_DIST) {
     cPos = rand.nextInt(CCRScenarios.POS_NUM);
   }
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   lastLoc = scenarios.getActLoc(sid, lastPos);
   dist = Coordinates.calDist(lastLoc, actLoc);
   t = (long) (dist / VELOCITY * 1000);
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     lastPos = cPos;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   while (cPos == -1
       || cPos == bPos
       || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
           < WALK_DIST) {
     cPos = rand.nextInt(CCRScenarios.POS_NUM);
   }
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   lastLoc = scenarios.getActLoc(sid, lastPos);
   dist = Coordinates.calDist(lastLoc, actLoc);
   t = (long) (dist / VELOCITY * 1000);
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     lastPos = cPos;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   while (cPos == -1
       || cPos == bPos
       || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
           < WALK_DIST) {
     cPos = rand.nextInt(CCRScenarios.POS_NUM);
   }
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   lastLoc = scenarios.getActLoc(sid, lastPos);
   dist = Coordinates.calDist(lastLoc, actLoc);
   t = (long) (dist / VELOCITY * 1000);
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     lastPos = cPos;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   while (cPos == -1
       || cPos == bPos
       || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
           < WALK_DIST) {
     cPos = rand.nextInt(CCRScenarios.POS_NUM);
   }
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   lastLoc = scenarios.getActLoc(sid, lastPos);
   dist = Coordinates.calDist(lastLoc, actLoc);
   t = (long) (dist / VELOCITY * 1000);
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     lastPos = cPos;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   cPos = rand.nextInt(CCRScenarios.POS_NUM);
   while (cPos == -1
       || cPos == bPos
       || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
           < WALK_DIST) {
     cPos = rand.nextInt(CCRScenarios.POS_NUM);
   }
   stay = rand.nextInt(MAX_STAY) + 1;
   c = c + stay;
   bPos = cPos;
   stay = stay - 1;
   actLoc = scenarios.getActLoc(sid, cPos);
   estLoc = scenarios.getEstLoc(sid, cPos);
   curEstX = estLoc.x;
   curEstY = estLoc.y;
   curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
   lastLoc = scenarios.getActLoc(sid, lastPos);
   dist = Coordinates.calDist(lastLoc, actLoc);
   t = (long) (dist / VELOCITY * 1000);
   timestamp = timestamp + t;
   lastPos = cPos;
   candidate = generateCtx();
   resolve();
   location = toCoordinates(candidate);
   displace =
       Math.sqrt(
           (location.x - lastLocation.x) * (location.x - lastLocation.x)
               + (location.y - lastLocation.y) * (location.y - lastLocation.y));
   moved = moved + toBoolean(displace);
   error =
       Math.sqrt(
           (actLoc.x - location.x) * (actLoc.x - location.x)
               + (actLoc.y - location.y) * (actLoc.y - location.y));
   lastLocation = location;
   counter = counter + 1;
   while (stay > 0) {
     stay = stay - 1;
     actLoc = scenarios.getActLoc(sid, cPos);
     estLoc = scenarios.getEstLoc(sid, cPos);
     curEstX = estLoc.x;
     curEstY = estLoc.y;
     curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE;
     lastLoc = scenarios.getActLoc(sid, lastPos);
     dist = Coordinates.calDist(lastLoc, actLoc);
     t = STAY_TIME;
     timestamp = timestamp + t;
     lastPos = cPos;
     candidate = generateCtx();
     resolve();
     location = toCoordinates(candidate);
     displace =
         Math.sqrt(
             (location.x - lastLocation.x) * (location.x - lastLocation.x)
                 + (location.y - lastLocation.y) * (location.y - lastLocation.y));
     moved = moved + toBoolean(displace);
     error =
         Math.sqrt(
             (actLoc.x - location.x) * (actLoc.x - location.x)
                 + (actLoc.y - location.y) * (actLoc.y - location.y));
     if (error <= ERR) {
       reliable = reliable + 1;
     }
     lastLocation = location;
     counter = counter + 1;
   }
   ccr.app.ApplicationResult result = new ccr.app.ApplicationResult(moved, reliable);
   return result;
 }
示例#2
0
  public Object application(String testcase) {

    // Program ID [c]

    // Ordinary Variable [location, lastLocation, moved, reliable, displace, error, curEstX,
    // curEstY, c, bPos, cPos, stay, lastPos, timestamp, counter, t, actLoc, estLoc, lastLoc, dist]

    // Context Variable [candidate]

    // Assignment [=]

    int seed = Integer.parseInt(testcase);
    queue = new Vector();
    Coordinates location = null;
    Random rand = new Random(seed);
    CCRScenarios scenarios = new CCRScenarios(seed);
    long t;
    Coordinates actLoc;
    Coordinates estLoc;
    Coordinates lastLoc;
    double dist;
    double displace;
    double error;

    // ENTRY // NODE

    int c = 0;
    int bPos = -1;
    int cPos = -1;
    int stay = 0;
    //	int mode = MODE_MIX;
    int lastPos = -1;
    timestamp = System.currentTimeMillis();
    counter = 0;
    //	double distance = 0;
    int moved = 0;
    int reliable = 0;
    Coordinates lastLocation = new Coordinates(0, 0);

    // initial
    //	if (bPos == -1) {
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    //	} else {
    //		cPos = rand.nextInt(CCRScenarios.POS_NUM);
    //		while (cPos == -1 || cPos == bPos ||
    //			Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) <
    // WALK_DIST) {
    //			cPos = rand.nextInt(CCRScenarios.POS_NUM);
    //		}
    //	}
    stay = rand.nextInt(MAX_STAY) + 1;
    //	mode = MODE_MIX; // Experimentation: Variation on mode
    //	if (mode == MODE_WALK) {
    //		stay = 1;  // Always walk without stay
    //	}
    //	if (c + stay > PATH_LEN) {
    //		stay = PATH_LEN - c;
    //	}
    c = c + stay;
    bPos = cPos;

    stay = stay - 1; // initial

    actLoc = scenarios.getActLoc(sid, cPos);
    // Set the estimated location for pos
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;

    // Apply the noise
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)

    // Decide the time we should wait before sending the next context
    t = 0; // Only for the first time
    //	if (lastPos != -1) {  // Not the first time
    //		lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    //		dist = Coordinates.calDist(lastLoc, actLoc);
    //		if (lastPos != cPos) {  // Walk
    //			t = (long) (dist / VELOCITY * 1000); // Estimated time required from lastLoc to actLoc
    //		} else {  // Stay
    //			t = STAY_TIME;
    //		}
    //	}
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	System.out.println(counter + ":\t(" + location.x + ", " + location.y + ")");
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;

    while (stay > 0) { // initial
      stay = stay - 1;

      actLoc = scenarios.getActLoc(sid, cPos);
      // Set the estimated location for pos
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;

      // Apply the noise
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)

      // Decide the time we should wait before sending the next context
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      //	if (lastPos != cPos) {  // Walk
      //		t = (long) (dist / VELOCITY * 1000); // Estimated time required from lastLoc to actLoc
      //	} else {  // Stay
      t = STAY_TIME;
      //	}
      timestamp = timestamp + t;
      //	lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	System.out.println(counter + ":\t(" + location.x + ", " + location.y + ")");
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    // 1
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    while (cPos == -1
        || cPos == bPos
        || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
            < WALK_DIST) {
      cPos = rand.nextInt(CCRScenarios.POS_NUM);
    }
    stay = rand.nextInt(MAX_STAY) + 1;
    c = c + stay;
    bPos = cPos;
    stay = stay - 1; // 1
    actLoc = scenarios.getActLoc(sid, cPos);
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    dist = Coordinates.calDist(lastLoc, actLoc);
    t =
        (long)
            (dist / VELOCITY
                * 1000); // Experimentation: Estimated time required from lastLoc to actLoc
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;
    while (stay > 0) { // 1
      stay = stay - 1;
      actLoc = scenarios.getActLoc(sid, cPos);
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      t = STAY_TIME; // Experimentation:
      timestamp = timestamp + t;
      lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    // 2
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    while (cPos == -1
        || cPos == bPos
        || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
            < WALK_DIST) {
      cPos = rand.nextInt(CCRScenarios.POS_NUM);
    }
    stay = rand.nextInt(MAX_STAY) + 1;
    c = c + stay;
    bPos = cPos;
    stay = stay - 1; // 2
    actLoc = scenarios.getActLoc(sid, cPos);
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    dist = Coordinates.calDist(lastLoc, actLoc);
    t =
        (long)
            (dist / VELOCITY
                * 1000); // Experimentation: Estimated time required from lastLoc to actLoc
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;
    while (stay > 0) { // 2
      stay = stay - 1;
      actLoc = scenarios.getActLoc(sid, cPos);
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      t = STAY_TIME; // Experimentation:
      timestamp = timestamp + t;
      lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    // 3
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    while (cPos == -1
        || cPos == bPos
        || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
            < WALK_DIST) {
      cPos = rand.nextInt(CCRScenarios.POS_NUM);
    }
    stay = rand.nextInt(MAX_STAY) + 1;
    c = c + stay;
    bPos = cPos;
    stay = stay - 1; // 3
    actLoc = scenarios.getActLoc(sid, cPos);
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    dist = Coordinates.calDist(lastLoc, actLoc);
    t =
        (long)
            (dist / VELOCITY
                * 1000); // Experimentation: Estimated time required from lastLoc to actLoc
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;
    while (stay > 0) { // 3
      stay = stay - 1;
      actLoc = scenarios.getActLoc(sid, cPos);
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      t = STAY_TIME; // Experimentation:
      timestamp = timestamp + t;
      lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    // 4
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    while (cPos == -1
        || cPos == bPos
        || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
            < WALK_DIST) {
      cPos = rand.nextInt(CCRScenarios.POS_NUM);
    }
    stay = rand.nextInt(MAX_STAY) + 1;
    c = c + stay;
    bPos = cPos;
    stay = stay - 1; // 4
    actLoc = scenarios.getActLoc(sid, cPos);
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    dist = Coordinates.calDist(lastLoc, actLoc);
    t =
        (long)
            (dist / VELOCITY
                * 1000); // Experimentation: Estimated time required from lastLoc to actLoc
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;
    while (stay > 0) { // 4
      stay = stay - 1;
      actLoc = scenarios.getActLoc(sid, cPos);
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      t = STAY_TIME; // Experimentation:
      timestamp = timestamp + t;
      lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    // 5
    cPos = rand.nextInt(CCRScenarios.POS_NUM);
    while (cPos == -1
        || cPos == bPos
        || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos))
            < WALK_DIST) {
      cPos = rand.nextInt(CCRScenarios.POS_NUM);
    }
    stay = rand.nextInt(MAX_STAY) + 1;
    c = c + stay;
    bPos = cPos;
    stay = stay - 1; // 5
    actLoc = scenarios.getActLoc(sid, cPos);
    estLoc = scenarios.getEstLoc(sid, cPos);
    curEstX = estLoc.x;
    curEstY = estLoc.y;
    curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
    lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
    dist = Coordinates.calDist(lastLoc, actLoc);
    t =
        (long)
            (dist / VELOCITY
                * 1000); // Experimentation: Estimated time required from lastLoc to actLoc
    timestamp = timestamp + t;
    lastPos = cPos;
    candidate = generateCtx();
    resolve();
    location = toCoordinates(candidate);
    //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments: calculate
    // distance
    displace =
        Math.sqrt(
            (location.x - lastLocation.x) * (location.x - lastLocation.x)
                + (location.y - lastLocation.y) * (location.y - lastLocation.y));
    moved = moved + toBoolean(displace);
    error =
        Math.sqrt(
            (actLoc.x - location.x) * (actLoc.x - location.x)
                + (actLoc.y - location.y) * (actLoc.y - location.y));
    lastLocation = location;
    counter = counter + 1;
    while (stay > 0) { // 5
      stay = stay - 1;
      actLoc = scenarios.getActLoc(sid, cPos);
      estLoc = scenarios.getEstLoc(sid, cPos);
      curEstX = estLoc.x;
      curEstY = estLoc.y;
      curEstX =
          curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      curEstY =
          curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; // [- NOISE, + NOISE)
      lastLoc = scenarios.getActLoc(sid, lastPos); // The actual location for lastPos
      dist = Coordinates.calDist(lastLoc, actLoc);
      t = STAY_TIME; // Experimentation:
      timestamp = timestamp + t;
      lastPos = cPos;
      candidate = generateCtx();
      resolve();
      location = toCoordinates(candidate);
      //	distance = distance + Coordinates.calDist(location, lastLocation); // Experiments:
      // calculate distance
      displace =
          Math.sqrt(
              (location.x - lastLocation.x) * (location.x - lastLocation.x)
                  + (location.y - lastLocation.y) * (location.y - lastLocation.y));
      moved = moved + toBoolean(displace);
      error =
          Math.sqrt(
              (actLoc.x - location.x) * (actLoc.x - location.x)
                  + (actLoc.y - location.y) * (actLoc.y - location.y));
      if (error <= ERR) {
        reliable = reliable + 1;
      }
      lastLocation = location;
      counter = counter + 1;
    }

    //	Double result = new Double(distance);
    ApplicationResult result = new ApplicationResult(moved, reliable);
    // EXIT // NODE

    return result;
  }