Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable to use part of the OD pairs #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -90,21 +90,27 @@ private NetworkCalibrator(Builder builder) {
this.departureTime = builder.departureTime;
}

public void performCalibration(Path odPairsPath) throws IOException, InterruptedException {
readOdPairs(odPairsPath);
public void performCalibration(Path odPairsPath, int maxOdPairsUsed) throws IOException, InterruptedException {
readOdPairs(odPairsPath, maxOdPairsUsed);
adjustNetworkAverageSpeed();
calibrate();
}

void readOdPairs(Path odPairsPath) throws IOException {
void readOdPairs(Path odPairsPath, int maxOdPairsUsed) throws IOException {
try (CSVParser parser = CSVFormat.Builder.create(CSVFormat.DEFAULT)
.setDelimiter(CsvUtils.detectDelimiter(odPairsPath.toString()))
.setHeader().setSkipHeaderRecord(true)
.build().parse(Files.newBufferedReader(odPairsPath))) {

int counter = 0;
for (CSVRecord record : parser.getRecords()) {
if (counter > maxOdPairsUsed) {
break;
}
String fromNodeIdString = record.get(FROM_NODE);
String toNodeIdString = record.get(TO_NODE);
odPairs.add(new Tuple<>(Id.createNodeId(fromNodeIdString), Id.createNodeId(toNodeIdString)));
counter++;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class RunNetworkCalibration implements MATSimAppCommand {
@CommandLine.Option(names = "--od-pairs", description = "Path to OD pair file (can also be the data base)", required = true)
private Path odPairsPath;

@CommandLine.Option(names = "--max-od-pairs-used", description = "At most top x of od pairs from the od pair files are" +
" used for calibration", defaultValue = "100000")
private int maxOdPairsUsed;

@CommandLine.Option(names = "--data-base", description = "Path to local data base (csv / tsv file)", required = true)
private String dataBase;

Expand Down Expand Up @@ -62,7 +66,7 @@ public Integer call() throws Exception {
NetworkCalibrator calibrator = new NetworkCalibrator.Builder(network, validator)
.setIterations(iterations).setCutOff(cutOff).setThreshold(threshold).setDepartureTime(departureTime)
.build();
calibrator.performCalibration(odPairsPath);
calibrator.performCalibration(odPairsPath, maxOdPairsUsed);
Map<Integer, Double> scores = calibrator.getScores();

// write calibrated network and score records
Expand Down