private boolean funcLocMixVeloOk(ccr.app.Context ctx1, ccr.app.Context ctx2) { java.lang.String v1 = (java.lang.String) ctx1.get(Context.FLD_OBJECT); java.lang.String v2 = (java.lang.String) ctx1.get(Context.FLD_TIMESTAMP); java.lang.String v3 = (java.lang.String) ctx2.get(Context.FLD_OBJECT); java.lang.String v4 = (java.lang.String) ctx2.get(Context.FLD_TIMESTAMP); if (v1 == null || v2 == null || v3 == null || v4 == null) { return false; } java.util.StringTokenizer st = new java.util.StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new java.util.StringTokenizer(v3); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; boolean result = false; double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000); double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000); double ve = dist / ((double) t / 1000); if (ve >= vmin && ve <= vmax) { result = true; } return result; }
private boolean funcLocMixVeloOk(Context ctx1, Context ctx2) { // boolean function 4 String v1 = (String) ctx1.get(Context.FLD_OBJECT); String v2 = (String) ctx1.get(Context.FLD_TIMESTAMP); String v3 = (String) ctx2.get(Context.FLD_OBJECT); String v4 = (String) ctx2.get(Context.FLD_TIMESTAMP); if (v1 == null || v2 == null || v3 == null || v4 == null) { return false; } StringTokenizer st = new StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new StringTokenizer(v3); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; // Different here // The velocity should be between vmin and vmax boolean result = false; double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000); double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000); double ve = dist / ((double) t / 1000); if (ve >= vmin && ve <= vmax) { result = true; } return result; }
private boolean funcLocDistOk(ccr.app.Context ctx1, ccr.app.Context ctx2) { java.lang.String v1 = (java.lang.String) ctx1.get(Context.FLD_OBJECT); java.lang.String v2 = (java.lang.String) ctx2.get(Context.FLD_OBJECT); if (v1 == null || v2 == null) { return false; } java.util.StringTokenizer st = new java.util.StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new java.util.StringTokenizer(v2); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); boolean result = false; if (dist <= 2 * ERR) { result = true; } return result; }
private boolean funcLocDistOk(Context ctx1, Context ctx2) { // boolean function 1 String v1 = (String) ctx1.get(Context.FLD_OBJECT); String v2 = (String) ctx2.get(Context.FLD_OBJECT); if (v1 == null || v2 == null) { return false; } StringTokenizer st = new StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new StringTokenizer(v2); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); // The distance should not be larger than two times the allowed error boolean result = false; if (dist <= 2 * ERR) { result = true; } return result; }
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; }
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; }