Skip to content

Commit

Permalink
Fixing generation of output csv files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvpsaraiva committed Nov 20, 2023
1 parent 754a790 commit 0cdaab0
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void setDecayFunction(String decayFunction, double decayValue) {
this.decayFunction.prepare();
}

@Override
protected boolean isOneToOne() {
return false;
}

public AccessibilityEstimator(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class DetailedItineraryPlanner extends R5Process {
private boolean dropItineraryGeometry = false;
public void dropItineraryGeometry() { dropItineraryGeometry = true; }

@Override
protected boolean isOneToOne() {
return true;
}

public DetailedItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ private boolean hasFares() {
return routingProperties.fareCalculator != null;
}

@Override
protected boolean isOneToOne() {
return true;
}

public FastDetailedItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

public class ParetoFrontierCalculator extends R5Process {

@Override
protected boolean isOneToOne() {
return false;
}

public ParetoFrontierCalculator(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class ParetoItineraryPlanner extends R5Process {

public static boolean travelAllowanceActive = true;

@Override
protected boolean isOneToOne() {
return true;
}

public ParetoItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
18 changes: 17 additions & 1 deletion java-r5rcore/src/org/ipea/r5r/Process/R5Process.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public abstract class R5Process {
protected int maxCarTime;
protected int maxTripDuration;

protected abstract boolean isOneToOne();

public R5Process(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
this.r5rThreadPool = threadPool;
this.transportNetwork = transportNetwork;
Expand Down Expand Up @@ -189,7 +191,7 @@ private RDataFrame tryRunProcess(AtomicInteger totalProcessed, int index) {
}

if (Utils.saveOutputToCsv & results != null) {
String filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + "_" + toIds[index] + ".csv";
String filename = getCsvFilename(index);
results.saveToCsv(filename);
results.clear();
}
Expand All @@ -204,6 +206,20 @@ private RDataFrame tryRunProcess(AtomicInteger totalProcessed, int index) {
return Utils.saveOutputToCsv ? null : results;
}

private String getCsvFilename(int index) {
String filename;
if (this.isOneToOne()) {
// one-to-one functions, such as detailed itineraries
// save one file per origin-destination pair
filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + "_to_" + toIds[index] + ".csv";
} else {
// one-to-many functions, such as travel time matrix
// save one file per origin
filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + ".csv";
}
return filename;
}

protected abstract RDataFrame runProcess(int index) throws ParseException;

private RDataFrame mergeResults(List<RDataFrame> processResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void unreachable() {

private static final Logger LOG = LoggerFactory.getLogger(TravelTimeMatrixComputer.class);

@Override
protected boolean isOneToOne() {
return false;
}

public TravelTimeMatrixComputer(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) {
super(threadPool, transportNetwork, routingProperties);
}
Expand Down
Binary file modified r-package/inst/jar/r5r.jar
Binary file not shown.

0 comments on commit 0cdaab0

Please sign in to comment.