@Override public final void initRoadUser(RoadModel model) { checkState(!roadModel.isPresent(), "RoadModel can not be registered twice!"); roadModel = Optional.of(model); if (startPosition.isPresent()) { model.addObjectAt(this, startPosition.get()); } if (pdpModel.isPresent()) { isRegistered = true; initRoadPDP(roadModel.get(), pdpModel.get()); } }
@Test(expected = IllegalArgumentException.class) public void testPickupFail3A() { // package not in available state (it is already been picked up) final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); model.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .pickupDuration(10) .deliveryDuration(10) .neededCapacity(2d) .build(); rm.register(pack1); model.register(pack1); rm.addObjectAtSamePosition(pack1, truck); assertTrue(rm.equalPosition(truck, pack1)); assertEquals(ParcelState.AVAILABLE, model.getParcelState(pack1)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); model.pickup(truck, pack1, TimeLapseFactory.create(0, 100)); assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack1)); assertEquals(VehicleState.IDLE, model.getVehicleState(truck)); // checks what happens when you add a package to the roadmodel which has // already been picked up rm.addObjectAt(pack1, new Point(1, 1)); model.pickup(truck, pack1, TimeLapseFactory.create(0, 100)); }
@Override public void initRoadUser(RoadModel model) { model.addObjectAt(this, pos); }
@Override public void initRoadUser(RoadModel model) { roadModel = Optional.of(model); roadModel.get().addObjectAt(this, roadModel.get().getRandomPosition(rng)); }
@Override public void initRoadUser(RoadModel model) { roadModel = Optional.of(model); roadModel.get().addObjectAt(this, roadModel.get().getRandomPosition(rng)); }
@Override public void initRoadUser(RoadModel model) { final Point startPos = model.getRandomPosition(rng); model.addObjectAt(this, startPos); rm = Optional.of(model); setDestination(destPos); }
@Override public void initRoadUser(RoadModel model) { final Point startPos = model.getRandomPosition(rng); model.addObjectAt(this, startPos); rm = Optional.of(model); setDestination(destPos); }
@Override public void initRoadUser(RoadModel model) { roadModel = Optional.of(model); roadModel.get().addObjectAt(this, roadModel.get().getRandomPosition(rng)); }
@Override public void tick(TimeLapse timeLapse) { // every time step (tick) this gets called. Each time we chose a // different destination and move in that direction using the time // that was made available to us. if (!roadModel.containsObject(this)) { roadModel.addObjectAt(this, roadModel.getRandomPosition(rnd)); } roadModel.moveTo(this, roadModel.getRandomPosition(rnd), timeLapse); }
@Override public void tick(TimeLapse timeLapse) { // every time step (tick) this gets called. Each time we chose a // different destination and move in that direction using the time // that was made available to us. if (!roadModel.containsObject(this)) { roadModel.addObjectAt(this, roadModel.getRandomPosition(rnd)); } roadModel.moveTo(this, roadModel.getRandomPosition(rnd), timeLapse); }
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); }
allObjects = Arrays.asList(o1, o2, o3, o4, o5, o6); rm.addObjectAt(o1, a); rm.addObjectAt(o2, b); rm.addObjectAt(o3, c); rm.addObjectAt(o4, d); rm.addObjectAt(o5, e); rm.addObjectAt(o6, f);
@Test public void addPackageIn() { assertTrue(model.getParcels(ParcelState.AVAILABLE).isEmpty()); final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); model.register(d); model.register(p1); rm.addObjectAt(d, new Point(0, 0)); model.addParcelIn(d, p1); assertEquals(1, model.getContents(d).size()); assertTrue(model.getContents(d).contains(p1)); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail1() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); rm.addObjectAt(p1, new Point(0, 0)); model.addParcelIn(d, p1); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail5() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(11d) .build(); model.register(p1); model.register(d); rm.addObjectAt(d, new Point(0, 0)); model.addParcelIn(d, p1); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail5() { // wrong position final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); model.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); rm.addObjectAt(pack1, new Point(0, 0)); model.register(pack1); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Test public void moveToHeuristicTest() { final MovingRoadUser fastestPathAgent = new SpeedyRoadUser(10); final MovingRoadUser shortestPathAgent = new SpeedyRoadUser(10); final Point origin = new Point(0, 0); final Point destination = new Point(0, 10); final Point midway = new Point(5, 5); // Graph with slow direct (shortest) route, but fast longer route. final Graph<MultiAttributeData> graph = new TableGraph<>(); graph.addConnection(origin, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(1).build()); graph.addConnection(origin, midway, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); graph.addConnection(midway, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); final RoadModel moveModel = RoadModelBuilders.staticGraph(graph) .withDistanceUnit(SI.KILOMETER).withSpeedUnit(NonSI.KILOMETERS_PER_HOUR) .build(mock(DependencyProvider.class)); moveModel.addObjectAt(fastestPathAgent, origin); moveModel.addObjectAt(shortestPathAgent, origin); moveModel.moveTo(fastestPathAgent, destination, hour(1), GeomHeuristics.time(10)); moveModel.moveTo(shortestPathAgent, destination, hour(1), GeomHeuristics.euclidean()); // Agent chose speedy route assertEquals(midway, moveModel.getPosition(fastestPathAgent)); // Agent chose shortest route assertEquals(new Point(0, 1), moveModel.getPosition(shortestPathAgent)); }