Commit 2e28bc46 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Merge branch 'master' into tm/sumo-integration

Conflicts:
	src/de/tud/kom/p2psim/impl/topology/DefaultTopologyComponent.java
parents 8aeec4ee 686eca40
......@@ -66,4 +66,9 @@ public class TransmissionControlProtocolDummy extends AbstractTransProtocol {
return TransProtocol.TCP.getHeaderSize();
}
@Override
public TransProtocol getProtocol() {
return TransProtocol.TCP;
}
}
......@@ -24,6 +24,7 @@ import de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.transport.TransProtocol;
import de.tud.kom.p2psim.impl.transport.UDPMessage;
import de.tud.kom.p2psim.impl.transport.modular.AbstractTransProtocol;
import de.tudarmstadt.maki.simonstrator.api.Message;
......@@ -65,4 +66,9 @@ public class UserDatagramProtocol extends AbstractTransProtocol {
return 8;
}
@Override
public TransProtocol getProtocol() {
return TransProtocol.UDP;
}
}
package de.tud.kom.p2psim.impl.util;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/**
* Reader for csv files. To use this reader you need to implement the
* {@link #parse(String[])}.
*
* @author Clemens Krug
*/
public abstract class CSVReader<T>
{
private String filename;
private String SEP;
public CSVReader(String filename, String SEP)
{
this.filename = filename;
this.SEP = SEP;
}
/**
* Reads the data into a list.
* @return A list of the generated objects.
*/
public List<T> readData()
{
List<T> data = new LinkedList<>();
BufferedReader csv = null;
try {
csv = new BufferedReader(new FileReader(filename));
while (csv.ready()) {
String line = csv.readLine();
if (line.contains(SEP)) {
String[] parts = line.split(SEP);
T entry = parse(parts);
if(entry != null) data.add(entry);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (csv != null) {
try {
csv.close();
} catch (IOException e) {
//nothing
}
}
}
return data;
}
/**
* Parses one line of csv entries into the desired type of object.
* @param parts The csv entries of a line.
* @return Object of desired type.
*/
public abstract T parse(String[] parts);
}
......@@ -169,6 +169,41 @@ public class MeasurementDAO extends DAO {
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
*/
public static void storeSpatialGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatistic measurement = new MeasurementStatistic(time, stats,
groupMetric, observationDuration, describesWholeSimulation, locationX, locationY);
addToPersistQueue(measurement);
}
/**
* Store a list-based measurement with a key (i.e., as a
* {@link MeasurementPairList}).
......
......@@ -119,11 +119,14 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[perc5]")
private Double perc5; // 5
@Column(nullable = true, name = "[skewness]")
private Double skewness;
@Column(nullable = true, name = "[locationX]")
private Integer locationX;
@Column(nullable = true, name = "[kurtosis]")
private Double kurtosis;
@Column(nullable = true, name = "[locationY]")
private Integer locationY;
@Column(nullable = true, name = "[isSpatial]")
private boolean isSpatial;
/**
* Mapping to group metric
......@@ -155,6 +158,36 @@ public class MeasurementStatistic implements GroupMetricBound {
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 MeasurementStatistic(long time, DescriptiveStatistics stats,
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation, int locationX, int locationY) {
this(time, stats, observationDuration, describesWholeSimulation);
this.groupMetric = groupMetric;
this.locationX = locationX;
this.locationY = locationY;
this.isSpatial = true;
}
/**
* Internal - write statistics
*
......@@ -182,9 +215,8 @@ public class MeasurementStatistic implements GroupMetricBound {
this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7));
this.perc5 = checkForSpecialNumbers(stats.getPercentile(5));
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.skewness = checkForSpecialNumbers(stats.getSkewness());
this.kurtosis = checkForSpecialNumbers(stats.getKurtosis());
this.std = checkForSpecialNumbers(stats.getStandardDeviation());
this.isSpatial = false;
}
/**
......
......@@ -27,7 +27,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*/
public class CustomDistribution implements Distribution {
private Random rand = Randoms.getRandom(this);
private Random rand = Randoms.getRandom(CustomDistribution.class);
private String csvFile = "";
......
......@@ -50,7 +50,8 @@ public class ExponentialDistribution implements Distribution {
if (distr == null) throw new ConfigurationException("Mu was not set for exponential distribution " + this);
double random = Randoms.getRandom(this).nextDouble();
double random = Randoms.getRandom(ExponentialDistribution.class)
.nextDouble();
double result;
try {
......
......@@ -132,7 +132,9 @@ public class LimitedNormalDistribution implements Distribution {
}
public double returnValue() {
double random = pmin + Randoms.getRandom(this).nextDouble() * pfactor;
double random = pmin
+ Randoms.getRandom(LimitedNormalDistribution.class)
.nextDouble() * pfactor;
double result;
try {
......
......@@ -22,10 +22,10 @@
package de.tud.kom.p2psim.impl.util.stat.distributions;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
import umontreal.iro.lecuyer.probdist.LognormalDist;
public class LognormalDistribution implements Distribution {
......@@ -48,7 +48,8 @@ public class LognormalDistribution implements Distribution {
}
public double returnValue() {
double random = Randoms.getRandom(this).nextDouble();
double random = Randoms.getRandom(LognormalDistribution.class)
.nextDouble();
double result = 0;
try {
......
......@@ -22,10 +22,10 @@
package de.tud.kom.p2psim.impl.util.stat.distributions;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.Distribution;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
import umontreal.iro.lecuyer.probdist.LognormalDist;
public class MixedLogNormalDistribution implements Distribution {
......@@ -65,7 +65,8 @@ public class MixedLogNormalDistribution implements Distribution {
}
public double returnValue() {
double random = Randoms.getRandom(this).nextDouble();
double random = Randoms.getRandom(MixedLogNormalDistribution.class)
.nextDouble();
double result = 0;
try {
result = weight1 * distr1.inverseF(random) + weight2
......
......@@ -35,7 +35,7 @@ public class NormalDistribution implements Distribution {
private NormalDistributionImpl normal;
private Random randomGen = Randoms.getRandom(this);
private Random randomGen = Randoms.getRandom(NormalDistribution.class);
private double mu;
......
......@@ -42,7 +42,7 @@ public class PoissonDistribution implements Distribution {
// returns the x-value for a random value in the cdf
public double returnValue() {
double random = Randoms.getRandom(this)
double random = Randoms.getRandom(PoissonDistribution.class)
.nextDouble();
int result;
......
......@@ -50,7 +50,8 @@ public class UniformDistribution implements Distribution {
*/
public double returnValue() {
return min + factor * Randoms.getRandom(this).nextDouble();
return min + factor
* Randoms.getRandom(UniformDistribution.class).nextDouble();
}
/**
......
......@@ -66,7 +66,8 @@ public class ZipfDistribution implements Distribution {
// rank = 1 ... maximum_Number_Of_Ranks => 1/rank = 0..1
return 1 / (Math
.pow(1 / (Randoms.getRandom(this).nextDouble() * harmonicNormFactor),
.pow(1 / (Randoms.getRandom(ZipfDistribution.class).nextDouble()
* harmonicNormFactor),
1 / zipfExponent));
}
......
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