Permalink
Browse files

cleanups

  • Loading branch information...
akegermany committed Sep 5, 2018
1 parent a654fdc commit 29cf86d6dee6699d9c54d0a941a71fb6d70813ea
Showing with 212 additions and 376 deletions.
  1. +7 −6 core/src/main/java/org/movsim/input/network/OpenDriveReader.java
  2. +14 −21 core/src/main/java/org/movsim/output/FileDetector.java
  3. +2 −2 core/src/main/java/org/movsim/output/FileTrafficLightControllerRecorder.java
  4. +6 −8 core/src/main/java/org/movsim/output/FileTrafficSinkData.java
  5. +6 −9 core/src/main/java/org/movsim/output/FileTrafficSourceData.java
  6. +13 −28 core/src/main/java/org/movsim/output/SimulationOutput.java
  7. +28 −36 core/src/main/java/org/movsim/output/floatingcars/FileFloatingCars.java
  8. +0 −10 core/src/main/java/org/movsim/output/floatingcars/FloatingCars.java
  9. +0 −2 core/src/main/java/org/movsim/output/route/ConsumptionOnRoute.java
  10. +6 −7 core/src/main/java/org/movsim/output/route/FileConsumptionOnRoute.java
  11. +8 −7 core/src/main/java/org/movsim/output/route/FileIndividualTravelTimesOnRoute.java
  12. +6 −6 core/src/main/java/org/movsim/output/route/FileSpatioTemporal.java
  13. +1 −3 core/src/main/java/org/movsim/output/route/FileTrajectories.java
  14. +8 −8 core/src/main/java/org/movsim/output/route/FileTravelTimeOnRoute.java
  15. +9 −11 core/src/main/java/org/movsim/output/route/IndividualTravelTimesOnRoute.java
  16. +1 −2 core/src/main/java/org/movsim/output/route/OutputOnRouteBase.java
  17. +6 −6 core/src/main/java/org/movsim/output/route/SpatioTemporal.java
  18. +10 −11 core/src/main/java/org/movsim/output/route/TravelTimeOnRoute.java
  19. +1 −5 core/src/main/java/org/movsim/roadmappings/RoadGeometry.java
  20. +4 −3 core/src/main/java/org/movsim/roadmappings/RoadMapping.java
  21. +12 −18 core/src/main/java/org/movsim/roadmappings/RoadMappingArc.java
  22. +27 −44 core/src/main/java/org/movsim/roadmappings/RoadMappingBezier.java
  23. +19 −32 core/src/main/java/org/movsim/roadmappings/RoadMappingLine.java
  24. +2 −5 core/src/main/java/org/movsim/roadmappings/RoadMappingPeer.java
  25. +3 −4 core/src/main/java/org/movsim/roadmappings/RoadMappingPoly.java
  26. +7 −39 core/src/main/java/org/movsim/roadmappings/RoadMappingPolyBezier.java
  27. +0 −26 core/src/main/java/org/movsim/roadmappings/RoadMappingPolyLine.java
  28. +3 −2 core/src/main/java/org/movsim/roadmappings/RoadMappingSpiral.java
  29. +2 −13 core/src/main/java/org/movsim/roadmappings/RoadMappingUtils.java
  30. +1 −2 core/src/main/java/org/movsim/simulator/Simulator.java
