Skip to content

Commit

Permalink
Use FleetReader
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Aug 29, 2024
1 parent d9c1986 commit 36a84da
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/org/matsim/dashboard/AdaptV2OutputFiles.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package org.matsim.dashboard;

import com.univocity.parsers.common.input.EOFException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.CsvOptions;
import org.matsim.vehicles.MatsimVehicleReader;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vehicles.Vehicles;
import org.matsim.contrib.dvrp.fleet.FleetReader;
import org.matsim.contrib.dvrp.fleet.FleetSpecification;
import org.matsim.contrib.dvrp.fleet.FleetSpecificationImpl;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import picocli.CommandLine;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.IntColumn;
import tech.tablesaw.api.Table;
import tech.tablesaw.io.csv.CsvReadOptions;

Expand Down Expand Up @@ -41,6 +44,8 @@
)
public class AdaptV2OutputFiles implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(AdaptV2OutputFiles.class);

@CommandLine.Option(names = "--runDir", description = "Path of V2 run directory with files to adapt.", required = true)
private String dir;

Expand Down Expand Up @@ -112,14 +117,12 @@ public Integer call() throws Exception {
}

if (!vehicleStats.containsColumn("totalServiceDuration")) {

Vehicles vehicles = VehicleUtils.createVehiclesContainer();
MatsimVehicleReader.VehicleReader vehicleReader = new MatsimVehicleReader.VehicleReader(vehicles);

vehicleReader.readFile(globFile(Path.of(dir), "*" + k + "_vehicles.xml").toString());
FleetSpecification fleet = new FleetSpecificationImpl();
new FleetReader(fleet).readFile(globFile(Path.of(dir), "*" + k + "_vehicles.xml*").toString());

AtomicReference<Double> serviceDuration = new AtomicReference<>(0.);
vehicles.getVehicles().values().forEach(veh -> serviceDuration.updateAndGet(v1 -> v1 + (Double) veh.getAttributes().getAttribute("t_1") - (Double) veh.getAttributes().getAttribute("t_0")));

fleet.getVehicleSpecifications().values().forEach(veh -> serviceDuration.updateAndGet(v1 -> v1 + veh.getServiceEndTime() - veh.getServiceBeginTime()));

double[] values = new double[vehicleStats.rowCount()];
Arrays.fill(values, serviceDuration.get());
Expand All @@ -146,8 +149,8 @@ public Integer call() throws Exception {

if (!customerStats.containsColumn("rides_pax") || !customerStats.containsColumn("groupSize_mean")) {
if (customerStats.containsColumn("rides")) {
DoubleColumn rides = customerStats.doubleColumn("rides");
DoubleColumn ridesPax = rides.copy().setName("rides_pax");
IntColumn rides = customerStats.intColumn("rides");
IntColumn ridesPax = rides.copy().setName("rides_pax");
customerStats.addColumns(ridesPax);
}
double[] defaultValues = new double[customerStats.rowCount()];
Expand Down Expand Up @@ -226,6 +229,9 @@ private static void copyFile(Path targetPath, File inputFile) {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
log.warn("File {} was not copied to target path {}. Please check if file already exists in target dir, the input file exists and the input file is not a directory."
, inputFile.getAbsolutePath(), targetPath);
}
}
}

0 comments on commit 36a84da

Please sign in to comment.