@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof MoveProgress) { MoveProgress that = (MoveProgress) o; return (this.distance.equals(that.distance())) && (this.time.equals(that.time())) && (this.travelledNodes.equals(that.travelledNodes())); } return false; }
/** * Constructs a new {@link MoveProgress} instance using all information that * was added via this builder. This method may be called only once per * builder. * @return A new {@link MoveProgress} instance. */ public MoveProgress build() { checkState(!used, "This method may be called only once."); used = true; final Measure<Double, Length> distTraveled = unitConversion .toExDistMeasure(travelDistance); final Measure<Long, Duration> timeConsumed = Measure.valueOf( time.getTimeConsumed() - startTimeConsumed, time.getTimeUnit()); return create(distTraveled, timeConsumed, traveledNodes); } }
verify(e instanceof MoveEvent); final MoveEvent me = (MoveEvent) e; increment((MovingRoadUser) me.roadUser, me.pathProgress.distance() .getValue() .doubleValue()); totalDistance += me.pathProgress.distance().getValue().doubleValue(); totalTime += me.pathProgress.time().getValue(); ((Vehicle) me.roadUser).getStartPosition()) < MOVE_THRESHOLD) { if (me.pathProgress.distance().getValue() .doubleValue() > MOVE_THRESHOLD) { lastArrivalTimeAtDepot.put((MovingRoadUser) me.roadUser,
if (mp != null) { final double correctedDist = unitConversion.toInDist(mp.distance().getValue().doubleValue()) - distToTo; final Measure<Double, Length> distTraveled = unitConversion .toExDistMeasure(correctedDist); mp = MoveProgress.create(distTraveled, mp.time(), mp.travelledNodes());
@Override public void tick(TimeLapse timeLapse) { if (!destination.isPresent()) { nextDestination(); } final MoveProgress mp = roadModel.get().moveTo(this, destination.get(), timeLapse); if (roadModel.get().getPosition(this).equals(destination.get()) || stuckTickCount >= MAX_STUCK_TICK_COUNT) { nextDestination(); stuckTickCount = 0; } else if (mp.distance().getValue().doubleValue() == 0d) { stuckTickCount++; } else { stuckTickCount = 0; } }
assertEquals(38d, mp.distance().getValue().doubleValue(), GraphRoadModelImpl.DELTA); assertEquals(NE, model.getPosition(tru)); assertEquals(asList(NW, SW, SE, NE), mp.travelledNodes()); assertEquals(10d, mp2.distance().getValue().doubleValue(), GraphRoadModelImpl.DELTA); assertEquals(asList(SE, X, SW), mp2.travelledNodes()); assertEquals(SW, model.getPosition(tru)); assertEquals(18d, mp3.distance().getValue().doubleValue(), GraphRoadModelImpl.DELTA); assertEquals(asList(SW, SE), mp3.travelledNodes()); assertEquals(SE, model.getPosition(tru));
final Point objLoc = verifyLocation(registry().getPosition(object)); Point tempLoc = objLoc; final MoveProgress.Builder mpBuilder = MoveProgress.builder(unitConversion, time);
verify(e instanceof MoveEvent); final MoveEvent me = (MoveEvent) e; increment((MovingRoadUser) me.roadUser, me.pathProgress.distance() .getValue() .doubleValue()); totalDistance += me.pathProgress.distance().getValue().doubleValue(); totalTime += me.pathProgress.time().getValue(); ((Vehicle) me.roadUser).getStartPosition()) < MOVE_THRESHOLD) { if (me.pathProgress.distance().getValue() .doubleValue() > MOVE_THRESHOLD) { lastArrivalTimeAtDepot.put((MovingRoadUser) me.roadUser,
@Override public void tick(TimeLapse timeLapse) { if (!destination.isPresent()) { nextDestination(); } final MoveProgress mp = roadModel.get().moveTo(this, destination.get(), timeLapse); if (roadModel.get().getPosition(this).equals(destination.get()) || stuckTickCount >= MAX_STUCK_TICK_COUNT) { nextDestination(); stuckTickCount = 0; } else if (mp.distance().getValue().doubleValue() == 0d) { stuckTickCount++; } else { stuckTickCount = 0; } }
static void checkNoMovement(MoveProgress mp) { assertTrue(mp.travelledNodes().isEmpty()); assertEquals(0L, mp.time().getValue().longValue()); assertEquals(0d, mp.distance().getValue().doubleValue(), 0); } }
/** * Follow path */ @Test public void followPathAllAtOnce() { final SpeedyRoadUser agent = new SpeedyRoadUser(18000000d); // sc.from(5, TimeUnit.MS) // .to(TimeUnit.H)); model.addObjectAt(agent, SW); assertEquals(SW, model.getPosition(agent)); final Queue<Point> path = asPath(SW, SE, NE); final MoveProgress travelled = model.followPath(agent, path, timeLength(5)); assertEquals(20, travelled.distance().getValue(), EPSILON); assertEquals(4, travelled.time().getValue().longValue()); assertEquals(0, path.size()); assertEquals(NE, model.getPosition(agent)); }
public void compatibilityCheck(List<Point> t) { final MovingRoadUser truck = new TrivialRoadUser(); rm.addObjectAt(truck, t.get(0)); final double len = pathLength(t); // speed of trivial truck is 1 len per hour thus we need to travel 'len' // hours final MoveProgress progress = rm.followPath( truck, new LinkedList<Point>(t), TimeLapseFactory.create(NonSI.HOUR, 0, DoubleMath.roundToLong(len, RoundingMode.CEILING))); assertEquals(len, progress.distance().getValue(), EPSILON); }
@SuppressWarnings({"unused", "null"}) @Test(expected = IllegalArgumentException.class) public void pathProgressConstructorFail1() { MoveProgress.create(meter(-1), durationSecond(1), new ArrayList<Point>()); }
/** * Situation: <code>SW ->- tru1 ->- SE </code><br> * tru1 wants to move directly to SW, which should throw an exception since * moving backward over an directed connection is not allowed. */ @Test(expected = IllegalArgumentException.class) public void followPathFailIllegalPath1() { final TestRoadUser testRoadUser = new TestRoadUser(); model.addObjectAt(testRoadUser, SW); final Queue<Point> p = new LinkedList<Point>(Arrays.asList(SW, SE)); final MoveProgress progress = model.followPath(testRoadUser, p, timeLength(3600000)); assertEquals(1.0, progress.distance().getValue(), EPSILON); assertEquals(asList(SE), p); assertEquals(3600000, progress.time().getValue().longValue()); assertEquals(asList(SW), progress.travelledNodes()); model.followPath(testRoadUser, asPath(SW), timeLength(1)); }
@Test public void followPathAllAtOnce() { final int timeNeeded = DoubleMath.roundToInt(pathLength / speed * 1.5, RoundingMode.CEILING); final TimeLapse timeLapse = TimeLapseFactory.create(NonSI.HOUR, 0, timeNeeded); final SpeedyRoadUser agent = new SpeedyRoadUser(speed); model.addObjectAt(agent, new Point(0, 0)); assertEquals(new Point(0, 0), model.getPosition(agent)); assertEquals(5, path.size()); final MoveProgress travelled = model.followPath(agent, path, timeLapse); assertTrue(timeLapse.hasTimeLeft()); assertEquals(pathLength, travelled.distance().getValue(), DELTA); assertTrue("time spend < timeNeeded", timeNeeded > travelled.time().getValue()); assertEquals(0, path.size()); assertEquals(new Point(5, 15), model.getPosition(agent)); }
@Test public void followPathStepByStep() { final SpeedyRoadUser agent = new SpeedyRoadUser(speed); model.addObjectAt(agent, new Point(0, 0)); assertEquals(new Point(0, 0), model.getPosition(agent)); assertEquals(5, path.size()); final MoveProgress progress = model.followPath(agent, path, AbstractRoadModelTest.hour()); assertEquals(speed, progress.distance().getValue(), DELTA); assertEquals(4, path.size()); }
@SuppressWarnings({"unused", "null"}) @Test(expected = IllegalArgumentException.class) public void pathProgressConstructorFail2() { MoveProgress.create(meter(1), durationSecond(-1), new ArrayList<Point>()); }
@Test public void followPath() { final MovingRoadUser mru = new TestRoadUser(); model.addObjectAt(mru, new Point(0, 0)); final Queue<Point> path = asPath(new Point(0, 0), new Point(5, 0), new Point( 5, 5)); final MoveProgress pp = model.followPath(mru, path, hour()); assertEquals(asPath(new Point(5, 0), new Point(5, 5)), path); assertEquals(1, pp.distance().getValue(), EPSILON); assertEquals(hour().getTickLength(), pp.time().getValue(), EPSILON); assertEquals(asList(new Point(0, 0)), pp.travelledNodes()); assertTrue( Point.distance(new Point(1, 0), model.getPosition(mru)) < EPSILON); final MoveProgress pp2 = model.followPath(mru, path, hour(5)); assertEquals(asPath(new Point(5, 5)), path); assertEquals(5, pp2.distance().getValue(), EPSILON); assertEquals(hour(5).getTickLength(), pp2.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 0)), pp2.travelledNodes()); assertTrue( Point.distance(new Point(5, 1), model.getPosition(mru)) < EPSILON); final MoveProgress pp3 = model.followPath(mru, path, hour(50)); assertTrue(path.isEmpty()); assertEquals(4, pp3.distance().getValue(), EPSILON); assertEquals(hour(4).getTickLength(), pp3.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 5)), pp3.travelledNodes()); assertTrue( Point.distance(new Point(5, 5), model.getPosition(mru)) < EPSILON); }
assertEquals(5d, progress.distance().getValue(), EPSILON); assertEquals(2, path.size()); assertEquals(new Point(5, 0), model.getPosition(agent)); assertEquals(10, progress.distance().getValue(), EPSILON); assertEquals(1, path.size()); assertEquals(new Point(10, 5), model.getPosition(agent)); assertEquals(5, progress.distance().getValue(), EPSILON); assertEquals(Measure.valueOf(1L, NonSI.HOUR).to(SI.MILLI(SI.SECOND)), progress.time()); assertEquals(0, path.size()); assertEquals(new Point(10, 10), model.getPosition(agent));
@Test public void followPathNotTillEnd() { final MovingRoadUser agent = new SpeedyRoadUser(1); model.addObjectAt(agent, new Point(0, 0)); assertEquals(new Point(0, 0), model.getPosition(agent)); final Queue<Point> path = asPath(SW, SE, NE); MoveProgress travelled = model.followPath(agent, path, hour(10)); assertEquals(10d, travelled.distance().getValue(), EPSILON); assertEquals(1, path.size()); travelled = model.followPath(agent, path, hour(1)); assertEquals(1d, travelled.distance().getValue(), EPSILON); assertEquals(1, path.size()); assertEquals(new Point(10, 1), model.getPosition(agent)); }