@@ -1,15 +1,16 @@
package org.movsim.input.network;
import org.movsim.simulator.roadnetwork.RoadNetwork;
import java.io.File;
import javax.xml.bind.JAXBException;
public final class OpenDriveReader {
import org.movsim.simulator.roadnetwork.RoadNetwork;
import org.xml.sax.SAXException;
public class OpenDriveReader {
private OpenDriveReader() {
// do not invoke
}
public static boolean loadRoadNetwork(RoadNetwork roadNetwork, File xodrFile) throws JAXBException, SAXException {
public static boolean loadRoadNetwork(RoadNetwork roadNetwork, File xodrFile) {
return OpenDriveHandler.loadRoadNetwork(roadNetwork, xodrFile);
}
@@ -33,39 +33,32 @@
public class FileDetector extends FileOutputBase {
private static final String extensionFormat = ".det.road_%s.x_%d.csv";
private static final String EXTENSION_FORMAT = ".det.road_%s.x_%d.csv";
private static final String outputHeadingTime = String.format("%s%10s,", COMMENT_CHAR, "t[s]");
private static final String outputHeadingLaneAverage = String.format("%10s,%10s,%10s,%10s,%10s,%10s,%10s,",
private static final String OUTPUT_HEADING_TIME = String.format("%s%10s,", COMMENT_CHAR, "t[s]");
private static final String OUTPUT_HEADING_LANE_AVERAGE = String.format("%10s,%10s,%10s,%10s,%10s,%10s,%10s,",
"nVehTotal[1]", "nTotalAccum[1]", "V[km/h]", "flow[1/h/lane]", "occup[1]", "1/<1/v>[km/h]",
"<1/Tbrut>[1/s]");
private static final String outputHeadingLane = String.format("%10s,%10s,%10s,%10s,%10s,%10s,%10s,", "nVeh[1]",
private static final String OUTPUT_HEADING_LANE = String.format("%10s,%10s,%10s,%10s,%10s,%10s,%10s,", "nVeh[1]",
"nAccum[1]", "V[km/h]", "flow[1/h]", "occup[1]", "1/<1/v>[km/h]", "<1/Tbrut>[1/s]");
// note: number before decimal point is total width of field, not width of
// integer part
private static final String outputFormatTime = "%10.1f, ";
private static final String outputFormat = "%10d, %10d, %10.3f, %10.1f, %10.7f, %10.3f, %10.5f, ";
private static final String OUTPUT_FORMAT_TIME = "%10.1f, ";
private static final String OUTPUT_FORMAT = "%10d, %10d, %10.3f, %10.1f, %10.7f, %10.3f, %10.5f, ";
private final LoopDetector detector;
private int laneCount;
private final boolean loggingLanes;
/**
* Instantiates a new file detector.
*
* @param detector
* the detector
* @param laneCount
*/
public FileDetector(LoopDetector detector, String roadId, int laneCount, boolean loggingLanes) {
super(ProjectMetaData.getInstance().getOutputPath(), ProjectMetaData.getInstance().getProjectName());
final int xDetectorInt = (int) detector.position();
this.detector = detector;
this.laneCount = laneCount;
this.loggingLanes = (loggingLanes || laneCount == 1) ? true : false;
this.loggingLanes = (loggingLanes || laneCount == 1);
writer = createWriter(String.format(extensionFormat, roadId, xDetectorInt));
writer = createWriter(String.format(EXTENSION_FORMAT, roadId, xDetectorInt));
writeHeader();
}
@@ -75,13 +68,13 @@ private void writeHeader() {
laneCount, Lanes.MOST_INNER_LANE);
writer.printf(COMMENT_CHAR + " dtSample in seconds = %-8.4f%n", detector.getDtSample());
writer.printf(COMMENT_CHAR + " logging lanes = %s%n", loggingLanes);
writer.printf(outputHeadingTime);
writer.printf(OUTPUT_HEADING_TIME);
if (laneCount > 1) {
write(outputHeadingLaneAverage);
write(OUTPUT_HEADING_LANE_AVERAGE);
}
if (loggingLanes) {
for (int i = 0; i < laneCount; i++) {
write(outputHeadingLane);
write(OUTPUT_HEADING_LANE);
}
}
writer.printf("%n");
@@ -92,7 +85,7 @@ private void writeHeader() {
* Pulls data and writes aggregated data to output file.
*/
public void writeAggregatedData(double time) {
writer.printf(outputFormatTime, time);
writer.printf(OUTPUT_FORMAT_TIME, time);
if (laneCount > 1) {
writeLaneAverages();
}
@@ -104,14 +97,14 @@ public void writeAggregatedData(double time) {
private void writeQuantitiesPerLane() {
for (int i = 0; i < laneCount; i++) {
write(outputFormat, detector.getVehCountOutput(i), detector.getVehCumulatedCountOutput(i), Units.MS_TO_KMH
write(OUTPUT_FORMAT, detector.getVehCountOutput(i), detector.getVehCumulatedCountOutput(i), Units.MS_TO_KMH
* detector.getMeanSpeed(i), Units.INVS_TO_INVH * detector.getFlow(i), detector.getOccupancy(i),
Units.MS_TO_KMH * detector.getMeanSpeedHarmonic(i), detector.getMeanTimegapHarmonic(i));
}
}
private void writeLaneAverages() {
write(outputFormat, detector.getVehCountOutputAllLanes(), detector.getVehCumulatedCountOutputAllLanes(),
write(OUTPUT_FORMAT, detector.getVehCountOutputAllLanes(), detector.getVehCumulatedCountOutputAllLanes(),
Units.MS_TO_KMH * detector.getMeanSpeedAllLanes(), Units.INVS_TO_INVH * detector.getFlowAllLanes(),
detector.getOccupancyAllLanes(), Units.MS_TO_KMH * detector.getMeanSpeedHarmonicAllLanes(),
detector.getMeanTimegapHarmonicAllLanes());
@@ -36,7 +36,7 @@
public class FileTrafficLightControllerRecorder extends FileOutputBase implements TrafficLightRecordDataCallback {
private static final String extensionFormat = ".controllerGroup_%s.firstSignal_%s.csv";
private static final String EXTENSION_FORMAT = ".controllerGroup_%s.firstSignal_%s.csv";
private final int nTimestep;
public FileTrafficLightControllerRecorder(TrafficLightController controller, int nTimestep) {
@@ -46,7 +46,7 @@ public FileTrafficLightControllerRecorder(TrafficLightController controller, int
this.nTimestep = nTimestep;
String groupName = controller.groupId().replaceAll("\\s", "");
String firstSignalId = controller.firstSignalId().replaceAll("\\s", "");
writer = Preconditions.checkNotNull(createWriter(String.format(extensionFormat, groupName, firstSignalId)));
writer = Preconditions.checkNotNull(createWriter(String.format(EXTENSION_FORMAT, groupName, firstSignalId)));
}
/**
@@ -29,27 +29,25 @@
import org.movsim.input.ProjectMetaData;
import org.movsim.io.FileOutputBase;
import org.movsim.simulator.vehicles.Vehicle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileTrafficSinkData extends FileOutputBase implements
org.movsim.simulator.roadnetwork.boundaries.TrafficSink.RecordDataCallback {
private static final String extensionFormat = ".sink.road_%s.csv";
private static final String outputHeading = COMMENT_CHAR
private static final String EXTENSION_FORMAT = ".sink.road_%s.csv";
private static final String OUTPUT_HEADING = COMMENT_CHAR
+ " t[s], timeFormatted, totalVehiclesRemoved, lane, route, vehicleId, vehicleLabel, vehicleUserData ...\n";
private static final String outputFormat = "%10.2f, %s, %6d, %2d, %s, %s, %s, %s %n";
private static final String OUTPUT_FORMAT = "%10.2f, %s, %6d, %2d, %s, %s, %s, %s %n";
public FileTrafficSinkData(String roadId) {
super(ProjectMetaData.getInstance().getOutputPath(), ProjectMetaData.getInstance().getProjectName());
writer = createWriter(String.format(extensionFormat, roadId));
writer.printf(outputHeading);
writer = createWriter(String.format(EXTENSION_FORMAT, roadId));
writer.printf(OUTPUT_HEADING);
}
@Override
public void recordData(double simulationTime, int totalVehiclesRemoved, Vehicle vehicle) {
String formattedTime = ProjectMetaData.getInstance().getFormatedTimeWithOffset(simulationTime);
writer.printf(outputFormat, simulationTime, formattedTime, totalVehiclesRemoved, vehicle.lane(),
writer.printf(OUTPUT_FORMAT, simulationTime, formattedTime, totalVehiclesRemoved, vehicle.lane(),
vehicle.getRouteName(), vehicle.getId(), vehicle.getLabel(),
vehicle.getUserData().getString(SEPARATOR_CHAR));
writer.flush();
@@ -31,24 +31,21 @@
public class FileTrafficSourceData extends FileOutputBase implements TrafficSourceMacro.RecordDataCallback {
private static final String extensionFormat = ".source.road_%s.csv";
private static final String outputHeading =
private static final String EXTENSION_FORMAT = ".source.road_%s.csv";
private static final String OUTPUT_HEADING =
COMMENT_CHAR + " t[s], lane, xEnter[m], v[km/h], qBC[1/h], count, queue\n";
private static final String outputFormat = "%10.2f, %4d, %10.2f, %10.2f, %10.2f, %8d, %10.5f%n";
private static final String OUTPUT_FORMAT = "%10.2f, %4d, %10.2f, %10.2f, %10.2f, %8d, %10.5f%n";
/**
* Instantiates a new file upstream boundary data.
*/
public FileTrafficSourceData(String roadId) {
super(ProjectMetaData.getInstance().getOutputPath(), ProjectMetaData.getInstance().getProjectName());
writer = createWriter(String.format(extensionFormat, roadId));
writer.printf(outputHeading);
writer = createWriter(String.format(EXTENSION_FORMAT, roadId));
writer.printf(OUTPUT_HEADING);
}
@Override
public void recordData(double simulationTime, int laneEnter, double xEnter, double vEnter, double totalInflow,
int enteringVehCounter, double nWait) {
writer.printf(outputFormat, simulationTime, laneEnter, xEnter, 3.6 * vEnter, 3600 * totalInflow,
writer.printf(OUTPUT_FORMAT, simulationTime, laneEnter, xEnter, 3.6 * vEnter, 3600 * totalInflow,
enteringVehCounter, nWait);
writer.flush();
}
@@ -25,37 +25,24 @@
*/
package org.movsim.output;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.movsim.autogen.ConsumptionCalculation;
import org.movsim.autogen.FloatingCarOutput;
import org.movsim.autogen.IndividualTravelTimes;
import org.movsim.autogen.OutputConfiguration;
import org.movsim.autogen.SpatioTemporalConfiguration;
import org.movsim.autogen.Trajectories;
import org.movsim.autogen.TravelTimes;
import com.google.common.base.Preconditions;
import org.movsim.autogen.*;
import org.movsim.output.floatingcars.FloatingCars;
import org.movsim.output.route.ConsumptionOnRoute;
import org.movsim.output.route.FileTrajectories;
import org.movsim.output.route.IndividualTravelTimesOnRoute;
import org.movsim.output.route.SpatioTemporal;
import org.movsim.output.route.TravelTimeOnRoute;
import org.movsim.output.route.*;
import org.movsim.simulator.SimulationTimeStep;
import org.movsim.simulator.observer.ServiceProvider;
import org.movsim.simulator.observer.ServiceProviders;
import org.movsim.simulator.roadnetwork.RoadNetwork;
import org.movsim.simulator.roadnetwork.routing.Route;
import org.movsim.simulator.roadnetwork.routing.Routing;
import org.movsim.simulator.vehicles.VehicleFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SimulationOutput implements SimulationTimeStep {
@@ -80,8 +67,7 @@
private final Routing routing;
public SimulationOutput(double simulationTimestep, boolean writeOutput, OutputConfiguration outputConfiguration,
RoadNetwork roadNetwork, Routing routing, VehicleFactory vehicleFactory,
@Nullable ServiceProviders serviceProviders) {
RoadNetwork roadNetwork, Routing routing, @Nullable ServiceProviders serviceProviders) {
Preconditions.checkNotNull(outputConfiguration);
this.roadNetwork = Preconditions.checkNotNull(roadNetwork);
@@ -91,7 +77,7 @@ public SimulationOutput(double simulationTimestep, boolean writeOutput, OutputCo
initFloatingCars(writeOutput, outputConfiguration);
initConsumption(writeOutput, simulationTimestep, outputConfiguration);
initTravelTimes(writeOutput, simulationTimestep, outputConfiguration);
initIndividualTravelTimes(writeOutput, simulationTimestep, outputConfiguration);
initIndividualTravelTimes(writeOutput, outputConfiguration);
initSpatioTemporalOutput(writeOutput, outputConfiguration);
initTrajectories(writeOutput, outputConfiguration);
@@ -121,12 +107,11 @@ private void initTravelTimes(boolean writeOutput, double simulationTimestep,
}
}
private void initIndividualTravelTimes(boolean writeOutput, double simulationTimestep,
OutputConfiguration outputConfiguration) {
private void initIndividualTravelTimes(boolean writeOutput, OutputConfiguration outputConfiguration) {
for (IndividualTravelTimes input : outputConfiguration.getIndividualTravelTimes()) {
Route route = getCheckedRoute(input.getRoute());
IndividualTravelTimesOnRoute travelTimes = new IndividualTravelTimesOnRoute(simulationTimestep, roadNetwork,
route, writeOutput);
IndividualTravelTimesOnRoute travelTimes = new IndividualTravelTimesOnRoute(roadNetwork, route,
writeOutput);
individualTravelTimeOnRoutes.put(route, travelTimes);
}
}
@@ -25,38 +25,36 @@
*/
package org.movsim.output.floatingcars;
import java.io.PrintWriter;
import java.util.Map;
import org.movsim.input.ProjectMetaData;
import org.movsim.io.FileOutputBase;
import org.movsim.simulator.roadnetwork.routing.Route;
import org.movsim.simulator.vehicles.PhysicalQuantities;
import org.movsim.simulator.vehicles.Vehicle;
import org.movsim.utilities.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.util.Map;
// TODO output of physical quantities for Cellular Automata. Test scenario test_speedlimits.xml
class FileFloatingCars extends FileOutputBase {
private static final String extensionFormat = ".car.route_%s.%06d.csv";
private static final String extensionRegex = "[.]car[.]route_.*[.]\\d+[.]csv";
private static final String EXTENSION_FORMAT = ".car.route_%s.%06d.csv";
private static final String EXTENSION_REGEX = "[.]car[.]route_.*[.]\\d+[.]csv";
private static final String outputHeading = COMMENT_CHAR
private static final String OUTPUT_HEADING = COMMENT_CHAR
+ " t[s], roadId, lane, x[m], totalX[m], v[m/s], a[m/s^2],aModel[m/s^2], gap[m], dv[m/s],distToTL[m],fuelFlow[ml/s],frontVehID,slope[rad]";
// note: number before decimal point is total width of field, not width of integer part
private static final String outputFormat = "%10.2f,%10d,%10d,%10.2f,%10.2f,%10.3f,%10.5f,%10.5f,%10.3f,%10.5f,%10.2f,%10f,%10d,%8.5f%n";
private static final String OUTPUT_FORMAT = "%10.2f,%10d,%10d,%10.2f,%10.2f,%10.3f,%10.5f,%10.5f,%10.3f,%10.5f,%10.2f,%10f,%10d,%8.5f%n";
FileFloatingCars() {
super(ProjectMetaData.getInstance().getOutputPath(), ProjectMetaData.getInstance().getProjectName());
String regex = baseFilename + extensionRegex;
String regex = baseFilename + EXTENSION_REGEX;
FileUtils.deleteFileList(path, regex);
}
PrintWriter createWriter(Vehicle vehicle, Route route) {
return createWriter(String.format(extensionFormat, route.getName(), vehicle.getVehNumber()));
return createWriter(String.format(EXTENSION_FORMAT, route.getName(), vehicle.getVehNumber()));
}
static void writeHeader(PrintWriter writer, Vehicle vehicle, Route route) {
@@ -65,48 +63,42 @@ static void writeHeader(PrintWriter writer, Vehicle vehicle, Route route) {
writer.println(String.format("%s vehicle type = %s", COMMENT_CHAR, vehicle.type()));
writer.println(String.format("%s model label = %s", COMMENT_CHAR, vehicle.getLabel()));
if (vehicle.getLongitudinalModel() != null) {
writer.println(String.format("%s model category = %s", COMMENT_CHAR, vehicle.getLongitudinalModel()
.modelName().getCategory().toString()));
writer.println(String.format("%s model name = %s (short name: %s)", COMMENT_CHAR, vehicle
.getLongitudinalModel().modelName().getDetailedName(), vehicle.getLongitudinalModel().modelName()
.getShortName()));
writer.println(String.format("%s model category = %s", COMMENT_CHAR,
vehicle.getLongitudinalModel().modelName().getCategory().toString()));
writer.println(String.format("%s model name = %s (short name: %s)", COMMENT_CHAR,
vehicle.getLongitudinalModel().modelName().getDetailedName(),
vehicle.getLongitudinalModel().modelName().getShortName()));
}
writer.println(String.format("%s physical vehicle length (in m) = %.2f", COMMENT_CHAR, vehicle
.physicalQuantities().getLength()));
writer.println(String.format("%s position x is defined by vehicle front (on the given road segment)",
COMMENT_CHAR));
writer.println(String.format("%s origin roadsegment id= %d, exit roadsegment id= %d (not set=%d)",
COMMENT_CHAR, vehicle.originRoadSegmentId(), vehicle.exitRoadSegmentId(),
Vehicle.ROAD_SEGMENT_ID_NOT_SET));
writer.println(String.format("%s physical vehicle length (in m) = %.2f", COMMENT_CHAR,
vehicle.physicalQuantities().getLength()));
writer.println(
String.format("%s position x is defined by vehicle front (on the given road segment)", COMMENT_CHAR));
writer.println(String.format("%s origin roadsegment id= %d, exit roadsegment id= %d (not set=%d)", COMMENT_CHAR,
vehicle.originRoadSegmentId(), vehicle.exitRoadSegmentId(), Vehicle.ROAD_SEGMENT_ID_NOT_SET));
writer.println(String.format("%s %s", COMMENT_CHAR, route.toString()));
for (Map.Entry<String, String> entry : vehicle.getUserData()) {
writer.println(String.format("%s userData: %s=%s", COMMENT_CHAR, entry.getKey(), entry.getValue()));
}
writer.println(outputHeading);
writer.println(OUTPUT_HEADING);
}
/**
* Write data in physical (not scaled) quantities
*
* @param time
* the time
* @param veh
* the veh
* @param frontVeh
* the front veh
* @param writer
* the writer
*
* @param time the time
* @param veh the veh
* @param frontVeh the front veh
* @param writer the writer
*/
static void writeData(double time, Vehicle veh, Vehicle frontVeh, PrintWriter writer) {
final PhysicalQuantities physicalQuantities = veh.physicalQuantities();
writer.printf(outputFormat, time, veh.roadSegmentId(), veh.lane(), physicalQuantities.getFrontPosition(),
writer.printf(OUTPUT_FORMAT, time, veh.roadSegmentId(), veh.lane(), physicalQuantities.getFrontPosition(),
physicalQuantities.totalTravelDistance(), physicalQuantities.getSpeed(), physicalQuantities.getAcc(),
physicalQuantities.accModel(), physicalQuantities.getNetDistance(frontVeh),
physicalQuantities.getRelSpeed(frontVeh),
physicalQuantities.getxScale() * veh.getDistanceToTrafficlight(),
1000 * veh.getEnergyModel().getActualFuelFlowLiterPerS(),
frontVeh == null ? -1 : frontVeh.getVehNumber(),
veh.getSlope());
frontVeh == null ? -1 : frontVeh.getVehNumber(), veh.getSlope());
writer.flush();
}
Oops, something went wrong.

0 comments on commit 29cf86d

Please sign in to comment.