Commit a47ef473 authored by Clemens Krug's avatar Clemens Krug
Browse files

Implemented MILPv2 Assignment

and corresponding necessities.
parent 68223a77
...@@ -24,6 +24,7 @@ import com.graphhopper.GHRequest; ...@@ -24,6 +24,7 @@ import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse; import com.graphhopper.GHResponse;
import com.graphhopper.GraphHopper; import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.EncodingManager; import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.util.DistanceCalc2D;
import com.graphhopper.util.PointList; import com.graphhopper.util.PointList;
import com.graphhopper.util.shapes.GHPoint; import com.graphhopper.util.shapes.GHPoint;
import com.graphhopper.util.shapes.GHPoint3D; import com.graphhopper.util.shapes.GHPoint3D;
...@@ -38,9 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder; ...@@ -38,9 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import java.util.HashMap; import java.util.*;
import java.util.Locale;
import java.util.UUID;
/** /**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination * This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
...@@ -190,7 +189,6 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -190,7 +189,6 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
* @return The projected position in world-dimensions * @return The projected position in world-dimensions
*/ */
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) { private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
VisualizationTopologyView.VisualizationInjector.getWorldX();
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft); double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft);
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLower)/(latUpper - latLower); double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLower)/(latUpper - latLower);
x = Math.max(0, x); x = Math.max(0, x);
...@@ -199,6 +197,59 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -199,6 +197,59 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
y = Math.min(worldDimensions.getY(), y); y = Math.min(worldDimensions.getY(), y);
return new PositionVector(x, y); return new PositionVector(x, y);
} }
/**
* Returns a list of points representing the current route of the component. Points are
* in x / y values of the own world.
* @param ms the component
* @return list of movement points.
*/
public List<PositionVector> getMovementPoints(SimLocationActuator ms)
{
List<PositionVector> positions = new LinkedList<>();
PointList pointList = movementPoints.get(ms).getPointList();
pointList.forEach(p -> positions.add(new PositionVector(transformGPSWindowToOwnWorld(p.getLat(), p.getLon()))));
return positions;
}
/**
* Calculates the length of a route in meters.
* @param start Starting position in own world coordinates (x / y)
* @param destination Destination on own world coordinates (x / y)
* @return the length of the route in meters.
*/
public double calculateRouteLength(PositionVector start, PositionVector destination)
{
PointList pointList;
double[] startPosition = transformOwnWorldWindowToGPS(start.getX(), start.getY());
double[] destinationPosition = transformOwnWorldWindowToGPS(destination.getX(), destination.getY());
GHRequest req = new GHRequest(startPosition[0], startPosition[1], destinationPosition[0], destinationPosition[1]).
setWeighting(navigationalType).
setVehicle(movementType).
setLocale(Locale.GERMANY);
GHResponse rsp = hopper.route(req);
//If the requested point is not in the map data, return -1
if(rsp.hasErrors()) {
return -1;
}
else {
pointList = rsp.getBest().getPoints();
return pointList.calcDistance(new DistanceCalc2D());
}
}
/**
* Calculates the length of the current route of the SimLocationActuator.
* @param ms the component
* @return the length of the current route
*/
public double getCurrentRouteLength(SimLocationActuator ms)
{
return movementPoints.get(ms).getPointList().calcDistance(new DistanceCalc2D());
}
public void setOsmFileLocation(String osmFileLocation) { public void setOsmFileLocation(String osmFileLocation) {
this.osmFileLocation = osmFileLocation; this.osmFileLocation = osmFileLocation;
......
...@@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm; ...@@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldMovementPoints;
import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement; import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy; import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy;
import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Either;
...@@ -13,6 +14,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction ...@@ -13,6 +14,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
/** /**
* This class is meant to be used with the RealWorldStreetsMovement * This class is meant to be used with the RealWorldStreetsMovement
...@@ -187,6 +189,17 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel ...@@ -187,6 +189,17 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
Monitor.log(ModularMultiTypeMovementModel.class, Monitor.Level.DEBUG, String.format("Client %s changed his transition strategy from %s to %s", ms.getHost().getId().toString(), usedStrategy.getClass(), newStrategy.getClass())); Monitor.log(ModularMultiTypeMovementModel.class, Monitor.Level.DEBUG, String.format("Client %s changed his transition strategy from %s to %s", ms.getHost().getId().toString(), usedStrategy.getClass(), newStrategy.getClass()));
} }
/**
* Returns a list of points representing the current route of the component. Points are
* in x / y values of the own world.
* @param ms the component
* @return list of movement points.
*/
public List<PositionVector> getMovementPoints(SimLocationActuator ms)
{
return ((RealWorldStreetsMovement) localMovementStrategy).getMovementPoints(ms);
}
/** /**
* Sets the default {@link ITransitionStrategy} for the specified {@link SimLocationActuator}. * Sets the default {@link ITransitionStrategy} for the specified {@link SimLocationActuator}.
* @param ms The SimLocationActuator * @param ms The SimLocationActuator
......
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