Commit 5d963bef authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Pulled Changes from tm/sumo-integration

parents 493642ed 30a32f4c
...@@ -662,7 +662,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -662,7 +662,7 @@ public class DefaultConfigurator implements Configurator {
} }
public String parseValue(String value) { public String parseValue(String value) {
if (value.trim().startsWith(CONFIG_VARIABLE_PREFIX_TAG)) { if (value.trim().startsWith(CONFIG_VARIABLE_PREFIX_TAG) && !value.trim().startsWith(CONFIG_VARIABLE_PREFIX_TAG + "{")) {
int posDollar = value.indexOf(CONFIG_VARIABLE_PREFIX_TAG); int posDollar = value.indexOf(CONFIG_VARIABLE_PREFIX_TAG);
String varName = value.substring(posDollar + 1, value.length()); String varName = value.substring(posDollar + 1, value.length());
value = variables.get(varName); value = variables.get(varName);
......
...@@ -331,7 +331,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -331,7 +331,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
} }
freeComponents.forEach((component) -> { freeComponents.forEach((component) -> {
component.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
try { try {
RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class); RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class);
for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) { for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) {
...@@ -342,6 +341,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -342,6 +341,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
} catch (ComponentNotAvailableException e) { } catch (ComponentNotAvailableException e) {
e.printStackTrace(); e.printStackTrace();
} }
component.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
}); });
// Reschedule next step // Reschedule next step
......
...@@ -14,6 +14,7 @@ import java.util.List; ...@@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
...@@ -46,7 +47,7 @@ import de.tudresden.ws.container.SumoPosition2D; ...@@ -46,7 +47,7 @@ import de.tudresden.ws.container.SumoPosition2D;
import de.tudresden.ws.container.SumoStringList; import de.tudresden.ws.container.SumoStringList;
import it.polito.appeal.traci.SumoTraciConnection; import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController { public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp"); private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp");
private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>(); private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>();
...@@ -105,7 +106,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -105,7 +106,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
// This will only work with the updated version of the TraaS API for sumo // This will only work with the updated version of the TraaS API for sumo
// It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git // It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git
_connection = new SumoTraciConnection(_sumoExe, _configFile, random.nextInt()); _connection = new SumoTraciConnection(_sumoExe, _configFile, random.nextInt());
/*
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/
_connection.addOption("time-to-teleport", Integer.toString(-1));
try { try {
_connection.runServer(); _connection.runServer();
...@@ -118,25 +123,20 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -118,25 +123,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
e.printStackTrace(); e.printStackTrace();
} }
Runnable shutdownHook = new Runnable() { Simulator.getInstance().addObserver(this);
@Override
public void run() {
_connection.close();
}
};
Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook));
_initalized = true; _initalized = true;
}
Event.scheduleWithDelay(Simulator.getEndTime()-Simulator.getCurrentTime(), new EventHandler() { }
@Override @Override
public void eventOccurred(Object content, int type) { public void simulationFinished() {
_connection.close(); /*
} * This is called by the simulation scheduler once the simulation is
}, null, 0); * finished - it should be used to terminate the connection to SUMO.
*/
if (_connection != null && !_connection.isClosed()) {
_connection.close();
} }
} }
......
...@@ -43,6 +43,7 @@ import java.util.Collection; ...@@ -43,6 +43,7 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
...@@ -387,7 +388,7 @@ public class VisualizationTopologyView extends JFrame ...@@ -387,7 +388,7 @@ public class VisualizationTopologyView extends JFrame
*/ */
protected class WorldPanel extends JLayeredPane { protected class WorldPanel extends JLayeredPane {
protected HashMap<INodeID, VisNodeInformation> nodeInformation = new HashMap<INodeID, VisNodeInformation>(); protected ConcurrentHashMap<INodeID, VisNodeInformation> nodeInformation = new ConcurrentHashMap<INodeID, VisNodeInformation>();
protected final static int PADDING = 16; protected final static int PADDING = 16;
......
...@@ -62,11 +62,13 @@ public class NodeInfoComponentVis extends JComponent ...@@ -62,11 +62,13 @@ public class NodeInfoComponentVis extends JComponent
protected Collection<NodeVis> nodes = new LinkedList<>(); protected Collection<NodeVis> nodes = new LinkedList<>();
private JMenu menu = new JMenu("Node Information"); private JMenu menu = new JMenu("Node Info");
protected boolean[] activeLayers = null; protected boolean[] activeLayers = null;
boolean hideInactiveNodes = false; boolean hideInactiveNodes = false;
private final String name;
public <T extends HostComponent> NodeInfoComponentVis( public <T extends HostComponent> NodeInfoComponentVis(
final Class<T> componentClass) { final Class<T> componentClass) {
...@@ -74,6 +76,8 @@ public class NodeInfoComponentVis extends JComponent ...@@ -74,6 +76,8 @@ public class NodeInfoComponentVis extends JComponent
VisualizationInjector.getWorldY()); VisualizationInjector.getWorldY());
setOpaque(true); setOpaque(true);
setVisible(true); setVisible(true);
this.name = componentClass.getSimpleName();
menu.setText("Info: "+name);
Event.scheduleWithDelay(1 * Time.MICROSECOND, new EventHandler() { Event.scheduleWithDelay(1 * Time.MICROSECOND, new EventHandler() {
@Override @Override
...@@ -312,7 +316,7 @@ public class NodeInfoComponentVis extends JComponent ...@@ -312,7 +316,7 @@ public class NodeInfoComponentVis extends JComponent
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return "Node Information"; return "Info: "+name;
} }
} }
...@@ -48,6 +48,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement; ...@@ -48,6 +48,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.Metric; import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
...@@ -155,6 +156,7 @@ public class DAO { ...@@ -155,6 +156,7 @@ public class DAO {
cfg.addAnnotatedClass(MeasurementPair.class); cfg.addAnnotatedClass(MeasurementPair.class);
cfg.addAnnotatedClass(MeasurementPairList.class); cfg.addAnnotatedClass(MeasurementPairList.class);
cfg.addAnnotatedClass(MeasurementSingle.class); cfg.addAnnotatedClass(MeasurementSingle.class);
cfg.addAnnotatedClass(MeasurementSpatial.class);
cfg.addAnnotatedClass(MeasurementStatistic.class); cfg.addAnnotatedClass(MeasurementStatistic.class);
cfg.addAnnotatedClass(Metric.class); cfg.addAnnotatedClass(Metric.class);
cfg.addAnnotatedClass(MetricDescription.class); cfg.addAnnotatedClass(MetricDescription.class);
......
...@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement; ...@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.Metric; import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
...@@ -101,6 +102,31 @@ public class MeasurementDAO extends DAO { ...@@ -101,6 +102,31 @@ public class MeasurementDAO extends DAO {
hostMetric); hostMetric);
addToPersistQueue(measurement); addToPersistQueue(measurement);
} }
/**
* Store a single measurement for a host, tied to a specific location.
*
* @param metricDesc
* @param hostId
* @param time
* @param value
* @param locationX
* @param locationY
*/
public static void storeSpatialMeasurement(MetricDescription metricDesc,
long hostId, long time, double value, int locationX,
int locationY) {
if (inactive) {
return;
}
Metric metric = MetricDAO.lookupSpatialMetric(metricDesc);
HostMetric hostMetric = HostMetricDAO.lookupHostMetric(metric, hostId);
MeasurementSpatial measurement = new MeasurementSpatial(time, value,
hostMetric, locationX, locationY);
addToPersistQueue(measurement);
}
/** /**
* Stores for a series of measurements the given values for a host. The * Stores for a series of measurements the given values for a host. The
......
...@@ -27,7 +27,7 @@ public class MetricDAO extends DAO { ...@@ -27,7 +27,7 @@ public class MetricDAO extends DAO {
/** /**
* Identifier for a single metric * Identifier for a single metric
*/ */
SINGLE, SINGLE, SPATIAL,
/** /**
* Identifier for an aggregate metric * Identifier for an aggregate metric
*/ */
...@@ -62,6 +62,16 @@ public class MetricDAO extends DAO { ...@@ -62,6 +62,16 @@ public class MetricDAO extends DAO {
public static Metric lookupSingleMetric(MetricDescription metricDesc) { public static Metric lookupSingleMetric(MetricDescription metricDesc) {
return lookupMetric(metricDesc, MetricType.SINGLE); return lookupMetric(metricDesc, MetricType.SINGLE);
} }
/** Retrieve a {@link Metric} object for the given MetricDescription
* for spatial value metrics.
*
* If there is no matching Metric object, it is created, persisted, and cached
* automatically.
*/
public static Metric lookupSpatialMetric(MetricDescription metricDesc) {
return lookupMetric(metricDesc, MetricType.SPATIAL);
}
/** Retrieve a {@link Metric} object for the given MetricDescription /** Retrieve a {@link Metric} object for the given MetricDescription
* for pair value metrics. * for pair value metrics.
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM 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
* any later version.
*
* PeerfactSim.KOM 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 PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.util.db.metric;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* A single measurement, but with an assigned location.
*
* @author Bjoern Richerzhagen
*/
@Entity
@Table(name = "measurements_spatial", indexes = {
@Index(columnList = "time", name = "time"),
@Index(columnList = "hostMetricId", name = "hostMetricId") })
public class MeasurementSpatial {
/**
* A unique Id, will be set by the database
*/
@SuppressWarnings("unused")
@Id
@GeneratedValue()
private int id;
/**
* The simulation time of this measurement
*/
@SuppressWarnings("unused")
private long time;
/**
* The value for this measurement
*/
@SuppressWarnings("unused")
@Column(nullable = true)
private Double value;
@Column(nullable = true, name = "[locationX]")
private Integer locationX;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
/**
* The mapping Object of this measurement to the {@link Metric}-Object,
* which describes this metric.
*/
@SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "hostMetricId")
private HostMetric hostMetric;
/**
* Creates a {@link MeasurementSingle}-Object with the given parameters. If
* value has the value infinity or NaN, then will be set this value to null.
*
* @param time
* The simulation time as date to this measurement
* @param value
* The value for this measurement
* @param statistic
* The reference to the {@link Metric}-Object, which describes
* this metric. Is used for the mapping.
*/
public MeasurementSpatial(long time, Double value, HostMetric hostMetric, Integer locationX, Integer locationY) {
super();
this.time = time;
this.hostMetric = hostMetric;
// check for infinity or NaN
this.value = checkForSpecialNumbers(value);
this.locationX = locationX;
this.locationY = locationY;
}
/**
* Check for special numbers, like infinity or NaN. If the given value is
* equals this numbers then will be return null, otherwise will be returned
* the given value.
*
* @param value
* The value, which should be checked.
* @return The value or null, if it is a special number.
*/
private Double checkForSpecialNumbers(Double value) {
if (value == null)
return value;
if (value.equals(Double.NEGATIVE_INFINITY)
|| value.equals(Double.POSITIVE_INFINITY)
|| value.equals(Double.NaN)) {
return null;
} else {
return value;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment