org.matsim.contrib.dvrp.fleet.ImmutableDvrpVehicleSpecification Java Examples

The following examples show how to use org.matsim.contrib.dvrp.fleet.ImmutableDvrpVehicleSpecification. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateFleetVehicles.java    From matsim-maas with GNU General Public License v2.0 6 votes vote down vote up
private void run() {

		Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
		new MatsimNetworkReader(scenario.getNetwork()).readFile(networkFile.toString());
		final int[] i = {0};
		Stream<DvrpVehicleSpecification> vehicleSpecificationStream = scenario.getNetwork().getLinks().entrySet().stream()
				.filter(entry -> entry.getValue().getAllowedModes().contains(TransportMode.car)) // drt can only start on links with Transport mode 'car'
				.sorted((e1, e2) -> (random.nextInt(2) - 1)) // shuffle links
				.limit(numberOfVehicles) // select the first *numberOfVehicles* links
				.map(entry -> ImmutableDvrpVehicleSpecification.newBuilder()
						.id(Id.create("drt_" + i[0]++, DvrpVehicle.class))
						.startLinkId(entry.getKey())
						.capacity(seatsPerVehicle)
						.serviceBeginTime(operationStartTime)
						.serviceEndTime(operationEndTime)
						.build());

		new FleetWriter(vehicleSpecificationStream).write(outputFile.toString());
	}
 
Example #2
Source File: VehicleToVSGenerator.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    int generatedNumberOfVehicles = 0;
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    placedVehicles = Array.zeros(virtualNetwork.getvNodesCount());

    while (generatedNumberOfVehicles < operatorConfig.getGeneratorConfig().getNumberOfVehicles()) {
        ++generatedNumberOfVehicles;
        int vNodeIndex = getNextVirtualNode();
        Link linkGen = getNextLink(virtualNetwork.getVirtualNode(vNodeIndex));
        /** update placedVehicles */
        placedVehicles.set(RealScalar.ONE::add, vNodeIndex);
        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(operatorConfig.getMode(), generatedNumberOfVehicles);
        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(linkGen.getId()) //
                .build());
    }
    return vehicles;
}
 
Example #3
Source File: RandomDensityGenerator.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    long generatedVehicles = 0;
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    while (generatedVehicles < operatorConfig.getGeneratorConfig().getNumberOfVehicles()) {
        ++generatedVehicles;

        int bound = network.getLinks().size();
        int elemRand = MatsimRandom.getRandom().nextInt(bound);
        Link link = network.getLinks().values().stream().skip(elemRand).findFirst().get();
        LOGGER.info("car placed at link " + link);

        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(operatorConfig.getMode(), generatedVehicles);
        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(link.getId()) //
                .build());
    }
    return vehicles;
}
 
Example #4
Source File: DemoGenerator.java    From amod with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    long generatedVehicles = 0;
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    while (generatedVehicles < operatorConfig.getGeneratorConfig().getNumberOfVehicles()) {
        ++generatedVehicles;

        /** select one of the 10 random links for placement */
        int elemRand = MatsimRandom.getRandom().nextInt(randomLinks.size());
        Link linkSel = randomLinks.stream().skip(elemRand).findFirst().get();

        LOGGER.info("car placed at link " + linkSel);

        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(operatorConfig.getMode(), generatedVehicles);

        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(linkSel.getId()) //
                .build());
    }
    return vehicles;
}
 
Example #5
Source File: PopulationDensityGenerator.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    Random random = new Random(randomSeed);

    int generatedNumberOfVehicles = 0;
    while (generatedNumberOfVehicles < numberOfVehicles) {
        generatedNumberOfVehicles++;

        // Multinomial selection
        double r = random.nextDouble();
        Link selectedLink = linkList.get(0);

        for (Link link : linkList) {
            if (r <= cumulativeDensity.get(link)) {
                selectedLink = link;
                break;
            }
        }

        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(mode, generatedNumberOfVehicles);

        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(selectedLink.getId()) //
                .build());
    }

    return vehicles;
}
 
Example #6
Source File: ArtificialSharedScenarioCreator.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
public ArtificialSharedScenarioCreator(Config config) {

        LinkTimePair divertableLinkTime = new LinkTimePair(linkDepotOut, 0.0);

        Id<DvrpVehicle> idAv1 = Id.create("av1", DvrpVehicle.class);
        vehicle1 = new DvrpVehicleImpl(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(idAv1) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(3) //
                .startLinkId(linkDepotOut.getId()) //
                .build(), linkDepotOut);
        roboTaxi1 = new RoboTaxi(vehicle1, divertableLinkTime, linkDepotOut, RoboTaxiUsageType.SHARED);
        setFirstStayTask(vehicle1);

        Id<DvrpVehicle> idAv2 = Id.create("av2", DvrpVehicle.class);
        vehicle2 = new DvrpVehicleImpl(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(idAv2) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(3) //
                .startLinkId(linkDepotOut.getId()) //
                .build(), linkDepotOut);
        roboTaxi2 = new RoboTaxi(vehicle2, divertableLinkTime, linkDepotOut, RoboTaxiUsageType.SHARED);
        setFirstStayTask(vehicle2);
        System.out.println("ArtificialScenario Created");
    }
 
Example #7
Source File: TestScenario.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    VehicleType vehicleType = VehicleUtils.getDefaultVehicleType();
    vehicleType.getCapacity().setSeats(capacity);

    return Collections.singletonList(ImmutableDvrpVehicleSpecification.newBuilder() //
            .id(Id.create("vehicle", DvrpVehicle.class)) //
            .startLinkId(link.getId()) //
            .serviceBeginTime(0.0) //
            .serviceEndTime(Double.POSITIVE_INFINITY) //
            .capacity(capacity) //
            .build());
}
 
Example #8
Source File: RunDrtTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
static public void createFleet(String path, int numberOfVehicles, Network network) {
    Random random = new Random(0);

    List<Link> links = network.getLinks().values().stream().filter(link -> link.getAllowedModes().contains("car")).collect(Collectors.toList());

    new FleetWriter(IntStream.range(0, 100).mapToObj(i -> {
        return ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(Id.create("drt" + i, DvrpVehicle.class)) //
                .startLinkId(links.get(random.nextInt(links.size())).getId()) //
                .capacity(4) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(30.0 * 3600.0) //
                .build();
    })).write(path);
}