Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
akegermany committed Sep 25, 2018
1 parent 39865fc commit 9d79353
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 219 deletions.
4 changes: 1 addition & 3 deletions common/src/main/java/org/movsim/input/ProjectMetaData.java
Expand Up @@ -24,7 +24,7 @@
* Container for some shared information. Singleton pattern. <br>
* created: Mar 9, 2013<br>
*/
// TODO this class deperately needs a throughout refactoring !!!
// TODO this class needs a throughout refactoring !!!
public final class ProjectMetaData {

private static final String MOVSIM_COMMON_LOG_PATH = "config";
Expand All @@ -43,8 +43,6 @@ public final class ProjectMetaData {

private String xodrNetworkFilename;

private String xodrPath;

private String consumptionFilename;

private String consumptionPath;
Expand Down
16 changes: 1 addition & 15 deletions common/src/main/java/org/movsim/io/CsvReaderUtil.java
Expand Up @@ -26,24 +26,10 @@ public static List<String[]> readData(File file, char separator) {
List<String[]> myEntries = Lists.newArrayList();

// see http://opencsv.sourceforge.net/#how-to-read
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(file), separator);
try (CSVReader reader = new CSVReader(new FileReader(file), separator)) {
myEntries = reader.readAll();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
return myEntries;
}
Expand Down
Expand Up @@ -5,5 +5,5 @@ public interface SimulationShutDown {
/**
* Callback to allow the application to close all open resources in an ordered way before the program exits.
*/
public void onShutDown();
void onShutDown();
}
20 changes: 10 additions & 10 deletions common/src/main/java/org/movsim/utilities/Units.java
Expand Up @@ -28,33 +28,33 @@
public interface Units {

/** converts 1/s to 1/h, factor is 3600 */
final double INVS_TO_INVH = 3600.;
double INVS_TO_INVH = 3600.;

/** converts 1/h to 1/s, factor is 1/3600 */
final double INVH_TO_INVS = 1 / INVS_TO_INVH;
double INVH_TO_INVS = 1 / INVS_TO_INVH;

/** converts m/s to km/h, factor is 3.6 */
final double MS_TO_KMH = 3.6;
double MS_TO_KMH = 3.6;

/** converts km/h to m/s, factor is 1/3.6 */
final double KMH_TO_MS = 1. / MS_TO_KMH;
double KMH_TO_MS = 1. / MS_TO_KMH;

/** converts from 1/m to 1/km, factor is 1000 */
final double INVM_TO_INVKM = 1000.;
double INVM_TO_INVKM = 1000.;

/** converts from 1/km to 1/m, factor is 1/1000 */
final double INVKM_TO_INVM = 1. / INVM_TO_INVKM;
double INVKM_TO_INVM = 1. / INVM_TO_INVKM;

/** converts meter to kilometer. Factor is 1000. */
final double KM_TO_M = 1000;
double KM_TO_M = 1000;

/** converts kilometer to meter. Factor is 1/1000. */
final double M_TO_KM = 1. / KM_TO_M;
double M_TO_KM = 1. / KM_TO_M;

/** converts hours to seconds. Factor is 3600. */
final double H_TO_S = 3600;
double H_TO_S = 3600;

/** converts seconds to hours. Factor is 1/3600. */
final double S_TO_H = 1 / H_TO_S;
double S_TO_H = 1 / H_TO_S;

}
Expand Up @@ -14,7 +14,7 @@ public class RoadGeometry {
// private static final Logger LOG = LoggerFactory.getLogger(RoadGeometry.class);

public enum GeometryType {
LINE, ARC, SPIRAL, POLY3;
LINE, ARC, SPIRAL, POLY3
}

protected final Geometry geometry;
Expand Down
112 changes: 54 additions & 58 deletions core/src/main/java/org/movsim/simulator/SimulationRun.java
Expand Up @@ -2,25 +2,25 @@
* Copyright (C) 2010, 2011, 2012 by Arne Kesting, Martin Treiber, Ralph Germ, Martin Budden
* <movsim.org@gmail.com>
* -----------------------------------------------------------------------------------------
*
*
* This file is part of
*
*
* MovSim - the multi-model open-source vehicular-traffic simulator.
*
*
* MovSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* MovSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with MovSim. If not, see <http://www.gnu.org/licenses/>
* or <http://www.movsim.org>.
*
*
* -----------------------------------------------------------------------------------------
*/
package org.movsim.simulator;
Expand All @@ -35,33 +35,32 @@
public class SimulationRun {

public interface CompletionCallback {
/**
* Callback to inform the application that the simulation has run to
* completion.
*
* @param simulationTime
*/
void simulationComplete(double simulationTime);
/**
* Callback to inform the application that the simulation has run to
* completion.
*
* @param simulationTime
*/
void simulationComplete(double simulationTime);
}

public interface UpdateStatusCallback {
/**
* Callback to allow the application to make updates to its state after
* the vehicle positions etc have been updated, but before the repaint
* is called.
*
* @param simulationTime
* the current logical time in the simulation
*/
public void updateStatus(double simulationTime);
/**
* Callback to allow the application to make updates to its state after
* the vehicle positions etc have been updated, but before the repaint
* is called.
*
* @param simulationTime the current logical time in the simulation
*/
void updateStatus(double simulationTime);
}

protected double dt; // timestep, seconds

protected double duration; // duration, seconds

protected double simulationTime; // Simulation time, seconds (reset to 0.0
// in each run)
// in each run)

protected long iterationCount;

Expand All @@ -76,125 +75,122 @@ public interface UpdateStatusCallback {

/**
* Constructor, sets the simulation object.
*
* @param simulation
* a simulation object that implements the SimulationTimeStep
* interface
*
* @param simulation a simulation object that implements the SimulationTimeStep
* interface
*/
public SimulationRun(SimulationTimeStep simulation) {
this.simulation = Preconditions.checkNotNull(simulation);
initShutdownHook();
this.simulation = Preconditions.checkNotNull(simulation);
initShutdownHook();
}

/**
* Returns the simulation timestep object.
*
*
* @return the simulation timestep object
*/
public final SimulationTimeStep simulation() {
return simulation;
return simulation;
}

/**
* Sets the simulation timestep.
*
* @param dt
* simulation timestep in seconds
*
* @param dt simulation timestep in seconds
*/
public final void setTimeStep(double dt) {
this.dt = dt;
this.dt = dt;
}

/**
* Returns the simulation timestep
*
*
* @return simulation timestep in seconds
*/
public final double timeStep() {
return dt;
return dt;
}

/**
* Sets the simulation duration.
*
* @param duration
* simulation duration in seconds
*
* @param duration simulation duration in seconds
*/
public final void setDuration(double duration) {
this.duration = duration;
this.duration = duration;
}

/**
* Returns the simulation duration.
*
*
* @return simulation duration in seconds
*/
public final double duration() {
return duration;
return duration;
}

/**
* Returns the number of iterations executed.
*
*
* @return number of iterations
*/
public final long iterationCount() {
return iterationCount;
return iterationCount;
}

/**
* <p>
* Returns the time for which the simulation has been running.
* </p>
*
*
* <p>
* This is the logical time in the simulation (that is the sum of the
* deltaTs), not the amount of real time that has been required to do the
* simulation calculations.
* </p>
*
*
* @return the simulation time
*/
public final double simulationTime() {
return simulationTime;
return simulationTime;
}

/**
* Returns the total execution time of the simulation. Useful for order of
* magnitude benchmarking.
*
*
* @return total execution time of the simulation
*/
public final long totalSimulationTime() {
return totalSimulationTime;
return totalSimulationTime;
}

/**
* Resets the simulation instrumentation data.
*/
public void reset() {
simulationTime = 0.0;
iterationCount = 0;
totalSimulationTime = 0;
simulationTime = 0.0;
iterationCount = 0;
totalSimulationTime = 0;
}

/**
* Adds a update status callback.
*
*
* @param updateStatusCallback
*/
public void addUpdateStatusCallback(UpdateStatusCallback updateStatusCallback) {
updateStatusCallbacks.add(Preconditions.checkNotNull(updateStatusCallback));
updateStatusCallbacks.add(Preconditions.checkNotNull(updateStatusCallback));
}

/**
* Sets the completion callback.
*
*
* @param completionCallback
*/
public final void setCompletionCallback(CompletionCallback completionCallback) {
Preconditions.checkState(this.completionCallback == null, "it's a mistake if this is set twice");
this.completionCallback = completionCallback;
Preconditions.checkState(this.completionCallback == null, "it's a mistake if this is set twice");
this.completionCallback = completionCallback;
}

/**
Expand Down
Expand Up @@ -10,7 +10,7 @@ private RoadNetworkUtils() {

public enum TravelTimeType {
GRID,
MEAN;
MEAN
}

public static double instantaneousTravelTime(Route route, TravelTimeType type) {
Expand Down
Expand Up @@ -6,6 +6,6 @@
public enum RoadSegmentDirection {

FORWARD,
BACKWARD;
BACKWARD

}
Expand Up @@ -36,7 +36,7 @@ enum RoadObjectType {
LOOPDETECTOR,
VMS_DIVERSION,
FLOW_CONSERVING_BOTTLENECK,
GRADIENT_PROFILE;
GRADIENT_PROFILE
}

RoadObjectType getType();
Expand Down

0 comments on commit 9d79353

Please sign in to comment.