Commit 30347bd1 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Merge branch 'tm/sumo-integration' into 'master'

Integrate RouteSensor/SpeedSensor

See merge request !5
parents 3628bb28 153af762
/*
* 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.future_location;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/**
* Based on the Google Location Service (LocationClient) provided for the
* Android Platform. Provides access to the last known location (energy
* efficient) or QoS-Specifications for regular location updates.
*
* @see http
* ://developer.android.com/reference/com/google/android/gms/location/package
* -summary.html
* @author Bjoern Richerzhagen
*
*/
public interface FutureLocationSensor {
/**
* Retrieve the last known location
*
* @return
*/
Location getFutureLocation(Host pHost);
}
/*
* 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.route;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.SensorComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
/**
*
* @author Tobias Meuser
*
*/
public interface RouteActuator extends SensorComponent {
public boolean changeCurrentRoute(RoadNetworkRoute pRoute);
public RoadNetworkRoute findNewRoute();
public RoadNetworkRoute findNewRoute(List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination);
}
/*
* 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.route;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.SensorComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
/**
*
* @author Tobias Meuser
*
*/
public interface RouteSensor extends SensorComponent {
public RoadNetworkRoute getCurrentRoute();
}
/*
* 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.speed;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.SensorComponent;
/**
*
* @author Tobias Meuser
*
*/
public interface SpeedActuator extends SensorComponent {
void stopVehicle();
}
/*
* 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.speed;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.SensorComponent;
/**
*
* @author Tobias Meuser
*
*/
public interface SpeedSensor extends SensorComponent {
double getCurrentSpeed();
}
......@@ -30,6 +30,7 @@ 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.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AbstractAggregation.AggregationDouble;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
/**
* Type registry (e.g., our taxonomy). Dependencies between the flat types are
......@@ -58,6 +59,11 @@ public final class SiSTypes {
public static final SiSType<Location> PHY_LOCATION = create("PHY_LOCATION",
Location.class, null);
/**
* [m/s] Speed of an entity
*/
public static final SiSType<Double> SPEED = create("SPEED", Double.class, null);
/**
* PHY-Location - x (deprecated)
*/
......@@ -104,6 +110,16 @@ public final class SiSTypes {
public static final SiSType<Double> TEST_DOUBLE = create("TEST_DOUBLE",
Double.class, new AggregationDouble());
/**
* [Location] Future location of an entity for Vehicular Scenario by TM
*/
public static final SiSType<Location> FUTURE_PHY_LOCATION = create("FUTURE_PHY_LOCATION", Location.class, null);
/**
* [RoadNetworkRoute] Route of an entity for Vehicular Scenario by TM
*/
public static final SiSType<RoadNetworkRoute> ROUTE = create("ROUTE", RoadNetworkRoute.class, null);
/**
*
* @param name
......
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
......
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
......
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
......
/*
* 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.vehicular;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.speed.SpeedActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.speed.SpeedSensor;
public interface VehicleInformationComponent
extends HostComponent, RouteSensor, RouteActuator, SpeedSensor, SpeedActuator {
void setVehicleID(String vehicleID);
void resetVehicleID();
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
public interface EdgeController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
void init();
void setEdgeMaxSpeed(String pEdgeID, double pMaxSpeed);
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
public interface SimulationSetupExtractor {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
void init();
List<Position> getAllIntersections(boolean pCluster);
double getScenarioWidth();
double getScenarioHeight();
RoadNetwork getRoadNetwork();
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
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.exception.NoAdditionalRouteAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException;
public interface VehicleController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
Position getVehiclePosition(String pVehicleID);
Position getVehiclePosition(double pStep, String pVehicleID);
boolean nextStep();
List<String> getAllVehicles();
List<String> getAllVehicles(double pStep);
RoadNetworkRoute getCurrentRoute(String pVehicleID);
double getMaximumAvailablePrediction();
void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute);
RoadNetworkRoute findNewRoute(String pVehicle)
throws NoAdditionalRouteAvailableException;
RoadNetworkRoute findNewRoute(String pVehicle,
List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination)
throws NoAdditionalRouteAvailableException,
NoExitAvailableException;
double getStep();
double getStart();
void init();
double getVehicleSpeed(String pVehicleID);
void stopVehicle(String pVehicle);
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.util.HashMap;
import java.util.Map;
public class LocationUtils {
private static boolean _saveID = false;
private static Map<String, Long> _ids = new HashMap<>();
private static long _currentID = 0;
public static long calculateID(String pID) {
long numericalID = -1;
if (!_saveID) {
try {
String[] split = pID.split("_");
for (int i = 0; i < split.length; i++) {
numericalID *= 100000;
numericalID += Integer.valueOf(split[i]);
}
} catch (NumberFormatException e) {
_saveID = true;
}
}
if (_saveID) {
synchronized (_ids) {
if (!_ids.containsKey(pID)) {
_ids.put(pID, _currentID++);
}
numericalID = _ids.get(pID);
}
}
return numericalID;
}
public static double calculateDistance(Position start, Position end) {
return Math.sqrt(Math.pow(end.getY() - start.getY(), 2) + Math.pow(end.getX() - start.getX(), 2)) / 1000.0;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.util.Comparator;
public class NoDublicatePositionComparator implements Comparator<Position> {
@Override
public int compare(Position pPos1, Position pPos2) {
int compare = Double.compare(pPos1.getY(), pPos2.getY());
if (compare == 0) {
compare = Double.compare(pPos1.getX(), pPos2.getX());
if (compare == 0) {
compare = Double.compare(pPos1.getAlt(), pPos2.getAlt());
if (compare == 0) {
compare = Double.compare(pPos1.getHeading(), pPos2.getHeading());
}
}
}
return compare;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.io.Serializable;
public class Position implements Serializable, Comparable<Position> {
/**
*
*/
private static final long serialVersionUID = -5007352031660976321L;
public static final double EQUAL_DISTANCE = 0.0;
private static final double EQUAL_HEADING = 5;
private static final double EQUAL_ALT = 10;
private double _y;
private double _x;
private double _heading;
private double _alt;
private double _speed;
public Position(double pX, double pY, double pAlt, double pHeading, double pSpeed) {
_x = pX;
_y = pY;
_alt = pAlt;
_heading = pHeading;
_speed = pSpeed;
}
public Position(double pX, double pY, double pAlt, double pHeading) {
this(pX, pY, pAlt, pHeading, 0);
}
public double getY() {
return _y;
}
public void setY(double pY) {
_y = pY;
}
public double getX() {
return _x;
}
public void setX(double pX) {
_x = pX;
}
public double getHeading() {
return _heading;
}
public void setHeading(double pHeading) {
_heading = pHeading;
}
public double getAlt() {
return _alt;
}
public void setAlt(double pAlt) {
_alt = pAlt;
}
public double getSpeed() {
return _speed;
}
public void setSpeed(double pSpeed) {
_speed = pSpeed;
}
@Override
public String toString() {
return _y + "/" + _x + " (" + _heading + ")";
}
@Override
public int hashCode() {
return 0;
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof Position) {
Position start = (Position) pObj;
double difference = LocationUtils.calculateDistance(start, this);
if (difference <= EQUAL_DISTANCE) {
if (Math.abs(getAlt() - start.getAlt()) < EQUAL_ALT) {
if (Math.abs(getHeading() - start.getHeading()) < EQUAL_HEADING) {
return true;
}
}
}
}
return false;
}
@Override
public int compareTo(Position pPosition) {
if (Math.abs(_y - pPosition.getY()) < 1 / 1000.0
&& Math.abs(_x - pPosition.getX()) < 1 / 1000.0
&& Math.abs(_alt - pPosition.getAlt()) <= EQUAL_ALT
&& Math.abs(_heading - pPosition.getHeading()) <= EQUAL_HEADING) {
if (equals(pPosition)) {
return 0;
}
}
int compare = Double.compare(_y, pPosition.getY());
if (compare == 0) {
compare = Double.compare(_x, pPosition.getX());
if (compare == 0) {
compare = Double.compare(_alt, pPosition.getAlt());
if (compare == 0) {
compare = Double.compare(_heading, pPosition.getHeading());
}
}
}
return compare;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.util.ArrayList;
import java.util.List;
public class Route {
private List<Street> _waypoints;
public Route() {
_waypoints = new ArrayList<>();
}
public List<Street> getStreets() {
return _waypoints;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
public class Street {
private String _edgeID;
public Street(String pEdgeID) {
_edgeID = pEdgeID;
}
public String getEdgeID() {
return _edgeID;
}
}
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController;
public class RoadNetwork {
private Map<String, RoadNetworkEdge> _roadNetwork;
public RoadNetwork(SerializableRoadNetwork pRoadNetwork, EdgeController pEdgeController) {
_roadNetwork = new HashMap<>();
for (SerializableRoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
_roadNetwork.put(edge.getEdgeID(), new RoadNetworkEdge(edge, pEdgeController));
}
for (SerializableRoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
RoadNetworkEdge roadNetworkEdge = _roadNetwork.get(edge.getEdgeID());
for (String edgeID : edge.getAccessibleEdges()) {
roadNetworkEdge.addConnectedEdge(_roadNetwork.get(edgeID));
}
}
}
public RoadNetwork(Map<String, RoadNetworkEdge> pRoadNetwork) {
_roadNetwork = pRoadNetwork;
}
public List<RoadNetworkEdge> getAvailableEdges() {
return new ArrayList<>(_roadNetwork.values());
}
public RoadNetworkEdge getEdge(String pEdge) {
return _roadNetwork.get(pEdge);
}
}
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController;
public class RoadNetworkEdge {
private String _edgeID;
private double _angle;
private double _originalMaxSpeed = 0;
private List<RoadNetworkLane> _lanes = new ArrayList<>();
private List<RoadNetworkEdge> _accessibleEdges = new ArrayList<>();
private final EdgeController _edgeController;
public RoadNetworkEdge(SerializableRoadNetworkEdge pEdge, EdgeController pEdgeController) {
_edgeController = pEdgeController;
_edgeID = pEdge.getEdgeID();
_angle = pEdge.getAngle();
for (SerializableRoadNetworkLane lane : pEdge.getLanes()) {
_lanes.add(new RoadNetworkLane(lane));
}
_originalMaxSpeed = pEdge.getMaxSpeed();
}
public RoadNetworkEdge(String pEdgeID, double pAngle, EdgeController pEdgeController) {
_edgeController = pEdgeController;
_edgeID = pEdgeID;
_angle = pAngle;
}
public List<RoadNetworkLane> getLanes() {
return _lanes;
}
public String getEdgeID() {
return _edgeID;
}
public double getAngle() {
return _angle;
}
public double getOriginalMaxSpeed() {
return _originalMaxSpeed;
}
public int getLaneAmount() {
return _lanes.size();
}
public void addLane(RoadNetworkLane pLane) {
_lanes.add(pLane);
}
public void setOriginalMaxSpeed(double pMaxSpeed) {
if (pMaxSpeed > _originalMaxSpeed) {
_originalMaxSpeed = pMaxSpeed;
}
}
public void addConnectedEdge(RoadNetworkEdge pEdge) {
if (!_accessibleEdges.contains(pEdge)) {
_accessibleEdges.add(pEdge);
}
}
public List<RoadNetworkEdge> getAccessibleEdges() {
return Collections.unmodifiableList(_accessibleEdges);
}
public String getDescription() {
return "id: " + _edgeID + ", lanes: " + _lanes.size() + ", speed limit: " + _originalMaxSpeed;
}
@Override
public String toString() {
return _edgeID;
}
public boolean isInternal() {
return _edgeID.startsWith(":");
}
public void changeEdgeMaxSpeed(double pMaxSpeed) {
_edgeController.setEdgeMaxSpeed(getEdgeID(), pMaxSpeed);
}
}
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