Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
......@@ -34,9 +34,11 @@ 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.MeasurementSpatial;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatisticMsgType;
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.stats.StatisticComputation;
import de.tudarmstadt.maki.simonstrator.api.MessageWithDisasterType.MessageDisasterType;
/**
* This class provides methods to persist measurements in a database.
......@@ -53,7 +55,7 @@ public class MeasurementDAO extends DAO {
/**
* The Host ID that is used for global metrics.
*/
private static final long GLOBAL_HOST_ID = -1;
public static final long GLOBAL_HOST_ID = -1;
private static boolean inactive = false;
......@@ -128,6 +130,22 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement);
}
/**
* Store a global 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 storeGlobalSpatialMeasurement(MetricDescription metricDesc,
long time, double value, int locationX, int locationY) {
storeSpatialMeasurement(metricDesc, GLOBAL_HOST_ID, time, value, locationX, locationY);
}
/**
* Stores for a series of measurements the given values for a host. The
* given values are a statistical representation of the series of
......@@ -229,6 +247,76 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement);
}
/**
* Stores a statistical description of a series of values for group of
* hosts.
*
* @param metricDesc
* The {@link MetricDescription} which describes the metric.
* @param groupName
* The host group
* @param time
* A time for the measurement in simulation time
* @param stats
* the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
* @param msgType
* the message type this statistic is for
*/
public static void storeGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, MessageDisasterType msgType) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatisticMsgType measurement = new MeasurementStatisticMsgType(time, stats,
groupMetric, observationDuration, describesWholeSimulation,
msgType);
addToPersistQueue(measurement);
}
/**
* Stores a statistical description of a series of values for group of hosts
* and a given spatial coordinate.
*
* @param metricDesc
* The {@link MetricDescription} which describes the metric.
* @param groupName
* The host group
* @param time
* A time for the measurement in simulation time
* @param stats
* the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
* @param msgType
* the message type this statistic is for
*/
public static void storeSpatialGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY,
MessageDisasterType msgType) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatisticMsgType measurement = new MeasurementStatisticMsgType(time, stats,
groupMetric, observationDuration, describesWholeSimulation,
locationX, locationY, msgType);
addToPersistQueue(measurement);
}
/**
* Store a list-based measurement with a key (i.e., as a
......
package de.tud.kom.p2psim.impl.util.db.dao.metric;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.db.dao.DAO;
import de.tud.kom.p2psim.impl.util.db.metric.Experiment;
import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
......@@ -53,6 +59,21 @@ public class MetricDAO extends DAO {
}
}
public static List<Metric> getMetricsForExperiment(int pExperimentID) {
begin();
Criteria criteria = getSession().createCriteria(Experiment.class);
if (pExperimentID != -1) {
criteria = criteria.add(Restrictions.eq("experimentID", pExperimentID));
}
List<Metric> metrics = criteria.list();
commit();
return metrics;
}
public List<Metric> getMetrics() {
return getMetricsForExperiment(-1);
}
/** Retrieve a {@link Metric} object for the given MetricDescription
* for single 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.CascadeType;
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;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import de.tudarmstadt.maki.simonstrator.api.MessageWithDisasterType.MessageDisasterType;
/**
* adapted {@link MeasurementStatistic} with also stores the types
*
* @author Simon Luser
*/
@Entity
@Table(name = "measurements_statistics_msg", indexes = {
@Index(columnList = "id", name = "id") })
public class MeasurementStatisticMsgType implements GroupMetricBound {
/**
* The id of this table
*/
@Id
@GeneratedValue
private int id;
/**
* The simulation time for to this measurement in simulator time, that is,
* microseconds.
*/
@Column(nullable = true, name = "[time]")
private long time;
@Column(nullable = false, name = "[describesWholeSimulation]")
private boolean describesWholeSimulation;
/**
* The simulation time for to this measurement in simulator time, that is,
* microseconds.
*/
@Column(nullable = true, name = "[observationDuration]")
private long observationDuration;
/**
* The number of values
*/
@Column(nullable = true, name = "[values]")
private Double values;
@Column(nullable = true, name = "[std]")
private Double std;
@Column(nullable = true, name = "[sum]")
private Double sum;
@Column(nullable = true, name = "[sum2]")
private Double sum2;
/**
* The minimum of all values for this measurement
*/
@Column(nullable = true, name = "[min]")
private Double min;
/**
* The maximum of all values for this measurement
*/
@Column(nullable = true, name = "[max]")
private Double max;
@Column(nullable = true, name = "[mean]")
private Double mean;
@Column(nullable = true, name = "[median]")
private Double median;
@Column(nullable = true, name = "[perc25]")
private Double perc25;
@Column(nullable = true, name = "[perc75]")
private Double perc75;
@Column(nullable = true, name = "[perc97]")
private Double perc97; // 97,7
@Column(nullable = true, name = "[perc2]")
private Double perc2; // 2,3
@Column(nullable = true, name = "[perc95]")
private Double perc95; // 95
@Column(nullable = true, name = "[perc5]")
private Double perc5; // 5
@Column(nullable = true, name = "[locationX]")
private Integer locationX;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
@Column(nullable = true, name = "[isSpatial]")
private boolean isSpatial;
@Column(nullable = true, name = "[messageType]")
private String msgType;
/**
* Mapping to group metric
*/
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "groupMetricId")
GroupMetric groupMetric;
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object.
*
* @param time
* The simulation time for to this measurement as Date
* @param stats
* the {@link DescriptiveStatistics} object
* @param hostMetric
* The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
*/
public MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, MessageDisasterType msgType) {
this(time, stats, observationDuration, describesWholeSimulation,
msgType);
this.groupMetric = groupMetric;
}
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object, with spatial data attached.
*
* @param time
* The simulation time for to this measurement as Date
* @param stats
* the {@link DescriptiveStatistics} object
* @param hostMetric
* The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
* @param locationX
* x coordinate for spatial sampling
* @param locationY
* y coordinate for spatial sampling
*/
public MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY,
MessageDisasterType msgType) {
this(time, stats, observationDuration, describesWholeSimulation,
msgType);
this.groupMetric = groupMetric;
this.locationX = locationX;
this.locationY = locationY;
this.isSpatial = true;
}
/**
* Internal - write statistics
*
* @param time
* @param stats
* @param observationDuration
* duration covered by this measurement in simulation units
* @param msgType
*/
private MeasurementStatisticMsgType(long time, DescriptiveStatistics stats,
long observationDuration, boolean describesWholeSimulation,
MessageDisasterType msgType) {
super();
this.time = time;
this.observationDuration = observationDuration;
this.describesWholeSimulation = describesWholeSimulation;
this.values = checkForSpecialNumbers((double) stats.getN());
this.sum = checkForSpecialNumbers(stats.getSum());
this.sum2 = checkForSpecialNumbers(stats.getSumsq());
this.min = checkForSpecialNumbers(stats.getMin());
this.max = checkForSpecialNumbers(stats.getMax());
this.mean = checkForSpecialNumbers(stats.getMean());
this.median = checkForSpecialNumbers(stats.getPercentile(50));
this.perc2 = checkForSpecialNumbers(stats.getPercentile(2.3));
this.perc25 = checkForSpecialNumbers(stats.getPercentile(25));
this.perc75 = checkForSpecialNumbers(stats.getPercentile(75));
this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7));
this.perc5 = checkForSpecialNumbers(stats.getPercentile(5));
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.std = checkForSpecialNumbers(stats.getStandardDeviation());
this.isSpatial = false;
if (msgType != null)
this.msgType = msgType.name();
}
/**
* 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;
}
}
@Override
public GroupMetric getGroupMetric() {
return groupMetric;
}
@Override
public void setGroupMetric(GroupMetric metric) {
this.groupMetric = metric;
}
}
......@@ -152,6 +152,14 @@ public class Metric {
return true;
}
public String getName() {
return name;
}
public String getComment() {
return comment;
}
@Override
public String toString() {
return "Metric{" +
......
......@@ -38,8 +38,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javanet.staxutils.IndentingXMLStreamWriter;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
......@@ -55,6 +53,8 @@ import de.tud.kom.p2psim.impl.util.toolkits.SAXToolkit;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import com.sun.xml.txw2.output.IndentingXMLStreamWriter;
/**
* <p>
* An simple, high performance relational database for object-oriented environments. A key function
......@@ -436,7 +436,7 @@ public abstract class RelationalDB implements XMLSerializable {
IndentingXMLStreamWriter indwr = new IndentingXMLStreamWriter(writer); //Ensures indentation of the XML document
indwr.setIndent(" ");
indwr.setIndentStep(" ");
writer = indwr;
writer.writeStartDocument("1.0");
......
......@@ -28,23 +28,24 @@ import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import org.jgrapht.alg.ConnectivityInspector;
import org.jgrapht.alg.DijkstraShortestPath;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.jgrapht.Graph;
import org.jgrapht.GraphPath;
import org.jgrapht.alg.connectivity.ConnectivityInspector;
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
import org.jgrapht.graph.SimpleWeightedGraph;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.api.util.geo.maps.Map;
import de.tud.kom.p2psim.api.util.geo.maps.Way;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.obstacles.PolygonObstacle;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdgeFactory;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener.MapEvent;
......@@ -52,10 +53,9 @@ import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener.MapEvent;
public abstract class AbstractMap implements Map {
private List<Obstacle> obstacles = Lists.newLinkedList();
private List<Path> paths = Lists.newLinkedList();
private List<PathEdge> paths = Lists.newLinkedList();
protected DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph = new DefaultWeightedEdgeRetrievableGraph<Waypoint, Path>(
new PathEdgeFactory());
protected Graph<Waypoint, PathEdge> graph = new SimpleWeightedGraph<>(PathEdge.class);
private Multimap<Class, Waypoint> typeWaypointMap = ArrayListMultimap.create();
......@@ -106,10 +106,9 @@ public abstract class AbstractMap implements Map {
}
protected void buildGraph() {
graph = new DefaultWeightedEdgeRetrievableGraph<Waypoint, Path>(
new PathEdgeFactory());
graph = new SimpleWeightedGraph<>(PathEdge.class);
for (Path path : paths) {
for (PathEdge path : paths) {
graph.addVertex(path.getSource());
graph.addVertex(path.getTarget());
typeWaypointMap.put(path.getSource().getClass(), path.getSource());
......@@ -123,12 +122,12 @@ public abstract class AbstractMap implements Map {
raiseMapChanged(new MapChangeListener.ObstacleEvent(obstacle));
}
public void addPath(Path path) {
public void addPath(PathEdge path) {
paths.add(path);
raiseMapChanged(new MapChangeListener.PathEvent(path));
}
public List<Path> getPaths() {
public List<PathEdge> getPaths() {
return paths;
}
......@@ -192,12 +191,11 @@ public abstract class AbstractMap implements Map {
}
protected void createPath(Waypoint wp1, Waypoint wp2) {
Path path = new Path(wp1, wp2);
PathEdge path = new PathEdge(wp1, wp2);
addPath(path);
}
@SuppressWarnings("unchecked")
public DefaultWeightedEdgeRetrievableGraph getGraph() {
public Graph<Waypoint, PathEdge> getGraph() {
return graph;
}
......@@ -257,11 +255,10 @@ public abstract class AbstractMap implements Map {
return swapped[axis.ordinal()];
}
public List<Path> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, Path> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, Path>(
graph, start, end);
return dijkstrashortestpath.getPathEdgeList();
public List<PathEdge> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, PathEdge> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, PathEdge>(graph);
GraphPath<Waypoint, PathEdge> path = dijkstrashortestpath.getPath(start, end);
return path.getEdgeList();
}
public void addWaypoint(Waypoint wp) {
......@@ -320,8 +317,8 @@ public abstract class AbstractMap implements Map {
while (waypoints != null) {
//removeWaypoints(waypoints, WeakWaypoint.class);
for (Waypoint w : waypoints) {
Set<Path> edges = Sets.newHashSet(graph.edgesOf(w));
for (Path p : edges) {
Set<PathEdge> edges = Sets.newHashSet(graph.edgesOf(w));
for (PathEdge p : edges) {
graph.removeEdge(p);
}
graph.removeVertex(w);
......@@ -359,8 +356,8 @@ public abstract class AbstractMap implements Map {
} catch (IllegalArgumentException e) {
//removeWaypoint(shortestDistancePair.getA());
Set<Path> edges = graph.outgoingEdgesOf(shortestDistancePair.getA());
for (Path p : edges) {
Set<PathEdge> edges = graph.outgoingEdgesOf(shortestDistancePair.getA());
for (PathEdge p : edges) {
graph.removeEdge(p);
}
graph.removeVertex(shortestDistancePair.getA());
......@@ -419,7 +416,7 @@ public abstract class AbstractMap implements Map {
}
private Queue<List<Waypoint>> getConnectedComponents() {
ConnectivityInspector ci = new ConnectivityInspector<Waypoint, Path>(getGraph());
ConnectivityInspector ci = new ConnectivityInspector<Waypoint, PathEdge>(getGraph());
@SuppressWarnings("unchecked")
List<Set<Waypoint>> connectedSets = ci.connectedSets();
......
......@@ -21,8 +21,8 @@
package de.tud.kom.p2psim.impl.util.geo.maps;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis;
......@@ -45,11 +45,11 @@ public interface MapChangeListener {
}
public static class PathEvent implements MapEvent {
private Path path;
public PathEvent(Path changedPath) {
private PathEdge path;
public PathEvent(PathEdge changedPath) {
this.path = changedPath;
}
public Path getPath() {
public PathEdge getPath() {
return path;
}
}
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.util.geo.maps;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.util.geo.maps.Map;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis;
import de.tud.kom.p2psim.impl.util.geo.maps.osm.OSMMap;
......
......@@ -24,7 +24,7 @@ import java.util.Map;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
class FuzzyWaypointCache {
......
......@@ -32,7 +32,7 @@ import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.util.geo.maps.Node;
import de.tud.kom.p2psim.api.util.geo.maps.Way;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.Tuple;
......
......@@ -21,7 +21,7 @@
package de.tud.kom.p2psim.impl.util.geo.maps.osm;
import de.tud.kom.p2psim.api.util.geo.maps.Node;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class OSMNode implements Node {
private Long id;
......
......@@ -24,8 +24,8 @@ import java.util.List;
import com.google.common.collect.Maps;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.obstacles.PolygonObstacle;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class OSMObstacle extends PolygonObstacle {
private java.util.Map<String, String> attributes = Maps.newHashMap();
......
......@@ -38,7 +38,7 @@ import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.util.geo.maps.Node;
import de.tud.kom.p2psim.api.util.geo.maps.Way;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.util.geo.maps.osm;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* A simple bean that holds information about a UTM coordinate
......
......@@ -9,7 +9,8 @@ import static java.lang.Math.cos;
import static java.lang.Math.pow;
import static java.lang.Math.sin;
import static java.lang.Math.tan;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* This class can be used to convert lat/lon coordinates to
......
......@@ -47,10 +47,10 @@ import com.vividsolutions.jts.algorithm.LineIntersector;
import com.vividsolutions.jts.algorithm.RobustLineIntersector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.obstacles.PolygonObstacle;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap;
......@@ -111,15 +111,15 @@ public class SVGMap extends AbstractMap {
private void resolveIntersections() {
List<PositionVector> intersections = Lists.newLinkedList();
List<Path> worklist = Lists.newLinkedList(getPaths());
Iterator<Path> iter = concurrentIterator(worklist);
List<PathEdge> worklist = Lists.newLinkedList(getPaths());
Iterator<PathEdge> iter = concurrentIterator(worklist);
while (iter.hasNext()) {
Path path = iter.next();
PathEdge path = iter.next();
Iterator<Path> compareIter = concurrentIterator(worklist);
Iterator<PathEdge> compareIter = concurrentIterator(worklist);
while (compareIter.hasNext()) {
Path comparePath = compareIter.next();
PathEdge comparePath = compareIter.next();
// Prevent intersection comparison for the same path and
// connected paths
......@@ -140,8 +140,8 @@ public class SVGMap extends AbstractMap {
PositionVector intersection = intersects(path, comparePath);
if (intersection != null) {
Path[] splitPath1 = splitPath(path, intersection);
Path[] splitPath2 = splitPath(comparePath, intersection);
PathEdge[] splitPath1 = splitPath(path, intersection);
PathEdge[] splitPath2 = splitPath(comparePath, intersection);
// Prevent the creation of loops
if (splitPath1[0].getSource().equals(
......@@ -222,20 +222,20 @@ public class SVGMap extends AbstractMap {
};
}
private Path[] splitPath(Path path, PositionVector intersectionPoint) {
Path[] paths = new Path[2];
private PathEdge[] splitPath(PathEdge path, PositionVector intersectionPoint) {
PathEdge[] paths = new PathEdge[2];
Waypoint wp1 = path.getSource();
Waypoint wp2 = path.getTarget();
Waypoint iwp = getWaypoint(intersectionPoint);
paths[0] = new Path(wp1, iwp);
paths[1] = new Path(wp2, iwp);
paths[0] = new PathEdge(wp1, iwp);
paths[1] = new PathEdge(wp2, iwp);
return paths;
}
private PositionVector intersects(Path path1, Path path2) {
private PositionVector intersects(PathEdge path1, PathEdge path2) {
LineIntersector inter = new RobustLineIntersector();
inter.computeIntersection(path1.getSource().getPosition()
......
......@@ -37,6 +37,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.toolkits.DOMToolkit;
......@@ -121,9 +122,13 @@ public class XMLConfigFile implements ConfigFile {
try {
parseContent();
parsed = true;
} catch (ConfigFileException e) {
log("Invalid configuration for starting a scenario. Pleae choose a different one!");
parsed = true;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
log("Problems while parsing. Will not retry.");
e.printStackTrace();
parsed = true;
}
}
......
......@@ -33,15 +33,14 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Node;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
......@@ -67,6 +66,8 @@ public class GlobalOracle implements OracleComponent {
private static GlobalOracle instance = new GlobalOracle();
private static Set<IAttractionPoint> attractionPoints = new LinkedHashSet<IAttractionPoint>();
private GlobalOracle() {
//
}
......@@ -75,6 +76,18 @@ public class GlobalOracle implements OracleComponent {
return instance;
}
public static void addAttractionPoint(IAttractionPoint attractionPoint) {
GlobalOracle.attractionPoints.add(attractionPoint);
}
public static void removeAttractionPoint(IAttractionPoint attractionPoint) {
GlobalOracle.attractionPoints.remove(attractionPoint);
}
public static Set<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
/**
* Initial population with hosts.
*
......@@ -175,11 +188,39 @@ public class GlobalOracle implements OracleComponent {
}
}
/**
* @return the list with all hosts of the scenario
*/
public static List<SimHost> getHostsByGroupID(String groupID) {
if(groupID.equals("")) {
return getHosts();
}
else {
synchronized (hosts) {
ArrayList<SimHost> groupedHosts = new ArrayList<SimHost>();
for (SimHost h : hosts) {
if(h.getProperties().getGroupID().equals(groupID)) {
groupedHosts.add(h);
}
}
return groupedHosts;
}
}
}
@Override
public List<Host> getAllHosts() {
return new ArrayList<Host>(hosts);
}
@Override
public Host getHostByID(long pValue) {
return hostIDtoHosts.get(pValue);
}
@Override
public boolean isSimulation() {
return true;
......
......@@ -90,13 +90,13 @@ public class GeoSpherePosition implements Transmitable, Location {
/** Get the latitude in degrees */
@Override
public double getLatitude() {
public double getLatitudeOrY() {
return Math.toDegrees(latitude);
}
/** Get the longitude in degrees */
@Override
public double getLongitude() {
public double getLongitudeOrX() {
return Math.toDegrees(longitude);
}
......@@ -260,7 +260,7 @@ public class GeoSpherePosition implements Transmitable, Location {
@Override
public String toString() {
return "GeoSpherePos["+getLatitude()+";"+getLongitude()+"]";
return "GeoSpherePos["+getLatitudeOrY()+";"+getLongitudeOrX()+"]";
}
@Override
......
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