Commit 9ebce6c2 authored by Nils Richerzhagen's avatar Nils Richerzhagen
Browse files

SiS AggregationFunctions for each type class in own class. Added

AggregationFunction Graph to SiS NEIGBORS_WIFI and NEIGHBORS_WIFI_LOCAL
parent 1fcd0915
...@@ -29,7 +29,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph; ...@@ -29,7 +29,8 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode; import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName; import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AbstractAggregation.AggregationDouble; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AggregationDouble;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AggregationGraph;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
/** /**
...@@ -79,13 +80,14 @@ public final class SiSTypes { ...@@ -79,13 +80,14 @@ public final class SiSTypes {
* local view of a single node. * local view of a single node.
*/ */
public static final SiSType<Graph> NEIGHBORS_WIFI = create( public static final SiSType<Graph> NEIGHBORS_WIFI = create(
"NEIGHBORS_WIFI", Graph.class, null); "NEIGHBORS_WIFI", Graph.class, new AggregationGraph());
/** /**
* {@link Graph} containing all 1-hop neighbors of a node on the WiFi * {@link Graph} containing all 1-hop neighbors of a node on the WiFi
* interface as {@link INode}. * interface as {@link INode}.
*/ */
public static final SiSType<Graph> NEIGHBORS_WIFI_LOCAL = create("NEIGHBORS_WIFI_LOCAL", Graph.class, null); public static final SiSType<Graph> NEIGHBORS_WIFI_LOCAL = create("NEIGHBORS_WIFI_LOCAL", Graph.class,
new AggregationGraph());
/** /**
* Energy (percentage) as double from 0 to 100 * Energy (percentage) as double from 0 to 100
......
...@@ -80,63 +80,4 @@ public class AbstractAggregation<T> implements SiSTypeAggregation<T> { ...@@ -80,63 +80,4 @@ public class AbstractAggregation<T> implements SiSTypeAggregation<T> {
throw new AggregationNotPossibleException(); throw new AggregationNotPossibleException();
} }
public static class AggregationDouble extends AbstractAggregation<Double> {
@Override
protected Double sum(Collection<Double> data)
throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = 0;
for (double val : data) {
result += val;
}
return result;
}
@Override
protected Double min(Collection<Double> data)
throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = Double.MAX_VALUE;
for (double val : data) {
result = Math.min(val, result);
}
return result;
}
@Override
protected Double max(Collection<Double> data)
throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = Double.MIN_VALUE;
for (double val : data) {
result = Math.max(val, result);
}
return result;
}
@Override
protected Double avg(Collection<Double> data)
throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
return sum(data) / count(data);
}
@Override
protected Double count(Collection<Double> data)
throws AggregationNotPossibleException {
if (data == null) {
return Double.NaN;
}
return (double) data.size();
}
}
} }
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation;
import java.util.Collection;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.AggregationNotPossibleException;
/**
* Aggregations for {@link Double}.
*
* @author Nils Richerzhagen
*
*/
public class AggregationDouble extends AbstractAggregation<Double>{
@Override
protected Double sum(Collection<Double> data) throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = 0;
for (double val : data) {
result += val;
}
return result;
}
@Override
protected Double min(Collection<Double> data) throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = Double.MAX_VALUE;
for (double val : data) {
result = Math.min(val, result);
}
return result;
}
@Override
protected Double max(Collection<Double> data) throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
double result = Double.MIN_VALUE;
for (double val : data) {
result = Math.max(val, result);
}
return result;
}
@Override
protected Double avg(Collection<Double> data) throws AggregationNotPossibleException {
if (data == null || data.isEmpty()) {
return Double.NaN;
}
return sum(data) / count(data);
}
@Override
protected Double count(Collection<Double> data) throws AggregationNotPossibleException {
if (data == null) {
return Double.NaN;
}
return (double) data.size();
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation;
import java.util.Collection;
import de.tudarmstadt.maki.simonstrator.api.common.graph.BasicGraph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationConsumer.AggregationFunction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.AggregationNotPossibleException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
/**
* {@link AggregationFunction} for {@link Graph} in {@link SiSTypes}.
*
* Using Set Theory (https://en.wikipedia.org/wiki/Set_theory)
*
* @author Nils Richerzhagen
*
*/
public class AggregationGraph extends AbstractAggregation<Graph> {
/**
* Complete merge - full merge of edges and full merge of nodes.
*/
@Override
protected Graph sum(Collection<Graph> data) throws AggregationNotPossibleException {
assert data.size() > 0;
if (data.size() == 1) {
return data.iterator().next();
}
Graph aggregatedGraph = new BasicGraph();
for (Graph graph : data) {
aggregatedGraph.mergeGraph(graph);
}
return aggregatedGraph;
}
/**
* Only what is in all structures. <b>Intersection</b>. TODO!
*/
@Override
protected Graph min(Collection<Graph> data) throws AggregationNotPossibleException {
return super.min(data);
}
/**
* Same as SUM
*/
@Override
protected Graph max(Collection<Graph> data) throws AggregationNotPossibleException {
return sum(data);
}
/**
* Same as SUM
*/
@Override
protected Graph avg(Collection<Graph> data) throws AggregationNotPossibleException {
return sum(data);
}
@Override
protected Graph count(Collection<Graph> data) throws AggregationNotPossibleException {
// Currently not supported
return super.count(data);
}
}
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