Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
/*
* 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 de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.GlobalKnowledgeDijkstraAlgorithm;
public class OptimalVehicleDecisionComponent extends StaticInformationVehicleDecisionComponent {
public OptimalVehicleDecisionComponent(Host pHost) {
super(pHost);
}
@Override
protected DijkstraAlgorithm getRoutingAlgorithm() {
return new GlobalKnowledgeDijkstraAlgorithm();
}
/*
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation) {
if (getVehicleInformation().isValid()) {
DijkstraAlgorithm dijkstraAlgorithm = new GlobalKnowledgeDijkstraAlgorithm();
List<RoadInformation> relevant = 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 (!relevant.contains(roadInformation)) {
relevant.add(roadInformation);
}
}
}
}
}
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), Collections.emptyList(), relevant);
if (route != null) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (relevant != null) {
for (RoadInformation roadInformation : relevant) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (additionalCosts > (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / Time.SECOND) {
additionalCosts = (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / (double) Time.SECOND;
}
oldCosts += additionalCosts;
}
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
if (relevant != null) {
for (RoadInformation roadInformation : relevant) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
if (additionalCosts > (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / Time.SECOND) {
additionalCosts = (Long) roadInformation
.getAttribute(AvailableInformationAttributes.EXPECTED_DURATION) / (double) Time.SECOND;
}
newCosts += additionalCosts;
}
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route);
}
}
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 (long) (timeToEvent * Time.SECOND * 0.9);
}
*/
}
/*
* 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.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
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() && pInvestigatedRoute.getRoute().size() > 1) {
DijkstraAlgorithm dijkstraAlgorithm = getRoutingAlgorithm();
RoadNetworkRoute route = dijkstraAlgorithm.findRoute(RoadNetwork.CURRENT_ROAD_NETWORK, getVehicleInformation().getCurrentRoute().getStart(), getVehicleInformation().getCurrentRoute().getDestination(), Collections.emptyList(), Collections.emptyList(), knownInformation);
if (route != null) {
double oldCosts = 0;
for (RoadNetworkEdge edge : pInvestigatedRoute.getRoute()) {
oldCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
oldCosts += additionalCosts;
}
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
if (knownInformation != null) {
for (RoadInformation roadInformation : knownInformation) {
double additionalCosts = edge.calculateAdditionalCostIfKnown(roadInformation.getValue());
newCosts += additionalCosts;
}
}
}
if (oldCosts > newCosts) {
return new BenefitBasedRoute(oldCosts - newCosts, route);
}
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
protected DijkstraAlgorithm getRoutingAlgorithm() {
return new DijkstraAlgorithm();
}
}
/*
* 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.Environment;
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> pKnownInformation) {
return new BenefitBasedRoute(0, pInvestigatedRoute);
}
@Override
public BenefitBasedRoute getOptimalRoute(RoadNetworkRoute pInvestigatedRoute, List<RoadInformation> knownInformation, Environment pEnvironment) {
List<RoadProperty> actualKnownInformation = new ArrayList<>();
if (getVehicleInformation().isValid()) {
if (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.getValue());
}
}
}
}
actualKnownInformation.addAll(pEnvironment.getProperties(RoadProperty.class));
DijkstraAlgorithm dijkstraAlgorithm = new DijkstraAlgorithm();
List<RoadNetworkEdge> blocked = new ArrayList<>();
for (RoadProperty roadInformation : actualKnownInformation) {
if (!blocked.contains(roadInformation.getEdge()) && roadInformation.getEdge().isActive()) {
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 (RoadProperty roadInformation : actualKnownInformation) {
oldCosts += edge.calculateAdditionalCostIfKnown(roadInformation);
}
}
double newCosts = 0;
for (RoadNetworkEdge edge : route.getRoute()) {
newCosts += edge.calculateStandardEdgeCosts();
for (RoadProperty roadInformation : actualKnownInformation) {
newCosts += edge.calculateAdditionalCostIfKnown(roadInformation);
}
}
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