Package rinde.sim.core.model.pdp

Examples of rinde.sim.core.model.pdp.Parcel


  }

  @Override
  protected void tickImpl(TimeLapse time) {
    // Check if we can deliver nearby
    final Parcel delivery = getDelivery(time, 5);

    final RoadModel rm = roadModel.get();
    final PDPModel pm = pdpModel.get();

    if (delivery != null) {
      if (delivery.getDestination().equals(getPosition())
          && pm.getVehicleState(this) == VehicleState.IDLE) {
        pm.deliver(this, delivery, time);
      } else {
        rm.moveTo(this, delivery.getDestination(), time);
      }
      return;
    }

    // Otherwise, Check if we can pickup nearby
View Full Code Here


    }
  }

  @Nullable
  public Parcel getDelivery(TimeLapse time, int distance) {
    Parcel target = null;
    double closest = distance;
    final PDPModel pm = pdpModel.get();
    for (final Parcel p : pm.getContents(this)) {

      final double dist = Point.distance(roadModel.get().getPosition(this),
View Full Code Here

  public void testDrop(){
      final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
      model.register(truck);
      rm.register(truck);

      final Parcel pack = new TestParcel(new Point(2, 2), 100, 100, 2);
      model.register(pack);
      rm.register(pack);
      rm.addObjectAt(pack, new Point(1, 2));

      rm.followPath(truck, newLinkedList(asList(new Point(1, 2))),
View Full Code Here

  public void testPickupAfterDrop(){
      final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
      model.register(truck);
      rm.register(truck);

      final Parcel pack2 = new TestParcel(new Point(2, 2), 100, 100, 2);
      model.register(pack2);
      rm.register(pack2);
      rm.addObjectAt(pack2, new Point(1, 2));

      rm.followPath(truck, newLinkedList(asList(new Point(1, 2))),
View Full Code Here

      assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
}
 
  @Test
  public void testPickup() {
    final Parcel pack1 = new TestParcel(new Point(2, 2), 0, 0, 2);
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    model.register(pack1);
    model.register(truck);
    rm.register(pack1);
    rm.register(truck);
    rm.addObjectAt(pack1, new Point(1, 1));

    // nothing should happen
    truck.tick(TimeLapseFactory.create(0, 10000));

    assertEquals(0, model.getContentsSize(truck), EPSILON);
    assertTrue(model.getContents(truck).isEmpty());
    assertEquals(ParcelState.AVAILABLE, model.getParcelState(pack1));
    assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
    model.pickup(truck, pack1, TimeLapseFactory.create(0, 10000));
    assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack1));
    assertEquals(VehicleState.IDLE, model.getVehicleState(truck));

    assertFalse(rm.containsObject(pack1));
    assertTrue(model.containerContains(truck, pack1));
    assertEquals(2, model.getContentsSize(truck), EPSILON);
    assertTrue(model.getContents(truck).contains(pack1));
    assertEquals(1, model.getContents(truck).size());

    final Parcel pack2 = new TestParcel(new Point(2, 2), 100, 100, 2);
    model.register(pack2);
    rm.register(pack2);
    rm.addObjectAt(pack2, new Point(1, 2));

    rm.followPath(truck, newLinkedList(asList(new Point(1, 2))),
View Full Code Here

  }

  @Test
  public void testDelayedPickup() {

    final Parcel pack1 = new TestParcel(new Point(2, 2), 10, 10, 2);
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    model.register(pack1);
    model.register(truck);
    rm.register(pack1);
    rm.register(truck);
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void testPickupFail2() {
    // package not in roadmodel
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    rm.register(truck);
    final Parcel pack1 = new TestParcel(new Point(2, 2), 0, 0, 2.0);
    model.pickup(truck, pack1, TimeLapseFactory.create(0, 1));
  }
View Full Code Here

  public void testPickupFail3A() {
    // package not in available state (it is already been picked up)
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    rm.register(truck);
    model.register(truck);
    final Parcel pack1 = new TestParcel(new Point(2, 2), 10, 10, 2.0);
    rm.register(pack1);
    model.register(pack1);
    rm.addObjectAtSamePosition(pack1, truck);
    assertTrue(rm.equalPosition(truck, pack1));
    assertEquals(ParcelState.AVAILABLE, model.getParcelState(pack1));
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void testPickupFail3B() {
    // package is not registered
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    rm.register(truck);
    final Parcel pack1 = new TestParcel(new Point(2, 2), 0, 0, 2.0);
    rm.register(pack1);
    rm.addObjectAtSamePosition(pack1, truck);
    model.pickup(truck, pack1, TimeLapseFactory.create(0, 1));
  }
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void testPickupFail4() {
    final Vehicle truck = new TestVehicle(new Point(1, 1), 10.0, 1.0);
    rm.register(truck);
    final Parcel pack1 = new TestParcel(new Point(2, 2), 0, 0, 2.0);
    rm.register(pack1);
    rm.addObjectAtSamePosition(pack1, truck);
    model.register(pack1);
    model.pickup(truck, pack1, TimeLapseFactory.create(0, 1));
  }
View Full Code Here

TOP

Related Classes of rinde.sim.core.model.pdp.Parcel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.