Package rinde.sim.pdptw.central.Solvers

Examples of rinde.sim.pdptw.central.Solvers.SimulationConverter


  public void convertTest() {
    // time unit = hour
    PDPTWTestUtil.register(rm, pm, v1, p1);

    final TestSimAPI simAPI = new TestSimAPI(0, 1, NonSI.MINUTE);
    final SimulationConverter handle = Solvers.converterBuilder().with(mp)
        .with(simAPI).build();

    final StateContext sc = handle.convert(SolveArgs.create().useAllParcels()
        .noCurrentRoutes());
    assertEquals(ImmutableMap.of(v1.dto, v1), sc.vehicleMap);
    assertEquals(ImmutableMap.of(p1.dto, p1), sc.parcelMap);

    assertEquals(ImmutableSet.of(p1.dto), sc.state.availableParcels);
    checkVehicles(asList(v1), sc.state.vehicles);

    rm.moveTo(v1, p1, create(NonSI.HOUR, 0L, 1L));

    checkVehicles(
        asList(v1),
        handle.convert(SolveArgs.create().useAllParcels().noCurrentRoutes()).state.vehicles);

    rm.moveTo(v1, p1, create(NonSI.HOUR, 0, 40));
    assertTrue(rm.equalPosition(v1, p1));
    pm.service(v1, p1, create(NonSI.HOUR, 0, 1));

    assertEquals(VehicleState.PICKING_UP, pm.getVehicleState(v1));
    final StateContext sc2 = handle.convert(SolveArgs.create().useAllParcels()
        .noCurrentRoutes());

    assertTrue(sc2.state.availableParcels.contains(p1.dto));
    assertFalse(sc2.state.vehicles.get(0).contents.contains(p1.dto));
    assertSame(p1.dto, sc2.state.vehicles.get(0).destination);
View Full Code Here


        .iterator().next();
    rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000));
    assertEquals(destination, rm.getDestinationToParcel(v1));
    assertEquals(ParcelState.AVAILABLE, pm.getParcelState(p1));

    final SimulationConverter handle = Solvers.converterBuilder().with(mp)
        .with(simAPI).build();

    final StateContext sc = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertEquals(1, sc.state.availableParcels.size());
    assertEquals(0, sc.state.vehicles.get(0).contents.size());
    final Solver solver = SolverValidator.wrap(new MultiVehicleSolverAdapter(
        new RandomMVArraysSolver(new MersenneTwister(123)), NonSI.MINUTE));
    Solvers.solverBuilder(solver).with(mp).with(simAPI).build().solve(sc);

    // give enough time to reach destination
    rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000000000));
    assertEquals(rm.getPosition(destination), rm.getPosition(v1));

    pm.pickup(v1, destination, TimeLapseFactory.create(0, 1));
    assertEquals(VehicleState.PICKING_UP, pm.getVehicleState(v1));

    final StateContext sc2 = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertEquals(1, sc2.state.availableParcels.size());
    assertEquals(0, sc2.state.vehicles.get(0).contents.size());

    // finish pickup operation
    v1.tick(TimeLapseFactory.create(0, 1000000000));
    assertEquals(VehicleState.IDLE, pm.getVehicleState(v1));

    final StateContext sc3 = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertTrue(sc3.state.availableParcels.isEmpty());
    assertEquals(1, sc3.state.vehicles.get(0).contents.size());

    // move to delivery location
    rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000));
    assertEquals(destination, rm.getDestinationToParcel(v1));
    assertEquals(ParcelState.IN_CARGO, pm.getParcelState(p1));

    final StateContext sc4 = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertEquals(1, sc4.state.vehicles.get(0).contents.size());
    assertTrue(sc4.state.availableParcels.isEmpty());

    // service delivery
    rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000000000));
    assertEquals(destination.dto.destinationLocation, rm.getPosition(v1));
    pm.deliver(v1, p1, TimeLapseFactory.create(0, 1));
    assertNull(rm.getDestinationToParcel(v1));
    assertEquals(VehicleState.DELIVERING, pm.getVehicleState(v1));
    final StateContext sc5 = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertEquals(1, sc5.state.vehicles.get(0).contents.size());
    assertTrue(sc5.state.availableParcels.isEmpty());

    // finish delivery operation
    v1.tick(TimeLapseFactory.create(0, 1000000000));
    assertEquals(VehicleState.IDLE, pm.getVehicleState(v1));

    final StateContext sc6 = handle.convert(SolveArgs.create()
        .useParcels(ImmutableSet.<DefaultParcel> of())
        .noCurrentRoutes());
    assertTrue(sc6.state.vehicles.get(0).contents.isEmpty());
    assertTrue(sc6.state.availableParcels.isEmpty());
  }
