Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eqasim.core.scenario.cutter.extent.ScenarioExtent;
import org.eqasim.core.scenario.cutter.extent.ShapeScenarioExtent;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
Expand All @@ -10,31 +12,45 @@
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.io.MatsimNetworkReader;

import java.net.MalformedURLException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;

public class CreateDrtVehicles {
private final static Logger logger = LogManager.getLogger(CreateDrtVehicles.class);

public final static long DEFAULT_RANDOM_SEED = 1234;

public static void main(String[] args) throws CommandLine.ConfigurationException, MalformedURLException {
public static void main(String[] args) throws CommandLine.ConfigurationException, IOException {
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("network-path", "output-vehicles-path", "vehicles-number")
.allowOptions("vehicles-capacity", "service-begin-time", "service-end-time", "vehicle-id-prefix")
.allowOptions("random-seed")
.allowOptions("service-area-path")
.build();
int vehiclesNumber = Integer.parseInt(cmd.getOptionStrict("vehicles-number"));
int vehiclesCapacity = cmd.hasOption("vehicles-capacity") ? Integer.parseInt(cmd.getOptionStrict("vehicles-capacity")) : 4;
int serviceBeginTime = cmd.hasOption("service-begin-time") ? Integer.parseInt(cmd.getOptionStrict("service-begin-time")) : 0;
int serviceEndTime = cmd.hasOption("service-end-time") ? Integer.parseInt(cmd.getOptionStrict("service-end-time")) : 24 * 3600;
long randomSeed = cmd.hasOption("random-seed") ? Long.parseLong(cmd.getOptionStrict("random-seed")) : DEFAULT_RANDOM_SEED;
String vehicleIdPrefx = cmd.getOption("vehicle-id-prefix").orElse("vehicle_drt_");
String serviceArea = cmd.getOption("service-area-path").orElse(null);
Network network = NetworkUtils.createNetwork();
new MatsimNetworkReader(network).readFile(cmd.getOptionStrict("network-path"));
List<Id<Link>> linksIds = new ArrayList<>(network.getLinks().keySet());
List<Id<Link>> linksIds;
if(serviceArea != null) {
ScenarioExtent extent = new ShapeScenarioExtent.Builder(new File(serviceArea), Optional.empty(), Optional.empty()).build();
linksIds = network.getLinks().values().stream()
.filter(link -> extent.isInside(link.getFromNode().getCoord()) || extent.isInside(link.getToNode().getCoord()))
.map(Link::getId)
.collect(Collectors.toList());
} else {
linksIds = new ArrayList<>(network.getLinks().keySet());
}
Random random = new Random(randomSeed);
FleetSpecification fleetSpecification = new FleetSpecificationImpl();
for(int i=0; i<vehiclesNumber; i++) {
Expand All @@ -43,7 +59,7 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
linkId = linksIds.get(random.nextInt(linksIds.size()));
}
Id<DvrpVehicle> vehicleId = Id.create(vehicleIdPrefx+i, DvrpVehicle.class);
logger.info("Creating vehicle " + vehicleId.toString() + " on link " + linkId.toString());
logger.info("Creating vehicle " + vehicleId.toString() + " on link " + linkId);
DvrpVehicleSpecification dvrpVehicleSpecification = ImmutableDvrpVehicleSpecification.newBuilder().id(vehicleId).startLinkId(linkId).serviceBeginTime(serviceBeginTime).serviceEndTime(serviceEndTime).capacity(vehiclesCapacity).build();
fleetSpecification.addVehicleSpecification(dvrpVehicleSpecification);
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/test/java/org/eqasim/TestSimulationPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -331,7 +330,7 @@ public void testTransitWithAbstractAccess() throws CommandLine.ConfigurationExce
}

@Test
public void testVDF() throws CommandLine.ConfigurationException, MalformedURLException {
public void testVDF() throws CommandLine.ConfigurationException, IOException {
AdaptConfigForVDF.main(new String[] {
"--input-config-path", "melun_test/input/config.xml",
"--output-config-path", "melun_test/input/config_vdf.xml",
Expand Down