Commit 3c79589c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added cost-based communication

parent 0f3113f7
/*
* 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.pubsub;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Attribute;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Topic;
public interface CostBasedPubSubComponent extends PubSubComponent {
public Subscription createSubscription(Topic topic, Filter filter, double costs);
public Notification createNotification(Topic topic,
List<Attribute<?>> attributes, double costs, byte[] payload);
}
/*
* 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.relevance;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.RelevanceCalculationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationConsumer.SiSConsumerHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
public abstract class AbstractRelevanceCalculationComponent implements RelevanceCalculationComponent {
private SiSComponent _sis;
private Host _host;
private List<SiSConsumerHandle> sisHandles = new ArrayList<>();
public AbstractRelevanceCalculationComponent(Host pHost) {
_host = pHost;
}
public abstract Map<SiSType<?>, SiSRequest> getRequiredInformation();
@Override
public Host getHost() {
return _host;
}
protected SiSComponent getSiS() {
if (_sis == null) {
try {
_sis = getHost().getComponent(SiSComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError(e);
}
}
return _sis;
}
@Override
public void initialize() {
Map<SiSType<?>, SiSRequest> metrics = getRequiredInformation();
for (Map.Entry<SiSType<?>, SiSRequest> metric : metrics.entrySet()) {
SiSConsumerHandle handle = getSiS().get().rawObservations(metric.getKey(), metric.getValue(), null);
sisHandles.add(handle);
}
}
}
......@@ -18,7 +18,7 @@
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance;
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
......
/*
* 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.relevance.vehicular;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
public interface RelevanceCalculationComponent extends HostComponent {
public double calculateRelevance(INodeID receivingNode, Notification pNotification);
}
......@@ -18,7 +18,7 @@
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance;
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.VehicularPointInformation;
......@@ -32,7 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
* @version 1.0.0
*
*/
public interface EventRelevanceCalculationComponent extends HostComponent {
public interface VehicularRelevanceCalculationComponent extends HostComponent {
/**
* This method calculates the relevance of an event for a vehicle, combining
* the temporal and the geographical relevance.
......
......@@ -18,18 +18,18 @@
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl;
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.ImpactFunction;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AggregatedInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.ImpactFunction;
public abstract class AbstractQoIBasedImpactFunction<T extends PointInformation> implements ImpactFunction<T> {
protected static final long SCALING = Time.SECOND;
......
......@@ -18,7 +18,7 @@
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl;
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.impl;
import java.util.List;
......
......@@ -18,7 +18,7 @@
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl;
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.impl;
import java.util.List;
......
......@@ -20,12 +20,16 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.LocationBasedEnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.bump.BumpProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.hazard.HazardProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
public class DefaultPropertyCostEstimator implements PropertyCostEstimator {
public class DefaultVehicularPropertyCostEstimator implements VehicularPropertyCostEstimator {
@Override
public double calculateCosts(Class<? extends RoadProperty> pProperty) {
......@@ -39,4 +43,16 @@ public class DefaultPropertyCostEstimator implements PropertyCostEstimator {
return 1;
}
@Override
public double calculateCosts(Notification pNotification) {
EnvironmentInformation<? extends LocationBasedEnvironmentProperty> environmentInformation = EnvironmentInformation
.createFromNotification(pNotification);
if (environmentInformation instanceof RoadInformation) {
return calculateCosts(((RoadInformation) environmentInformation).getValue());
}
throw new AssertionError("Cost calculation only valid for road information!");
}
}
......@@ -20,12 +20,8 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
public interface PropertyCostEstimator {
default double calculateCosts(RoadProperty pProperty) {
return calculateCosts(pProperty.getClass());
}
double calculateCosts(Class<? extends RoadProperty> pProperty);
double calculateCosts(Notification pNotification);
}
......@@ -21,7 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs;
public class PropertyCostEstimatorFactory {
private static DefaultPropertyCostEstimator _costEstimator = new DefaultPropertyCostEstimator();
private static DefaultVehicularPropertyCostEstimator _costEstimator = new DefaultVehicularPropertyCostEstimator();
public static PropertyCostEstimator getPropertyCostEstimator() {
return _costEstimator;
......
/*
* 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.sensor.environment.data.costs;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
public interface VehicularPropertyCostEstimator extends PropertyCostEstimator {
default double calculateCosts(RoadProperty pProperty) {
return calculateCosts(pProperty.getClass());
}
double calculateCosts(Class<? extends RoadProperty> pProperty);
}
......@@ -7,6 +7,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.pubsub.PubSubComponent;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.attribute.Topic;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyCostEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.PropertyCostEstimatorFactory;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.costs.VehicularPropertyCostEstimator;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.subscriptions.SubscriptionTopicType;
......@@ -45,7 +46,8 @@ public class CostBasedTopic implements ProcessedTopic, Comparable<CostBasedTopic
if (pInformation instanceof RoadInformation) {
RoadInformation roadInfo = (RoadInformation) pInformation;
PropertyCostEstimator costEstimator = PropertyCostEstimatorFactory.getPropertyCostEstimator();
double costsForMissingInformation = costEstimator.calculateCosts(roadInfo.getValue());
double costsForMissingInformation = ((VehicularPropertyCostEstimator) costEstimator)
.calculateCosts(roadInfo.getValue());
if (costsForMissingInformation >= _costs) {
return true;
......
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