View Full Code Here

  public void test() {
    final TestVehicle v1 = new TestVehicle(new Point(0, 1));
    final TestVehicle v2 = new TestVehicle(new Point(0, 1));
    PDPTWTestUtil.register(sim, p1, p2, p3, v1, v2);

    final SimulationConverter s = Solvers.converterBuilder().with(sim).build();

    StateContext res = s.convert(SolveArgs.create().useAllParcels()
        .noCurrentRoutes());
    assertEquals(2, res.state.vehicles.size());
    assertTrue(res.state.vehicles.get(0).contents.isEmpty());
    assertNull(res.state.vehicles.get(0).destination);
    assertEquals(3, res.state.availableParcels.size());
    assertEquals(v1.getWaitState(), v1.getState());

    // start moving: goto
    v1.setRoute(asList(p1, p2));
    assertEquals(asList(p1, p2), newArrayList(v1.getRoute()));
    assertEquals(new Point(0, 1), rm.getPosition(v1));
    sim.tick();

    while (v1.getState() == v1.getGotoState()) {
      assertFalse(new Point(0, 1).equals(rm.getPosition(v1)));
      res = s.convert(SolveArgs.create().useAllParcels().noCurrentRoutes());
      assertEquals(2, res.state.vehicles.size());
      assertTrue(res.state.vehicles.get(0).contents.isEmpty());
      assertEquals(p1.dto, res.state.vehicles.get(0).destination);
      assertEquals(3, res.state.availableParcels.size());
      assertEquals(v1.getGotoState(), v1.getState());
      sim.tick();
    }
    // arrived at parcel1: waitForService
    assertEquals(new Point(3, 0), rm.getPosition(v1));
    assertEquals(v1.getWaitForServiceState(), v1.getState());
    res = s.convert(SolveArgs.create().useAllParcels().noCurrentRoutes());
    assertEquals(2, res.state.vehicles.size());
    assertTrue(res.state.vehicles.get(0).contents.isEmpty());
    assertEquals(p1.dto, res.state.vehicles.get(0).destination);
    assertEquals(3, res.state.availableParcels.size());

    // start servicing: service
    sim.tick();
    assertEquals(v1.getServiceState(), v1.getState());
    res = s.convert(SolveArgs.create().useAllParcels().noCurrentRoutes());
    assertSame(p1.dto, res.state.vehicles.get(0).destination);
    assertEquals(v1.getServiceState(), v1.getState());
  }
View Full Code Here

    while (rfv.getRoute().size() > 0) {
      sim.tick();
    }

    final SimulationConverter simConv = Solvers.converterBuilder().with(sim)
        .build();
    final StateContext sc = simConv.convert(SolveArgs.create()
        .noCurrentRoutes().useAllParcels());

    final ArraysObject singleVehicleArrays = ArraysSolvers
        .toSingleVehicleArrays(sc.state,
            SI.MILLI(SI.SECOND));
View Full Code Here

TOP

Related Classes of rinde.sim.pdptw.central.Solvers.SimulationConverter

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.