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; ...@@ -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.MeasurementSingle;
import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial; 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.MeasurementStatisticMsgType;
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;
import de.tud.kom.p2psim.impl.util.stats.StatisticComputation; 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. * This class provides methods to persist measurements in a database.
...@@ -53,7 +55,7 @@ public class MeasurementDAO extends DAO { ...@@ -53,7 +55,7 @@ public class MeasurementDAO extends DAO {
/** /**
* The Host ID that is used for global metrics. * 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; private static boolean inactive = false;
...@@ -102,31 +104,47 @@ public class MeasurementDAO extends DAO { ...@@ -102,31 +104,47 @@ 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); * 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);
}
/**
* 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);
}
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
...@@ -194,7 +212,7 @@ public class MeasurementDAO extends DAO { ...@@ -194,7 +212,7 @@ public class MeasurementDAO extends DAO {
groupMetric, observationDuration, describesWholeSimulation); groupMetric, observationDuration, describesWholeSimulation);
addToPersistQueue(measurement); addToPersistQueue(measurement);
} }
/** /**
* Stores a statistical description of a series of values for group of * Stores a statistical description of a series of values for group of
* hosts and a given spatial coordinate. * hosts and a given spatial coordinate.
...@@ -229,11 +247,81 @@ public class MeasurementDAO extends DAO { ...@@ -229,11 +247,81 @@ public class MeasurementDAO extends DAO {
addToPersistQueue(measurement); 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 * Store a list-based measurement with a key (i.e., as a
* {@link MeasurementPairList}). * {@link MeasurementPairList}).
* *
* @param metricDesc * @param metricDesc
* @param hostId * @param hostId
* @param time * @param time
...@@ -256,7 +344,7 @@ public class MeasurementDAO extends DAO { ...@@ -256,7 +344,7 @@ public class MeasurementDAO extends DAO {
/** /**
* Shortcut for {@link MeasurementPairList} metrics based on a single list. * Shortcut for {@link MeasurementPairList} metrics based on a single list.
* *
* @param metric * @param metric
* @param hostId * @param hostId
* @param time * @param time
......
package de.tud.kom.p2psim.impl.util.db.dao.metric; package de.tud.kom.p2psim.impl.util.db.dao.metric;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; 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.Tuple;
import de.tud.kom.p2psim.impl.util.db.dao.DAO; 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.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
...@@ -53,6 +59,21 @@ public class MetricDAO extends DAO { ...@@ -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 /** Retrieve a {@link Metric} object for the given MetricDescription
* for single value metrics. * for single value metrics.
* *
...@@ -62,7 +83,7 @@ public class MetricDAO extends DAO { ...@@ -62,7 +83,7 @@ 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 /** Retrieve a {@link Metric} object for the given MetricDescription
* for spatial value metrics. * for spatial value metrics.
* *
...@@ -86,7 +107,7 @@ public class MetricDAO extends DAO { ...@@ -86,7 +107,7 @@ public class MetricDAO extends DAO {
/** /**
* Retrieve a {@link Metric} object for the given MetricDescription for pair * Retrieve a {@link Metric} object for the given MetricDescription for pair
* list metrics. * list metrics.
* *
* If there is no matching Metric object, it is created, persisted, and * If there is no matching Metric object, it is created, persisted, and
* cached automatically. * cached automatically.
*/ */
......
/*
* 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 { ...@@ -152,6 +152,14 @@ public class Metric {
return true; return true;
} }
public String getName() {
return name;
}
public String getComment() {
return comment;
}
@Override @Override
public String toString() { public String toString() {
return "Metric{" + return "Metric{" +
......
...@@ -38,8 +38,6 @@ import java.util.Map; ...@@ -38,8 +38,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import javanet.staxutils.IndentingXMLStreamWriter;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
...@@ -55,6 +53,8 @@ import de.tud.kom.p2psim.impl.util.toolkits.SAXToolkit; ...@@ -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;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import com.sun.xml.txw2.output.IndentingXMLStreamWriter;
/** /**
* <p> * <p>
* An simple, high performance relational database for object-oriented environments. A key function * An simple, high performance relational database for object-oriented environments. A key function
...@@ -436,7 +436,7 @@ public abstract class RelationalDB implements XMLSerializable { ...@@ -436,7 +436,7 @@ public abstract class RelationalDB implements XMLSerializable {
IndentingXMLStreamWriter indwr = new IndentingXMLStreamWriter(writer); //Ensures indentation of the XML document IndentingXMLStreamWriter indwr = new IndentingXMLStreamWriter(writer); //Ensures indentation of the XML document
indwr.setIndent(" "); indwr.setIndentStep(" ");
writer = indwr; writer = indwr;
writer.writeStartDocument("1.0"); writer.writeStartDocument("1.0");
......
...@@ -28,23 +28,24 @@ import java.util.PriorityQueue; ...@@ -28,23 +28,24 @@ import java.util.PriorityQueue;
import java.util.Queue; import java.util.Queue;
import java.util.Set; 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.ArrayListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; 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.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle; 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.Map;
import de.tud.kom.p2psim.api.util.geo.maps.Way; 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.obstacles.PolygonObstacle;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
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.PathEdgeFactory;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint; 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.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener.MapEvent; 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; ...@@ -52,10 +53,9 @@ import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener.MapEvent;
public abstract class AbstractMap implements Map { public abstract class AbstractMap implements Map {
private List<Obstacle> obstacles = Lists.newLinkedList(); 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>( protected Graph<Waypoint, PathEdge> graph = new SimpleWeightedGraph<>(PathEdge.class);
new PathEdgeFactory());
private Multimap<Class, Waypoint> typeWaypointMap = ArrayListMultimap.create(); private Multimap<Class, Waypoint> typeWaypointMap = ArrayListMultimap.create();
...@@ -106,10 +106,9 @@ public abstract class AbstractMap implements Map { ...@@ -106,10 +106,9 @@ public abstract class AbstractMap implements Map {
} }
protected void buildGraph() { protected void buildGraph() {
graph = new DefaultWeightedEdgeRetrievableGraph<Waypoint, Path>( graph = new SimpleWeightedGraph<>(PathEdge.class);
new PathEdgeFactory());
for (Path path : paths) { for (PathEdge path : paths) {
graph.addVertex(path.getSource()); graph.addVertex(path.getSource());
graph.addVertex(path.getTarget()); graph.addVertex(path.getTarget());
typeWaypointMap.put(path.getSource().getClass(), path.getSource()); typeWaypointMap.put(path.getSource().getClass(), path.getSource());
...@@ -123,12 +122,12 @@ public abstract class AbstractMap implements Map { ...@@ -123,12 +122,12 @@ public abstract class AbstractMap implements Map {
raiseMapChanged(new MapChangeListener.ObstacleEvent(obstacle)); raiseMapChanged(new MapChangeListener.ObstacleEvent(obstacle));
} }
public void addPath(Path path) { public void addPath(PathEdge path) {
paths.add(path); paths.add(path);
raiseMapChanged(new MapChangeListener.PathEvent(path)); raiseMapChanged(new MapChangeListener.PathEvent(path));
} }
public List<Path> getPaths() { public List<PathEdge> getPaths() {
return paths; return paths;
} }
...@@ -192,12 +191,11 @@ public abstract class AbstractMap implements Map { ...@@ -192,12 +191,11 @@ public abstract class AbstractMap implements Map {
} }
protected void createPath(Waypoint wp1, Waypoint wp2) { protected void createPath(Waypoint wp1, Waypoint wp2) {
Path path = new Path(wp1, wp2); PathEdge path = new PathEdge(wp1, wp2);
addPath(path); addPath(path);
} }
@SuppressWarnings("unchecked") public Graph<Waypoint, PathEdge> getGraph() {
public DefaultWeightedEdgeRetrievableGraph getGraph() {
return graph; return graph;
} }
...@@ -257,11 +255,10 @@ public abstract class AbstractMap implements Map { ...@@ -257,11 +255,10 @@ public abstract class AbstractMap implements Map {
return swapped[axis.ordinal()]; return swapped[axis.ordinal()];
} }
public List<Path> getShortestPath(Waypoint start, Waypoint end) { public List<PathEdge> getShortestPath(Waypoint start, Waypoint end) {
DijkstraShortestPath<Waypoint, Path> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, Path>( DijkstraShortestPath<Waypoint, PathEdge> dijkstrashortestpath = new DijkstraShortestPath<Waypoint, PathEdge>(graph);
graph, start, end); GraphPath<Waypoint, PathEdge> path = dijkstrashortestpath.getPath(start, end);
return path.getEdgeList();
return dijkstrashortestpath.getPathEdgeList();
} }
public void addWaypoint(Waypoint wp) { public void addWaypoint(Waypoint wp) {
...@@ -320,8 +317,8 @@ public abstract class AbstractMap implements Map { ...@@ -320,8 +317,8 @@ public abstract class AbstractMap implements Map {
while (waypoints != null) { while (waypoints != null) {
//removeWaypoints(waypoints, WeakWaypoint.class); //removeWaypoints(waypoints, WeakWaypoint.class);
for (Waypoint w : waypoints) { for (Waypoint w : waypoints) {
Set<Path> edges = Sets.newHashSet(graph.edgesOf(w)); Set<PathEdge> edges = Sets.newHashSet(graph.edgesOf(w));
for (Path p : edges) { for (PathEdge p : edges) {
graph.removeEdge(p); graph.removeEdge(p);
} }
graph.removeVertex(w); graph.removeVertex(w);
...@@ -359,8 +356,8 @@ public abstract class AbstractMap implements Map { ...@@ -359,8 +356,8 @@ public abstract class AbstractMap implements Map {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
//removeWaypoint(shortestDistancePair.getA()); //removeWaypoint(shortestDistancePair.getA());
Set<Path> edges = graph.outgoingEdgesOf(shortestDistancePair.getA()); Set<PathEdge> edges = graph.outgoingEdgesOf(shortestDistancePair.getA());
for (Path p : edges) { for (PathEdge p : edges) {
graph.removeEdge(p); graph.removeEdge(p);
} }
graph.removeVertex(shortestDistancePair.getA()); graph.removeVertex(shortestDistancePair.getA());
...@@ -419,7 +416,7 @@ public abstract class AbstractMap implements Map { ...@@ -419,7 +416,7 @@ public abstract class AbstractMap implements Map {
} }
private Queue<List<Waypoint>> getConnectedComponents() { private Queue<List<Waypoint>> getConnectedComponents() {
ConnectivityInspector ci = new ConnectivityInspector<Waypoint, Path>(getGraph()); ConnectivityInspector ci = new ConnectivityInspector<Waypoint, PathEdge>(getGraph());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Set<Waypoint>> connectedSets = ci.connectedSets(); List<Set<Waypoint>> connectedSets = ci.connectedSets();
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
package de.tud.kom.p2psim.impl.util.geo.maps; package de.tud.kom.p2psim.impl.util.geo.maps;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle; import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
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.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.Waypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis; import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis;
...@@ -45,11 +45,11 @@ public interface MapChangeListener { ...@@ -45,11 +45,11 @@ public interface MapChangeListener {
} }
public static class PathEvent implements MapEvent { public static class PathEvent implements MapEvent {
private Path path; private PathEdge path;
public PathEvent(Path changedPath) { public PathEvent(PathEdge changedPath) {
this.path = changedPath; this.path = changedPath;
} }
public Path getPath() { public PathEdge getPath() {
return path; return path;
} }
} }
......
...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.util.geo.maps; ...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.util.geo.maps;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.util.geo.maps.Map; 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.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis; import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap.Axis;
import de.tud.kom.p2psim.impl.util.geo.maps.osm.OSMMap; import de.tud.kom.p2psim.impl.util.geo.maps.osm.OSMMap;
......
...@@ -24,7 +24,7 @@ import java.util.Map; ...@@ -24,7 +24,7 @@ import java.util.Map;
import com.google.common.collect.Maps; 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; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
class FuzzyWaypointCache { class FuzzyWaypointCache {
......
...@@ -32,7 +32,7 @@ import com.google.common.collect.Maps; ...@@ -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.Node;
import de.tud.kom.p2psim.api.util.geo.maps.Way; 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.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint; import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.Tuple; import de.tud.kom.p2psim.impl.util.Tuple;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
package de.tud.kom.p2psim.impl.util.geo.maps.osm; 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.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 { public class OSMNode implements Node {
private Long id; private Long id;
......
...@@ -24,8 +24,8 @@ import java.util.List; ...@@ -24,8 +24,8 @@ import java.util.List;
import com.google.common.collect.Maps; 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.obstacles.PolygonObstacle;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class OSMObstacle extends PolygonObstacle { public class OSMObstacle extends PolygonObstacle {
private java.util.Map<String, String> attributes = Maps.newHashMap(); private java.util.Map<String, String> attributes = Maps.newHashMap();
......
...@@ -38,7 +38,7 @@ import org.xml.sax.helpers.DefaultHandler; ...@@ -38,7 +38,7 @@ import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; 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.Node;
import de.tud.kom.p2psim.api.util.geo.maps.Way; 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;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.util.geo.maps.osm; 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 * A simple bean that holds information about a UTM coordinate
......
...@@ -9,7 +9,8 @@ import static java.lang.Math.cos; ...@@ -9,7 +9,8 @@ import static java.lang.Math.cos;
import static java.lang.Math.pow; import static java.lang.Math.pow;
import static java.lang.Math.sin; import static java.lang.Math.sin;
import static java.lang.Math.tan; 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 * This class can be used to convert lat/lon coordinates to
......
...@@ -47,10 +47,10 @@ import com.vividsolutions.jts.algorithm.LineIntersector; ...@@ -47,10 +47,10 @@ import com.vividsolutions.jts.algorithm.LineIntersector;
import com.vividsolutions.jts.algorithm.RobustLineIntersector; import com.vividsolutions.jts.algorithm.RobustLineIntersector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; 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.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.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.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint; import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap; import de.tud.kom.p2psim.impl.util.geo.maps.AbstractMap;
...@@ -111,15 +111,15 @@ public class SVGMap extends AbstractMap { ...@@ -111,15 +111,15 @@ public class SVGMap extends AbstractMap {
private void resolveIntersections() { private void resolveIntersections() {
List<PositionVector> intersections = Lists.newLinkedList(); List<PositionVector> intersections = Lists.newLinkedList();
List<Path> worklist = Lists.newLinkedList(getPaths()); List<PathEdge> worklist = Lists.newLinkedList(getPaths());
Iterator<Path> iter = concurrentIterator(worklist); Iterator<PathEdge> iter = concurrentIterator(worklist);
while (iter.hasNext()) { while (iter.hasNext()) {
Path path = iter.next(); PathEdge path = iter.next();
Iterator<Path> compareIter = concurrentIterator(worklist); Iterator<PathEdge> compareIter = concurrentIterator(worklist);
while (compareIter.hasNext()) { while (compareIter.hasNext()) {
Path comparePath = compareIter.next(); PathEdge comparePath = compareIter.next();
// Prevent intersection comparison for the same path and // Prevent intersection comparison for the same path and
// connected paths // connected paths
...@@ -140,8 +140,8 @@ public class SVGMap extends AbstractMap { ...@@ -140,8 +140,8 @@ public class SVGMap extends AbstractMap {
PositionVector intersection = intersects(path, comparePath); PositionVector intersection = intersects(path, comparePath);
if (intersection != null) { if (intersection != null) {
Path[] splitPath1 = splitPath(path, intersection); PathEdge[] splitPath1 = splitPath(path, intersection);
Path[] splitPath2 = splitPath(comparePath, intersection); PathEdge[] splitPath2 = splitPath(comparePath, intersection);
// Prevent the creation of loops // Prevent the creation of loops
if (splitPath1[0].getSource().equals( if (splitPath1[0].getSource().equals(
...@@ -222,20 +222,20 @@ public class SVGMap extends AbstractMap { ...@@ -222,20 +222,20 @@ public class SVGMap extends AbstractMap {
}; };
} }
private Path[] splitPath(Path path, PositionVector intersectionPoint) { private PathEdge[] splitPath(PathEdge path, PositionVector intersectionPoint) {
Path[] paths = new Path[2]; PathEdge[] paths = new PathEdge[2];
Waypoint wp1 = path.getSource(); Waypoint wp1 = path.getSource();
Waypoint wp2 = path.getTarget(); Waypoint wp2 = path.getTarget();
Waypoint iwp = getWaypoint(intersectionPoint); Waypoint iwp = getWaypoint(intersectionPoint);
paths[0] = new Path(wp1, iwp); paths[0] = new PathEdge(wp1, iwp);
paths[1] = new Path(wp2, iwp); paths[1] = new PathEdge(wp2, iwp);
return paths; return paths;
} }
private PositionVector intersects(Path path1, Path path2) { private PositionVector intersects(PathEdge path1, PathEdge path2) {
LineIntersector inter = new RobustLineIntersector(); LineIntersector inter = new RobustLineIntersector();
inter.computeIntersection(path1.getSource().getPosition() inter.computeIntersection(path1.getSource().getPosition()
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab * Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -32,9 +32,9 @@ import de.tud.kom.p2psim.impl.util.guirunner.GUIRunner; ...@@ -32,9 +32,9 @@ import de.tud.kom.p2psim.impl.util.guirunner.GUIRunner;
import de.tud.kom.p2psim.impl.util.guirunner.seed.SeedDetermination; import de.tud.kom.p2psim.impl.util.guirunner.seed.SeedDetermination;
/** /**
* *
* Runs the simulator or invokes operations on the view. * Runs the simulator or invokes operations on the view.
* *
* @author Leo Nobach * @author Leo Nobach
* @version 3.0, 25.11.2008 * @version 3.0, 25.11.2008
* *
...@@ -45,11 +45,11 @@ public class RunnerController implements ActionListener { ...@@ -45,11 +45,11 @@ public class RunnerController implements ActionListener {
ConfigFile selectedFile = null; ConfigFile selectedFile = null;
JButton launchButton = null; JButton launchButton = null;
private GUIRunner runner; private GUIRunner runner;
private List<IRunnerCtrlListener> listeners = new LinkedList<IRunnerCtrlListener>(); private List<IRunnerCtrlListener> listeners = new LinkedList<IRunnerCtrlListener>();
SeedDetermination det = new SeedDetermination(); SeedDetermination det = new SeedDetermination();
/** /**
* Runs the simulator with the specified config file string. * Runs the simulator with the specified config file string.
* @param configFile * @param configFile
...@@ -57,9 +57,9 @@ public class RunnerController implements ActionListener { ...@@ -57,9 +57,9 @@ public class RunnerController implements ActionListener {
private void runSimulator() { private void runSimulator() {
SimulationThread simulationThread = new SimulationThread(selectedFile, det.getChosenSeed()); SimulationThread simulationThread = new SimulationThread(selectedFile, det.getChosenSeed());
simulationThread.start(); simulationThread.start();
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
...@@ -78,30 +78,30 @@ public class RunnerController implements ActionListener { ...@@ -78,30 +78,30 @@ public class RunnerController implements ActionListener {
}); });
// thread.start(); // thread.start();
} }
public void setLastOpened(LastOpened lastOpened) { public void setLastOpened(LastOpened lastOpened) {
this.lastOpened = lastOpened; this.lastOpened = lastOpened;
} }
public SeedDetermination getDetermination() { public SeedDetermination getDetermination() {
return det; return det;
} }
/** /**
* Called when the user wants to start the simulation. * Called when the user wants to start the simulation.
*/ */
public void invokeRunSimulator() { public void invokeRunSimulator() {
if (selectedFile == null) return; //No file is selected! if (selectedFile == null) return; //No file is selected!
if (lastOpened != null) lastOpened.append(selectedFile); if (lastOpened != null) lastOpened.append(selectedFile);
lastOpened.saveToFile(); lastOpened.saveToFile();
System.out.println("GUIRunner: Starting simulator with " + selectedFile.getFile().getAbsolutePath()); System.out.println("GUIRunner: Starting simulator with " + selectedFile.getFile().getAbsolutePath());
runner.disposeRunner(); runner.disposeRunner();
det.saveSettings(); det.saveSettings();
runSimulator(); runSimulator();
} }
...@@ -111,11 +111,11 @@ public class RunnerController implements ActionListener { ...@@ -111,11 +111,11 @@ public class RunnerController implements ActionListener {
*/ */
public void selectFile(final ConfigFile file) { public void selectFile(final ConfigFile file) {
selectedFile = file; selectedFile = file;
if (selectedFile == null) { if (selectedFile == null) {
return; return;
} }
selectedFile.loadConfiguration(new ConfigLoadedCallback() { selectedFile.loadConfiguration(new ConfigLoadedCallback() {
@Override @Override
public void loadingFinished() { public void loadingFinished() {
...@@ -123,11 +123,11 @@ public class RunnerController implements ActionListener { ...@@ -123,11 +123,11 @@ public class RunnerController implements ActionListener {
launchButton.setEnabled(selectedFile != null); launchButton.setEnabled(selectedFile != null);
} }
if (file != null) det.loadFile(selectedFile); if (file != null) det.loadFile(selectedFile);
newFileSelected(file); newFileSelected(file);
} }
}); });
} }
/** /**
* Sets the launch button that invokes the launch of the * Sets the launch button that invokes the launch of the
* simulation * simulation
...@@ -144,15 +144,15 @@ public class RunnerController implements ActionListener { ...@@ -144,15 +144,15 @@ public class RunnerController implements ActionListener {
invokeRunSimulator(); invokeRunSimulator();
} }
} }
public void addListener(IRunnerCtrlListener l) { public void addListener(IRunnerCtrlListener l) {
listeners.add(l); listeners.add(l);
} }
public void removeListener(IRunnerCtrlListener l) { public void removeListener(IRunnerCtrlListener l) {
listeners.remove(l); listeners.remove(l);
} }
void newFileSelected(ConfigFile f) { void newFileSelected(ConfigFile f) {
for (IRunnerCtrlListener l : listeners) l.newFileSelected(f); for (IRunnerCtrlListener l : listeners) l.newFileSelected(f);
} }
...@@ -164,16 +164,16 @@ public class RunnerController implements ActionListener { ...@@ -164,16 +164,16 @@ public class RunnerController implements ActionListener {
public void setMainWindow(GUIRunner runner) { public void setMainWindow(GUIRunner runner) {
this.runner=runner; this.runner=runner;
} }
public static interface IRunnerCtrlListener { public static interface IRunnerCtrlListener {
public void newFileSelected(ConfigFile f); public void newFileSelected(ConfigFile f);
} }
public ConfigFile getSelectedFile() { public ConfigFile getSelectedFile() {
return selectedFile; return selectedFile;
} }
} }
...@@ -37,6 +37,7 @@ import javax.xml.parsers.DocumentBuilderFactory; ...@@ -37,6 +37,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; 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.Tuple;
import de.tud.kom.p2psim.impl.util.toolkits.DOMToolkit; import de.tud.kom.p2psim.impl.util.toolkits.DOMToolkit;
...@@ -121,9 +122,13 @@ public class XMLConfigFile implements ConfigFile { ...@@ -121,9 +122,13 @@ public class XMLConfigFile implements ConfigFile {
try { try {
parseContent(); parseContent();
parsed = true; 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) { } catch (Exception e) {
log("Problems while parsing. Will not retry."); log("Problems while parsing. Will not retry.");
e.printStackTrace();
parsed = true; parsed = true;
} }
} }
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab * Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -33,27 +33,26 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -33,27 +33,26 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tudarmstadt.maki.simonstrator.api.Graphs; import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms; 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.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge; 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.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.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent; 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.NetID;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface; 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.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider; import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
/** /**
* This class gives access to the hosts of the scenario. To work, it has to be * This class gives access to the hosts of the scenario. To work, it has to be
* referenced in the configuration file after the host builder. * referenced in the configuration file after the host builder.
* *
* The purpose of this class is to enable a global knowledge for analyzing. It * The purpose of this class is to enable a global knowledge for analyzing. It
* is not meant to be used within any functional parts of simulated systems. * is not meant to be used within any functional parts of simulated systems.
* *
* @author Julius Rueckert * @author Julius Rueckert
* *
*/ */
public class GlobalOracle implements OracleComponent { public class GlobalOracle implements OracleComponent {
...@@ -66,6 +65,8 @@ public class GlobalOracle implements OracleComponent { ...@@ -66,6 +65,8 @@ public class GlobalOracle implements OracleComponent {
private static List<NetID> bootstrapList = new LinkedList<NetID>(); private static List<NetID> bootstrapList = new LinkedList<NetID>();
private static GlobalOracle instance = new GlobalOracle(); private static GlobalOracle instance = new GlobalOracle();
private static Set<IAttractionPoint> attractionPoints = new LinkedHashSet<IAttractionPoint>();
private GlobalOracle() { private GlobalOracle() {
// //
...@@ -74,10 +75,22 @@ public class GlobalOracle implements OracleComponent { ...@@ -74,10 +75,22 @@ public class GlobalOracle implements OracleComponent {
public static GlobalOracle getInstance() { public static GlobalOracle getInstance() {
return instance; 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. * Initial population with hosts.
* *
* @param hostBuilder * @param hostBuilder
*/ */
public static void populate(List<SimHost> allHosts) { public static void populate(List<SimHost> allHosts) {
...@@ -107,7 +120,7 @@ public class GlobalOracle implements OracleComponent { ...@@ -107,7 +120,7 @@ public class GlobalOracle implements OracleComponent {
/** /**
* Sets the bootstrap hosts. To be called by netLayer. * Sets the bootstrap hosts. To be called by netLayer.
* *
* @param bootstrapList * @param bootstrapList
* the new bootstrap hosts * the new bootstrap hosts
*/ */
...@@ -117,7 +130,7 @@ public class GlobalOracle implements OracleComponent { ...@@ -117,7 +130,7 @@ public class GlobalOracle implements OracleComponent {
/** /**
* Gets the bootstrap hosts. * Gets the bootstrap hosts.
* *
* @return the bootstrap hosts * @return the bootstrap hosts
*/ */
public static List<NetID> getBootstrapHosts() { public static List<NetID> getBootstrapHosts() {
...@@ -126,7 +139,7 @@ public class GlobalOracle implements OracleComponent { ...@@ -126,7 +139,7 @@ public class GlobalOracle implements OracleComponent {
/** /**
* Gets the random host. * Gets the random host.
* *
* @return the random host * @return the random host
*/ */
public static NetID getRandomHost() { public static NetID getRandomHost() {
...@@ -136,7 +149,7 @@ public class GlobalOracle implements OracleComponent { ...@@ -136,7 +149,7 @@ public class GlobalOracle implements OracleComponent {
/** /**
* Gets the first host. * Gets the first host.
* *
* @return the first host * @return the first host
*/ */
public static NetID getFirstHost() { public static NetID getFirstHost() {
...@@ -175,22 +188,50 @@ public class GlobalOracle implements OracleComponent { ...@@ -175,22 +188,50 @@ 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 @Override
public List<Host> getAllHosts() { public List<Host> getAllHosts() {
return new ArrayList<Host>(hosts); return new ArrayList<Host>(hosts);
} }
@Override
public Host getHostByID(long pValue) {
return hostIDtoHosts.get(pValue);
}
@Override @Override
public boolean isSimulation() { public boolean isSimulation() {
return true; return true;
} }
/** /**
* Returns a global view of the topology for the specified mechanism. The * Returns a global view of the topology for the specified mechanism. The
* mechanism must be a HostComponent that is registered at the local host. * mechanism must be a HostComponent that is registered at the local host.
* Otherwise, this method will not be able to find the local mechanism * Otherwise, this method will not be able to find the local mechanism
* objects. * objects.
* *
* @param component * @param component
* @param identifier * @param identifier
* @return * @return
...@@ -239,17 +280,17 @@ public class GlobalOracle implements OracleComponent { ...@@ -239,17 +280,17 @@ public class GlobalOracle implements OracleComponent {
IEdge copy = graph.createEdge(edge.fromId(), edge.toId()); IEdge copy = graph.createEdge(edge.fromId(), edge.toId());
copy.addPropertiesFrom(edge); copy.addPropertiesFrom(edge);
} }
return graph; return graph;
} }
/** /**
* Returns available topology identifiers for the given component. Throws an * Returns available topology identifiers for the given component. Throws an
* {@link ComponentNotAvailableException} if the component is not available * {@link ComponentNotAvailableException} if the component is not available
* on any node in the network. Assumes that all instances of a given * on any node in the network. Assumes that all instances of a given
* component class provide the same topology identifiers. * component class provide the same topology identifiers.
* *
* @throws ComponentNotAvailableException * @throws ComponentNotAvailableException
*/ */
public static <T extends TopologyProvider> Iterable<TopologyID> getTopologyIdentifiers( public static <T extends TopologyProvider> Iterable<TopologyID> getTopologyIdentifiers(
Class<T> component) throws ComponentNotAvailableException { Class<T> component) throws ComponentNotAvailableException {
...@@ -269,16 +310,16 @@ public class GlobalOracle implements OracleComponent { ...@@ -269,16 +310,16 @@ public class GlobalOracle implements OracleComponent {
// in various scenarios // in various scenarios
} }
} }
throw new ComponentNotAvailableException(); throw new ComponentNotAvailableException();
} }
/** /**
* Checks whether the host with the given NetID is online using a global * Checks whether the host with the given NetID is online using a global
* list of all hosts in the current scenario. * list of all hosts in the current scenario.
* *
* @param receiver * @param receiver
* @return true if online * @return true if online
*/ */
......
...@@ -90,13 +90,13 @@ public class GeoSpherePosition implements Transmitable, Location { ...@@ -90,13 +90,13 @@ public class GeoSpherePosition implements Transmitable, Location {
/** Get the latitude in degrees */ /** Get the latitude in degrees */
@Override @Override
public double getLatitude() { public double getLatitudeOrY() {
return Math.toDegrees(latitude); return Math.toDegrees(latitude);
} }
/** Get the longitude in degrees */ /** Get the longitude in degrees */
@Override @Override
public double getLongitude() { public double getLongitudeOrX() {
return Math.toDegrees(longitude); return Math.toDegrees(longitude);
} }
...@@ -260,7 +260,7 @@ public class GeoSpherePosition implements Transmitable, Location { ...@@ -260,7 +260,7 @@ public class GeoSpherePosition implements Transmitable, Location {
@Override @Override
public String toString() { public String toString() {
return "GeoSpherePos["+getLatitude()+";"+getLongitude()+"]"; return "GeoSpherePos["+getLatitudeOrY()+";"+getLongitudeOrX()+"]";
} }
@Override @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