Commit 15bca905 authored by Clemens Krug's avatar Clemens Krug
Browse files

Merged branch "master" into "nr/resAlloc-Clemens"

parents 1bb39784 bccf15b5
......@@ -38,8 +38,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.MetricFilter;
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
public abstract class AbstractFilter<M extends MetricValue<?>> implements
MetricFilter {
public abstract class AbstractFilter<M extends MetricValue<?>>
implements MetricFilter {
private final String name;
......@@ -67,6 +67,20 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
......@@ -83,7 +97,9 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
incomingMetrics.add(metric);
}
if (incomingMetrics.isEmpty()) {
throw new AssertionError("No incoming metrics configured! Available metrics are: "+metrics.toString());
throw new AssertionError(
"No incoming metrics configured! Available metrics are: "
+ metrics.toString());
}
onInitialize(incomingMetrics);
......@@ -233,8 +249,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>> implements
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
private class DerivedActiveMetric extends DerivedMetric implements
ActiveMetric<M> {
private class DerivedActiveMetric extends DerivedMetric
implements ActiveMetric<M> {
private final List<ActiveMetricListener> listeners;
......
/*
* 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.analyzer.metric.filter;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.LifecycleComponent;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Filter a metric usign a {@link LifecycleComponent}s isActive method.
*
* @author Bjoern Richerzhagen
* @version 1.0, Feb 7, 2017
*/
public class ActiveComponentFilter extends AbstractFilter<MetricValue<?>> {
private Class<? extends LifecycleComponent> compClass;
private String description;
private String prefix;
@SuppressWarnings("unchecked")
@XMLConfigurableConstructor({ "clazz", "prefix" })
public ActiveComponentFilter(String clazz, String prefix) {
super("active");
this.prefix = prefix;
description = "only active "+clazz.substring(clazz.lastIndexOf(".") + 1);
// Find class
try {
compClass = (Class<? extends LifecycleComponent>) Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new AssertionError();
}
}
@Override
protected String getNameForDerivedMetric(List<Metric<?>> inputs) {
assert inputs.size() == 1;
return prefix + "_" + inputs.get(0).getName();
}
@Override
protected void onInitialize(List<Metric<?>> incomingMetrics) {
for (Metric metric : incomingMetrics) {
if (metric.isOverallMetric()) {
continue;
}
createDerivedMetric(metric, false, metric.getUnit(),
description + " of " + metric.getName(), false);
}
}
@Override
public void onStop() {
// nothing to do
}
@Override
protected MetricValue<?> getDerivedMetricValueFor(Metric<?> derivedMetric,
List<Metric<?>> inputs, Host host) {
assert inputs.size() == 1;
assert host != null;
Metric<?> input = inputs.get(0);
if (input.isOverallMetric()) {
throw new AssertionError(
"Only available for per-host input metrics.");
}
try {
LifecycleComponent comp = host.getComponent(compClass);
MetricValue mvIn = input.getPerHostMetric(host.getId());
if (mvIn != null) {
return new ActiveHostMetricValue(input.getPerHostMetric(host.getId()), comp);
}
} catch (ComponentNotAvailableException e) {
//
}
return null; // no derived metric
}
/**
* Computes statistics such as svg, sum, std...
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
private class ActiveHostMetricValue implements MetricValue {
private final MetricValue input;
private final LifecycleComponent comp;
public ActiveHostMetricValue(MetricValue input, LifecycleComponent comp) {
this.input = input;
this.comp = comp;
}
@Override
public Object getValue() {
return input.getValue();
}
@Override
public boolean isValid() {
return comp.isActive() && input.isValid();
}
}
}
......@@ -46,6 +46,20 @@ public abstract class AbstractOutput implements MetricOutput {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
......
......@@ -25,6 +25,7 @@ import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
......@@ -56,6 +57,8 @@ public class MetricOutputDAO extends AbstractOutput {
protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<MetricDaoAdapter> daoAdapters = new LinkedList<>();
/**
*
* @param table
......@@ -93,6 +96,29 @@ public class MetricOutputDAO extends AbstractOutput {
this.metricsToAggregate.add(metric);
}
}
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
@Override
public void onInitialize(List<Metric> metrics) {
......@@ -103,13 +129,18 @@ public class MetricOutputDAO extends AbstractOutput {
*/
if (metric instanceof ActiveMetric) {
ActiveMetric am = (ActiveMetric) metric;
am.addActiveMetricListener(new MetricDaoAdapter(am));
MetricDaoAdapter adapter = new MetricDaoAdapter(am);
am.addActiveMetricListener(adapter);
daoAdapters.add(adapter);
}
}
}
@Override
public void onStop() {
for (MetricDaoAdapter adapter : daoAdapters) {
adapter.onStop();
}
/*
* Commit missing values
*/
......@@ -136,23 +167,43 @@ public class MetricOutputDAO extends AbstractOutput {
private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) {
this.metric = metric;
this.md = new MetricDescription(MetricOutputDAO.class.getName(),
metric.getName(), metric.getDescription(),
metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts();
writeAggregates = metricsToAggregate.contains(metric.getName());
this.writeAggregates = isToAggregate(metric);
this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId,
new DescriptiveStatistics());
}
this.hostsByGroup.get(groupId).add(simHost);
}
}
public void onStop() {
if (writeAggregates) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
groupData.getKey(), Time.getCurrentTime(),
groupData.getValue(),
Time.getCurrentTime() - timeEnableDao, true);
}
globalStatsByGroup.clear();
}
}
@Override
public void onMetricUpdate(ActiveMetric metric) {
long time = Time.getCurrentTime();
......@@ -182,6 +233,8 @@ public class MetricOutputDAO extends AbstractOutput {
// Iterate over groups
for (String group : hostsByGroup.keySet()) {
DescriptiveStatistics stats = new DescriptiveStatistics();
DescriptiveStatistics globalStats = globalStatsByGroup
.get(group);
for (SimHost host : hostsByGroup.get(group)) {
MetricValue mv = metric
.getPerHostMetric(host.getId());
......@@ -196,14 +249,22 @@ public class MetricOutputDAO extends AbstractOutput {
}
// Add value
stats.addValue(vd);
globalStats.addValue(vd);
}
}
}
}
// Write Group stats
long observationDuration = Time.getCurrentTime()
- timestampLastEvent;
if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime()
- timeEnableDao;
}
MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats);
group, time, stats, observationDuration, false);
}
timestampLastEvent = Time.getCurrentTime();
} else {
for (SimHost host : hosts) {
MetricValue mv = metric.getPerHostMetric(host.getId());
......
......@@ -85,7 +85,9 @@ public class DefaultMonitor implements MonitorComponent, EventHandler,
@Override
public <A extends Analyzer> void registerAnalyzer(A analyzer) {
analyzers.add(analyzer);
if (!analyzers.contains(analyzer)) {
analyzers.add(analyzer);
}
}
@Override
......
......@@ -22,6 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement.local;
import java.util.HashMap;
import java.util.Locale;
import java.util.UUID;
import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
......@@ -39,6 +40,7 @@ import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.Left;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
......@@ -58,12 +60,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private String graphFolderFiles;
private String movementType; //car, bike or foot
private String defaultMovement;
private String navigationalType; //fastest,
private String navigationalType; //fastest,
private double latLeft; //Values from -90 to 90; always smaller than latRight
private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180
private boolean uniqueFolders;
/**
* Tolerance in meters (if the node reached a waypoint up to "tolerance"
* meters, it will select the next waypoint in the path.
......@@ -83,7 +86,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
hopper = new GraphHopper().forServer();
hopper.setOSMFile(osmFileLocation);
// where to store graphhopper files?
hopper.setGraphHopperLocation(graphFolderFiles+"/"+osmFileLocation.hashCode()+movementType);
if (uniqueFolders) {
Monitor.log(RealWorldStreetsMovement.class, Level.WARN,
"Using per-simulation unique folders for GraphHopper temporary data in %s. Remember to delete them to prevent your disk from filling up.",
graphFolderFiles);
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ UUID.randomUUID().toString());
} else {
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ osmFileLocation.hashCode() + movementType);
}
hopper.setEncodingManager(new EncodingManager(movementType));
hopper.importOrLoad();
init = true;
......@@ -203,4 +215,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public void setWaypointTolerance(double tolerance) {
this.tolerance = tolerance;
}
/**
* For large batch simulations, we need to prevent same-time access to
* garphhopper temp data. Therefore, this flag creates unique folders for
* each run (which, obviously, wastes a lot of space and comp-resources and
* should not be used in standalone, single-threaded demo mode...)
*
* @param uniqueFolders
*/
public void setCreateUniqueFolders(boolean uniqueFolders) {
this.uniqueFolders = uniqueFolders;
}
}
......@@ -141,7 +141,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
*/
public void initialize() {
if (!initialized) {
if (!initialized) {
VisualizationInjector.injectComponent(modelVisualisation);
if (mapVisualization != null) {
VisualizationInjector.injectComponent(mapVisualization);
......@@ -249,14 +249,18 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
*/
PositionVector attractionCenter = (PositionVector) newAssignment;
PositionVector destination = null;
/*
* Even if an AP does not have a radius, we slightly offset
*/
double apRadius = Math.max(newAssignment.getRadius(), 25.0);
int tries = 0;
do {
destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3);
rand.nextGaussian() * apRadius / 3,
rand.nextGaussian() * apRadius / 3);
destination.add(offset);
// Check constraints
if (destination.getX() < 0.0
......
......@@ -260,7 +260,11 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
* FIXME add @Override lateron, as soon as the API is updated globally.
*/
public void removeTransportMessageListener() {
assert listener != null;
// assert listener != null;
if (listener == null) {
Monitor.log(ModularTransLayer.class, Level.DEBUG, "Trying tor remove a non-existing transport message listener.");
return;
}
removeTransMsgListener(listener, localPort);
listener = null;
}
......
......@@ -151,13 +151,21 @@ public class MeasurementDAO extends DAO {
* 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
*/
public static void storeGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats) {
DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric, groupName);
MeasurementStatistic measurement = new MeasurementStatistic(time, stats, groupMetric);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
groupName);
MeasurementStatistic measurement = new MeasurementStatistic(time, stats,
groupMetric, observationDuration, describesWholeSimulation);
addToPersistQueue(measurement);
}
......
......@@ -58,19 +58,31 @@ public class MeasurementStatistic implements GroupMetricBound {
@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
*/
......@@ -82,28 +94,34 @@ public class MeasurementStatistic implements GroupMetricBound {
*/
@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 = "[skewness]")
private Double skewness;
@Column(nullable = true, name = "[kurtosis]")
private Double kurtosis;
......@@ -113,7 +131,7 @@ public class MeasurementStatistic implements GroupMetricBound {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "groupMetricId")
GroupMetric groupMetric;
/**
* Creates a {@link Measurement}-Object using the provided
* {@link DescriptiveStatistics} object.
......@@ -125,26 +143,34 @@ public class MeasurementStatistic implements GroupMetricBound {
* @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 MeasurementStatistic(long time, DescriptiveStatistics stats,
GroupMetric groupMetric) {
this(time, stats);
GroupMetric groupMetric, long observationDuration,
boolean describesWholeSimulation) {
this(time, stats, observationDuration, describesWholeSimulation);
this.groupMetric = groupMetric;
}
/**
* Internal - write statistics
*
* @param time
* @param stats
* @param observationDuration
* duration covered by this measurement in simulation units
*/
private MeasurementStatistic(long time, DescriptiveStatistics stats) {
private MeasurementStatistic(long time, DescriptiveStatistics stats,
long observationDuration, boolean describesWholeSimulation) {
super();
this.time = time;
/*
* TODO add stats
*/
this.observationDuration = observationDuration;
this.describesWholeSimulation = describesWholeSimulation;
this.values = checkForSpecialNumbers((double) stats.getN());
this.sum = checkForSpecialNumbers(stats.getSum());
this.sum = checkForSpecialNumbers(stats.getSum());
this.sum2 = checkForSpecialNumbers(stats.getSumsq());
this.min = checkForSpecialNumbers(stats.getMin());
this.max = checkForSpecialNumbers(stats.getMax());
......@@ -154,8 +180,11 @@ public class MeasurementStatistic implements GroupMetricBound {
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.skewness = checkForSpecialNumbers(stats.getSkewness());
this.kurtosis = checkForSpecialNumbers(stats.getKurtosis());
this.std = checkForSpecialNumbers(stats.getStandardDeviation());
}
/**
......@@ -178,12 +207,12 @@ public class MeasurementStatistic implements GroupMetricBound {
return value;
}
}
@Override
public GroupMetric getGroupMetric() {
return groupMetric;
}
@Override
public void setGroupMetric(GroupMetric metric) {
this.groupMetric = metric;
......
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