Package rinde.sim.core

Examples of rinde.sim.core.TimeLapse


  @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));
View Full Code Here


    sc.stop();
    final long before = sc.simulator.getCurrentTime();
    sc.start();// should have no effect

    assertEquals(before, sc.simulator.getCurrentTime());
    final TimeLapse emptyTime = TimeLapseFactory.create(0, 1);
    emptyTime.consumeAll();
    sc.tick(emptyTime);
  }
View Full Code Here

      }
    });

    sc.start();
    sc.stop();
    final TimeLapse emptyTime = TimeLapseFactory.create(0, 1);
    emptyTime.consumeAll();
    sc.tick(emptyTime);
  }
View Full Code Here

  }

  static TimeLapse emptyTimeLapse = init();

  static TimeLapse init() {
    final TimeLapse tl = TimeLapseFactory.create(0, 1);
    tl.consumeAll();
    return tl;
  }
View Full Code Here

      rm.followPath(truck, newLinkedList(asList(new Point(1, 2))),
          TimeLapseFactory.create(0, 3600000));
      model.pickup(truck, pack, TimeLapseFactory.create(0, 40));
      model.continuePreviousActions(truck, TimeLapseFactory.create(0, 40));

      final TimeLapse tl = TimeLapseFactory.create(0, 40);
      model.continuePreviousActions(truck, tl);
      assertFalse(model.getContents(truck).isEmpty());
      assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack));
      assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
     
View Full Code Here

      rm.followPath(truck, newLinkedList(asList(new Point(1, 2))),
          TimeLapseFactory.create(0, 3600000));
      model.pickup(truck, pack2, TimeLapseFactory.create(0, 40));
      model.continuePreviousActions(truck, TimeLapseFactory.create(0, 40));

      final TimeLapse tl = TimeLapseFactory.create(0, 40);
      model.continuePreviousActions(truck, tl);
      assertFalse(model.getContents(truck).isEmpty());
      assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack2));
      assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
     
      //riding to other spot to drop
      rm.followPath(truck, newLinkedList(asList(new Point(2, 2))),
            TimeLapseFactory.create(0, 3600000));
     
      model.drop(truck, pack2, TimeLapseFactory.create(0, 100));
     
      final Vehicle truck2 = new TestVehicle(new Point(2, 2), 10.0, 1.0);
      model.register(truck2);
      rm.register(truck2);
     
      model.pickup(truck2, pack2, TimeLapseFactory.create(0, 40));
      model.continuePreviousActions(truck2, TimeLapseFactory.create(0, 40));

      final TimeLapse tl2 = TimeLapseFactory.create(0, 40);
      model.continuePreviousActions(truck2, tl2);
      assertFalse(model.getContents(truck2).isEmpty());
      assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack2));
      assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
}
View Full Code Here

    assertFalse(action.isDone());
    assertEquals(20, action.timeNeeded());
    assertEquals(ParcelState.PICKING_UP, model.getParcelState(pack2));
    assertEquals(VehicleState.PICKING_UP, model.getVehicleState(truck));

    final TimeLapse tl = TimeLapseFactory.create(0, 40);
    model.continuePreviousActions(truck, tl);
    assertTrue(action.isDone());
    assertEquals(0, action.timeNeeded());
    assertEquals(20, tl.getTimeLeft());
    assertEquals(ParcelState.IN_CARGO, model.getParcelState(pack2));
    assertEquals(VehicleState.IDLE, model.getVehicleState(truck));

  }
View Full Code Here

    model.deliver(truck, pack1, TimeLapseFactory.create(0, 8));
    assertEquals(ParcelState.DELIVERING, model.getParcelState(pack1));
    assertEquals(VehicleState.DELIVERING, model.getVehicleState(truck));

    final TimeLapse tl = TimeLapseFactory.create(0, 10);
    model.continuePreviousActions(truck, tl);
    assertEquals(ParcelState.DELIVERED, model.getParcelState(pack1));
    assertEquals(VehicleState.IDLE, model.getVehicleState(truck));
    assertEquals(8, tl.getTimeLeft());

    final Parcel pack2 = new TestParcel(new Point(2, 2), 10, 10, 2.0);
    rm.register(pack2);
    model.register(pack2);
    rm.addObjectAtSamePosition(pack2, truck);
View Full Code Here

    assertFalse(d.isTooEarly(p2, time(minute(12), minute(13))));
    assertFalse(d.isTooEarly(p2, time(minute(20), minute(21))));
  }

  void tick(long beginMinute, long endMinute, long consumeSeconds) {
    final TimeLapse tl = time(minute(beginMinute), minute(endMinute));
    if (consumeSeconds > 0) {
      tl.consume(consumeSeconds * 1000);
    }
    pm.tick(tl);
    d.tick(tl);
    assertSame(tl, d.getCurrentTime());
    assertFalse(tl.hasTimeLeft());

    // tests whether internal states of vehicle match the state of the pdp model
    // at all times
    if (pm.getVehicleState(d) == VehicleState.DELIVERING
        || pm.getVehicleState(d) == VehicleState.PICKING_UP) {
View Full Code Here

      if (route.isEmpty()) {
        return DefaultEvent.NOGO;
      }
      checkCurrentParcelOwnership();
      final PDPModel pm = pdpModel.get();
      final TimeLapse time = currentTime.get();
      final DefaultParcel cur = route.element();
      // we are not at the parcel's position, this means the next parcel has
      // changed in the mean time, so we have to reroute.
      if (!roadModel.get().equalPosition(context, cur)) {
        return DefaultEvent.REROUTE;
      }
      // if parcel is not ready yet, wait
      final boolean pickup = !pm.getContents(context).contains(cur);
      final long timeUntilReady = (pickup ? cur.dto.pickupTimeWindow.begin
          : cur.dto.deliveryTimeWindow.begin) - time.getTime();
      if (timeUntilReady > 0) {
        if (time.getTimeLeft() < timeUntilReady) {
          // in this case we can not yet start servicing
          time.consumeAll();
          return null;
        } else {
          time.consume(timeUntilReady);
        }
      }
      if (time.hasTimeLeft()) {
        return DefaultEvent.READY_TO_SERVICE;
      } else {
        return null;
      }
    }
View Full Code Here

TOP

Related Classes of rinde.sim.core.TimeLapse

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.