Skip to content

Commit

Permalink
Update DrtFleetSizing.java
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 committed Sep 9, 2024
1 parent 2c91fa9 commit 502df1a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/org/matsim/run/DrtFleetSizing.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import org.matsim.rebalancing.WaitingPointsBasedRebalancingModule;
import picocli.CommandLine;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static org.matsim.application.ApplicationUtils.globFile;

public class DrtFleetSizing implements MATSimAppCommand {
@CommandLine.Option(names = "--run-folder", description = "Output folder of MATsim run", required = true)
private String runFolderPath;
private String matsimRunFolderPath;

@CommandLine.Option(names = "--target-wait-time", description = "the target average waiting time", required = true)
private double meanWaitTime;
Expand Down Expand Up @@ -60,8 +61,13 @@ public static void main(String[] args) {

@Override
public Integer call() throws Exception {
// write output root folder
if (!Files.exists(Path.of(outputFolderPath))){
Files.createDirectories(Path.of(outputFolderPath));
}

// read DRT trips and generate plans
Path outputPopulationPath = globFile(Path.of(runFolderPath), "*output_plans.xml.gz*");
Path outputPopulationPath = globFile(Path.of(matsimRunFolderPath), "*output_plans.xml.gz*");
MainModeIdentifier modeIdentifier = new DefaultAnalysisMainModeIdentifier();
Population outputPlans = PopulationUtils.readPopulation(outputPopulationPath.toString());
Population avPlans = PopulationUtils.createPopulation(ConfigUtils.createConfig());
Expand Down Expand Up @@ -92,7 +98,7 @@ public Integer call() throws Exception {
}
}
new PopulationWriter(avPlans).write(outputFolderPath + "/av-plans.xml.gz");

// run DRT simulations
Preconditions.checkArgument(fleetSizing.size() == 3);
int fleetFrom = fleetSizing.get(0);
Expand All @@ -106,8 +112,7 @@ public Integer call() throws Exception {
config.controller().setLastIteration(1);
config.controller().setOutputDirectory(outputFolderPath + "/" + fleetSize + "-veh");
config.vehicles().setVehiclesFile(vehiclesFolderPath + "/" + fleetSize + "-veh.xml");

String singleRunOutputDirectory = config.controller().getOutputDirectory();
String singleDrtRunOutputDirectory = config.controller().getOutputDirectory();

Controler controler = DrtControlerCreator.createControler(config, false);
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);
Expand All @@ -119,7 +124,7 @@ public Integer call() throws Exception {
controler.run();

// analyze mean waiting time
Path waitTimeStatsPath = globFile(Path.of(singleRunOutputDirectory), "*drt_customer_stats_av.csv*");
Path waitTimeStatsPath = globFile(Path.of(singleDrtRunOutputDirectory), "*drt_customer_stats_av.csv*");
double waitingTime = 0;
CSVFormat.Builder format = CSVFormat.DEFAULT.builder().setDelimiter(';').setHeader().setSkipHeaderRecord(true);
try (CSVParser parser = new CSVParser(IOUtils.getBufferedReader(waitTimeStatsPath.toString()), format.build())) {
Expand Down

0 comments on commit 502df1a

Please sign in to comment.