Commit 863a0954 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added attacker scenario, decision-making, intersection-management and platform evaluation

parent 35db3e75
......@@ -2,17 +2,17 @@
* 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/>.
*
......@@ -38,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* basic filter for more complex statistical computations on the provided
* dataset. Common functions are included as inner classes in this abstract
* filter.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -92,23 +92,22 @@ public abstract class StatisticsFilter extends
if (values == null || values.isEmpty()) {
return null;
}
LinkedList<MetricValue> mvs = new LinkedList<MetricValue>(values);
return new StatisticsMetricValue(mvs);
return new StatisticsMetricValue(values);
}
/**
* Computes statistics such as svg, sum, std...
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
private class StatisticsMetricValue implements MetricValue<Double> {
private final List<MetricValue> inputs;
private final List<? extends MetricValue<?>> inputs;
private Double result = Double.NaN;
public StatisticsMetricValue(List<MetricValue> inputs) {
public StatisticsMetricValue(List<? extends MetricValue<?>> inputs) {
this.inputs = inputs;
}
......@@ -175,7 +174,7 @@ public abstract class StatisticsFilter extends
/**
* Function that has to compute sth. on the double-list. For convenience,
* some basic statistical values are already included.
*
*
* @param incoming
* @param count
* number of values
......@@ -191,7 +190,7 @@ public abstract class StatisticsFilter extends
/**
* Standard deviation
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -208,7 +207,7 @@ public abstract class StatisticsFilter extends
/**
* Average
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -231,7 +230,7 @@ public abstract class StatisticsFilter extends
/**
* Minimum
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -250,7 +249,7 @@ public abstract class StatisticsFilter extends
/**
* Maximum
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -271,7 +270,7 @@ public abstract class StatisticsFilter extends
* The Percentile, pass a value between 0 (exclusive) and 100 (inclusive).
* The resulting metric will be called "P20_incomingmetric" in the case of
* the 20th percentile.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......
......@@ -2,17 +2,17 @@
* 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/>.
*
......@@ -31,7 +31,7 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
/**
* Live Monitoring of all configured {@link Metric}s
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
*/
......@@ -55,7 +55,7 @@ public class MetricOutputLive extends AbstractOutput {
/**
* Just matching the {@link ProgressValue}-interface to the
* {@link TransitMetric} interface.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
*/
......
......@@ -32,6 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.core.SchedulerComponent;
import de.tudarmstadt.maki.simonstrator.api.component.core.SimulationRuntimeAnalyzer;
import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent;
/**
......@@ -93,6 +94,9 @@ SchedulerComponent, TimeComponent {
protected static final int TYPE_END = 3;
private SimulationRuntimeAnalyzer _simulationRuntimeAnalyzer;
private boolean _simulationRuntimeAnalyzerInit;
/**
* Constructs a new scheduler instance using a calendar queue. If desired,
* status events about the progress of the simulation will be plotted.
......@@ -267,8 +271,14 @@ SchedulerComponent, TimeComponent {
processedEventCounter++;
currentTime = realEvent.getSimulationTime();
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler);
if (realEvent.schedulerType == TYPE_END)
......@@ -298,8 +308,15 @@ SchedulerComponent, TimeComponent {
assert (realEvent.simTime == Long.MIN_VALUE);
realEvent.simTime = currentTime;
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler);
}
......@@ -403,8 +420,14 @@ SchedulerComponent, TimeComponent {
}
currentTime = realEvent.getSimulationTime();
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler);
if (realEvent.schedulerType == TYPE_END) {
......@@ -612,4 +635,16 @@ SchedulerComponent, TimeComponent {
}
}
private SimulationRuntimeAnalyzer getSimulationRuntimeAnalyzer() {
return _simulationRuntimeAnalyzer;
}
private boolean hasSimulationRuntimeAnalyzer() {
if (!_simulationRuntimeAnalyzerInit) {
_simulationRuntimeAnalyzer = Monitor.getOrNull(SimulationRuntimeAnalyzer.class);
_simulationRuntimeAnalyzerInit = true;
}
return _simulationRuntimeAnalyzer != null;
}
}
......@@ -142,12 +142,12 @@ public class RSUMovementModel implements MovementModel {
protected void initializeModel() {
if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller.init();
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true);
} else {
_controller = new XMLSimulationController(null, sumoIntersections);
_controller.init();
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true);
}
......
......@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
......@@ -44,6 +45,12 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
......@@ -80,8 +87,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private final String sumoTrace;
private String sumoIntersections;
private final long timestepConversion = Time.SECOND;
private boolean initialized = false;
private VehicleController _controller;
......@@ -175,7 +180,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
}
public void setStartTime(long pStartTime) {
_startTime = (int) (pStartTime / Time.SECOND);
_startTime = (int) (pStartTime / timeBetweenMoveOperations);
}
public void setReuseComponents(boolean pReuseComponents) {
......@@ -246,8 +251,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
_controller = simulationController;
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
simulationController.setStartTime(_startTime);
_controller.init();
_controller.nextStep();
_controller.init(timeBetweenMoveOperations);
_controller.nextStep(timeBetweenMoveOperations);
_extractor = simulationController;
} else {
......@@ -260,8 +265,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
_controller = simulationController;
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_controller.init();
_controller.nextStep();
_controller.init(timeBetweenMoveOperations);
_controller.nextStep(timeBetweenMoveOperations);
_extractor = simulationController;
}
......@@ -282,12 +287,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
* simulation performance due to less recalculations in the network
* models.
*/
long currentTime = Time.getCurrentTime() / timestepConversion;
long currentTime = Time.getCurrentTime() / timeBetweenMoveOperations;
System.out.println("Performing movement for step " + currentTime);
while (_controller.getStep() - _controller.getStart() < currentTime) {
if (!_controller.nextStep()) {
if (!_controller.nextStep(timeBetweenMoveOperations)) {
return;
}
}
......
......@@ -12,6 +12,7 @@ import javax.xml.parsers.SAXParserFactory;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
......@@ -49,7 +50,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
}
@Override
public void init() {
public void init(long timeBetweenMoveOperations) {
if (!_initalized) {
if (_vehicleDataPath != null) {
......@@ -57,7 +58,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
thread.start();
for (int i = 0; i < _futureInformation; i++) {
nextStep();
nextStep(Time.SECOND);
}
}
if (_roadSideUnitDataPath != null) {
......@@ -77,7 +78,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
}
@Override
public boolean nextStep() {
public boolean nextStep(long pTimeScale) {
_vehicleDataInformationHandler.readNext();
_step = _vehicleDataInformationHandler.getStep() - _futureInformation;
......@@ -171,6 +172,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return -1;
}
@Override
public double getVehicleLength(String pVehicleID) {
throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName());
}
@Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName());
......
......@@ -27,6 +27,7 @@ import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......@@ -87,12 +88,12 @@ public class RSUPlacement implements PlacementModel {
protected void initializeModel() {
if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller.init();
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true);
} else {
_controller = new XMLSimulationController(null, sumoIntersections);
_controller.init();
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true);
}
......
......@@ -24,9 +24,10 @@ import java.util.List;
import java.util.Set;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VehicleProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.VehicleProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
......@@ -55,6 +56,8 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
private String vehicleID;
private long _startingTime = -1;
public DefaultVehicleInformationComponent(Host host, VehicleController controller, SimulationSetupExtractor extractor, boolean pRouteKnown) {
this.host = host;
......@@ -92,31 +95,57 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
});
siSComponent.provide().nodeState(SiSTypes.HEADING, new SiSDataCallback<Double>() {
@Override
public Double getValue(INodeID pNodeID,
SiSProviderHandle pProviderHandle)
throws InformationNotAvailableException {
if (pNodeID == getHost().getId()) {
if (isValid()) {
return controller.getVehicleHeading(vehicleID);
}
}
return null;
}
@Override
public Set<INodeID> getObservedNodes() {
return INodeID.getSingleIDSet(getHost().getId());
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
siSComponent.provide().nodeState(SiSTypes.HEADING, new SiSDataCallback<Double>() {
@Override
public Double getValue(INodeID pNodeID,
SiSProviderHandle pProviderHandle)
throws InformationNotAvailableException {
if (pNodeID == getHost().getId()) {
if (isValid()) {
return controller.getVehicleHeading(vehicleID);
}
}
return null;
}
@Override
public Set<INodeID> getObservedNodes() {
return INodeID.getSingleIDSet(getHost().getId());
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
siSComponent.provide().nodeState(SiSTypes.VEHICLE_LENGTH, new SiSDataCallback<Double>() {
@Override
public Double getValue(INodeID pNodeID,
SiSProviderHandle pProviderHandle)
throws InformationNotAvailableException {
if (pNodeID == getHost().getId()) {
if (isValid()) {
return controller.getVehicleLength(vehicleID);
}
}
return null;
}
@Override
public Set<INodeID> getObservedNodes() {
return INodeID.getSingleIDSet(getHost().getId());
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
if (pRouteKnown) {
siSComponent.provide().nodeState(SiSTypes.ROUTE, new SiSDataCallback<RoadNetworkRoute>() {
......@@ -153,14 +182,21 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
@Override
public VehicleProperty getVehicleProperty() {
return new VehicleProperty(host.getId().value(), getLastLocation(),
getCurrentRoute().getStart(), getCurrentSpeed());
getCurrentRoute().getStart(), getCurrentSpeed(), getLength());
}
@Override
public void setVehicleID(String pVehicleID) {
vehicleID = pVehicleID;
_startingTime = Time.getCurrentTime();
}
@Override
public long getStartingTime() {
return _startingTime;
}
@Override
public void resetVehicleID() {
vehicleID = null;
......@@ -194,6 +230,10 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
return true;
}
public double getLength() {
return controller.getVehicleLength(vehicleID);
}
@Override
public RoadNetworkRoute findNewRoute() {
try {
......
......@@ -23,8 +23,8 @@ package de.tud.kom.p2psim.impl.vehicular.caching.decision;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.NumericVectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.NumericVectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
......
......@@ -25,7 +25,7 @@ import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
......
......@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
......
......@@ -30,9 +30,9 @@ import java.util.Map.Entry;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.impl.SimpleQoIBasedImpactFunction;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.jam.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralJamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy;
......
......@@ -29,10 +29,10 @@ import java.util.Map.Entry;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular.impl.VectoralQoIBasedImpactFunction;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.aggregation.AggregationInformation;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty;
import de.tudarmstadt.maki.simonstrator.api.component.transition.MechanismState;
import de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy;
......
/*
* 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.tud.kom.p2psim.impl.vehicular.decision;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleDecisionComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.VehicleRouteAnalyzer;
public abstract class AbstractVehicleDecisionComponent implements VehicleDecisionComponent, EventHandler {
private static final int EVENT_DECISION_MAKING_CYCLE = 0;
private VehicleInformationComponent _vehicleInformation;
private Host _host;
private CachingComponent _cache;
private boolean _routeAnalyzerInit = false;
private VehicleRouteAnalyzer _routeAnalyzer = null;
public AbstractVehicleDecisionComponent(Host pHost) {
_host = pHost;
}
@Override
public void initialize() {
try {
_cache = getHost().getComponent(CachingComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError(e);
}
}
@Override
public void shutdown() {
// Nothing to do
}
public VehicleInformationComponent getVehicleInformation() {
if (_vehicleInformation == null) {
try {
_vehicleInformation = getHost().getComponent(VehicleInformationComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError(e);
}
}
return _vehicleInformation;
}
@Override
public Host getHost() {
return _host;
}
@Override
public void startDecisionMaking() {
Event.scheduleImmediately(this, null, EVENT_DECISION_MAKING_CYCLE);
}
@Override
public final void eventOccurred(Object pContent, int pType) {
switch (pType) {
case EVENT_DECISION_MAKING_CYCLE:
RoadNetworkRoute currentRoute = getVehicleInformation().getCurrentRoute();
if (currentRoute != null && currentRoute.getRoute().size() > 2) {
boolean changed = false;
BenefitBasedRoute optimalRouteWithBenefit = getOptimalRoute(currentRoute,
_cache.getDecidedCacheEntries(RoadInformation.class));
if (optimalRouteWithBenefit != null) {
RoadNetworkRoute optimalRoute = optimalRouteWithBenefit.getRoute();
if (optimalRouteWithBenefit.getRoute().getRoute().size() > 1) {
if (currentRoute.getRoute().get(1) != optimalRoute.getRoute().get(1)) {
if (hasRouteAnalyzer()) {
getRouteAnalyzer().routeChanged(getHost().getId(), currentRoute, optimalRoute);
}
changed = true;
getVehicleInformation().changeCurrentRoute(optimalRouteWithBenefit.getRoute());
}
}
}
if (!changed) {
if (hasRouteAnalyzer()) {
getRouteAnalyzer().routeUnchanged(getHost().getId(), currentRoute);
}
}
}
Event.scheduleWithDelay(Time.SECOND, this, null, EVENT_DECISION_MAKING_CYCLE);
break;
default:
break;
}
}
public boolean hasRouteAnalyzer() {
if (!_routeAnalyzerInit) {
_routeAnalyzerInit = true;
try {
_routeAnalyzer = Monitor.get(VehicleRouteAnalyzer.class);
} catch (AnalyzerNotAvailableException e) {
}
}
return _routeAnalyzer != null;
}
public VehicleRouteAnalyzer getRouteAnalyzer() {
return _routeAnalyzer;
}
}
\ No newline at end of file
/*
* 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.vehicular.decision;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class DefaultVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
public DefaultVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid()) {
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return null;
}
}
/*
* 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.vehicular.decision;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTracker;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
public class DynamicInformationVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
private static Map<RoadNetworkEdge, CostGraph> _unknownCostGraphs = new HashMap<>();
private static Map<RoadProperty, Map<RoadNetworkEdge, CostGraph>> _knownCostGraphs = new HashMap<>();
public DynamicInformationVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null && pInvestigatedRoute.getRoute().size() > 1 && pInvestigatedRoute.getStart().getAccessibleEdges().size() > 1) {
if (knownInformation.size() > 1) {
for (RoadInformation roadInformation : knownInformation) {
System.out.println("Known information for road " + roadInformation.getEdge());
}
throw new AssertionError("Only one information currently supported!");
}
CostGraph usedCostGraph = null;
if (!_unknownCostGraphs.containsKey(pInvestigatedRoute.getDestination())) {
CostGraph costGraph = new CostGraph(pInvestigatedRoute.getDestination());
costGraph.createCostGraph();
_unknownCostGraphs.put(pInvestigatedRoute.getDestination(), costGraph);
}
if (knownInformation.size() > 0) {
if (!_knownCostGraphs.containsKey(knownInformation.get(0).getValue())) {
_knownCostGraphs.put(knownInformation.get(0).getValue(), new HashMap<>());
}
Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue());
if (!costGraphs.containsKey(pInvestigatedRoute.getDestination())) {
CostGraph costGraph = new CostGraph(pInvestigatedRoute.getDestination(), knownInformation.get(0), _unknownCostGraphs.get(pInvestigatedRoute.getDestination()));
costGraph.createCostGraph();
costGraphs.put(pInvestigatedRoute.getDestination(), costGraph);
}
}
if (knownInformation.size() > 0) {
Map<RoadNetworkEdge, CostGraph> costGraphs = _knownCostGraphs.get(knownInformation.get(0).getValue());
usedCostGraph = costGraphs.get(pInvestigatedRoute.getDestination());
} else {
usedCostGraph = _unknownCostGraphs.get(pInvestigatedRoute.getDestination());
}
double minCosts = Double.MAX_VALUE;
RoadNetworkRoute optimalRoute = null;
for (RoadNetworkEdge edge : pInvestigatedRoute.getStart().getAccessibleEdges()) {
if (usedCostGraph.getCosts(edge) < minCosts) {
RoadNetworkRoute roadNetworkRoute = usedCostGraph.getOptimalRoute(edge);
minCosts = usedCostGraph.getCosts(edge);
optimalRoute = roadNetworkRoute;
}
}
if (optimalRoute != null) {
optimalRoute.getRoute().add(0, pInvestigatedRoute.getStart());
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : optimalRoute.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, optimalRoute);
}
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
private class CostGraph {
private Map<RoadNetworkEdge, Double> _costGraph = new HashMap<>();
private Map<RoadNetworkEdge, RoadNetworkEdge> _nextEdgeGraph = new HashMap<>();
// For event active
private RoadInformation _information;
private CostGraph _costGraphWithoutEvent;
private RoadNetworkEdge _destination;
// If event inactive
public CostGraph(RoadNetworkEdge pDestination) {
_costGraph.put(pDestination, 0d);
_destination = pDestination;
}
// If event active
public CostGraph(RoadNetworkEdge pDestination, RoadInformation pInformation, CostGraph pCostGraphWithoutEvent) {
this(pDestination);
_information = pInformation;
_costGraphWithoutEvent = pCostGraphWithoutEvent;
}
public RoadNetworkRoute getOptimalRoute(RoadNetworkEdge pEdge) {
List<RoadNetworkEdge> edges = new ArrayList<>();
RoadNetworkEdge current = pEdge;
edges.add(current);
while (_nextEdgeGraph.containsKey(current)) {
RoadNetworkEdge next = _nextEdgeGraph.get(current);
edges.add(next);
current = next;
if (next.equals(_destination) || !_costGraph.containsKey(current) || !_costGraph.containsKey(next)
|| _costGraph.get(current) < _costGraph.get(next)) {
break;
}
}
if (edges.get(edges.size() - 1).equals(_destination)) {
return new RoadNetworkRoute(edges);
}
return null;
}
public void createCostGraph() {
createCostGraph(RoadNetwork.CURRENT_ROAD_NETWORK.getUsableEdges().size());
}
public void createCostGraph(int pMaxDepth) {
RoadProperty property = null;
if (_information != null) {
property = _information.getValue();
}
if (_information != null) {
VehiclePathTracker tracker = VehiclePathTrackerFactory.getVehiclePathTracker();
long duration = _information.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION);
double existProbability = 1 - 1 / (double) (duration / Time.SECOND);
for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
for (RoadNetworkEdge incomingEdge : incomingEdges) {
if (isCyclic(incomingEdge, roadNetworkEdge)) {
continue;
}
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double eventActiveCost = _costGraph.get(roadNetworkEdge);
double eventInactiveCost = _costGraphWithoutEvent.getCosts(roadNetworkEdge);
double stillExistProbability = Math.pow(existProbability,
tracker.getTravelTime(incomingEdge, roadNetworkEdge));
double totalCosts = edgeCost + eventInactiveCost * (1 - stillExistProbability)
+ eventActiveCost * stillExistProbability;
if (!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) {
_costGraph.put(incomingEdge, totalCosts);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
}
}
}
}
} else {
for (int i = 0; i < pMaxDepth; i++) {
List<RoadNetworkEdge> labeledEdges = new ArrayList<>(_costGraph.keySet());
for (RoadNetworkEdge roadNetworkEdge : labeledEdges) {
List<RoadNetworkEdge> incomingEdges = roadNetworkEdge.getIncomingEdges();
for (RoadNetworkEdge incomingEdge : incomingEdges) {
double edgeCost = incomingEdge.calculateEdgeCostIfKnown(property);
double totalCosts = _costGraph.get(roadNetworkEdge) + edgeCost;
if (!_costGraph.containsKey(incomingEdge) || totalCosts < _costGraph.get(incomingEdge)) {
_costGraph.put(incomingEdge, totalCosts);
_nextEdgeGraph.put(incomingEdge, roadNetworkEdge);
}
}
}
}
}
}
private boolean isCyclic(RoadNetworkEdge pIncomingEdge, RoadNetworkEdge pRoadNetworkEdge) {
RoadNetworkEdge current = pRoadNetworkEdge;
while (_nextEdgeGraph.containsKey(current)) {
if (pIncomingEdge.equals(current)) {
return true;
}
if (current == _destination) {
break;
}
current = _nextEdgeGraph.get(current);
}
return false;
}
public double getCosts(RoadNetworkEdge pEdge) {
if (_costGraph.containsKey(pEdge)) {
return _costGraph.get(pEdge);
} else {
return Double.MAX_VALUE;
}
}
}
}
/*
* 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.vehicular.decision;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
public class OptimalVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
public OptimalVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid()) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue();
if (!property.getValue().equals(property.getDefaultProperty().getValue())) {
if (roadInformation.getValue().getDuration() == -1
|| roadInformation.getValue().getDetectionDate()
+ roadInformation.getValue().getDuration() > Time.getCurrentTime()
+ getTimeToEvent(pInvestigatedRoute, roadInformation.getEdge())) {
if (!blocked.contains(roadInformation.getEdge())) {
blocked.add(roadInformation.getEdge());
}
}
}
}
}
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), blocked);
if (route != null) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route);
}
// if (pInvestigatedRoute.getStart().getEdgeID().equals("gneE8") && pInvestigatedRoute.getRoute().contains(RoadNetwork.CURRENT_ROAD_NETWORK.getEdge("event"))
// && RoadNetwork.CURRENT_ROAD_NETWORK.getEdge("event").isActive() && Time.getCurrentTime() > 13 * Time.SECOND) {
// System.out.println();
// }
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return null;
}
private long getTimeToEvent(RoadNetworkRoute pRoute, RoadNetworkEdge pEventEdge) {
long timeToEvent = 0;
if (pRoute.getRoute().indexOf(pEventEdge) > 0) {
for (int i = 1; i < pRoute.getRoute().size(); i++) {
if (!pRoute.getRoute().get(i).equals(pEventEdge)) {
timeToEvent += VehiclePathTrackerFactory.getVehiclePathTracker().getTravelTime(pEventEdge);
} else {
break;
}
}
}
return timeToEvent * Time.SECOND;
}
}
/*
* 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.vehicular.decision;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
public class StaticInformationVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
public StaticInformationVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid() && knownInformation != null) {
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue();
if (!property.getValue().equals(property.getDefaultProperty().getValue())) {
if (!blocked.contains(roadInformation.getEdge())) {
blocked.add(roadInformation.getEdge());
}
}
}
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), blocked);
if (route != null) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
for (RoadInformation roadInformation : knownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route);
}
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return null;
}
}
/*
* 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.vehicular.decision;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
public class VisionBasedVehicleDecisionComponent extends AbstractVehicleDecisionComponent {
public VisionBasedVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
List<RoadInformation> actualKnownInformation = new ArrayList<>();
if (getVehicleInformation().isValid() && knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
RoadProperty property = roadInformation.getValue();
if (!property.getValue().equals(property.getDefaultProperty().getValue())) {
if (pInvestigatedRoute.getStart().getAccessibleEdges().contains(roadInformation.getEdge())) {
actualKnownInformation.add(roadInformation);
}
}
}
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
for (RoadInformation roadInformation : actualKnownInformation) {
if (!blocked.contains(roadInformation.getEdge())) {
blocked.add(roadInformation.getEdge());
}
}
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), blocked);
if (route != null) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : actualKnownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : actualKnownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
}
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route);
}
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return null;
}
}
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