Commit 829d5123 authored by Clemens Krug's avatar Clemens Krug
Browse files

Working on routing problems

parent 15bca905
package de.tud.kom.p2psim.api.application;
/**
* The workload items which should be generated by a {@link WorkloadGenerator}.
* More or less just a wrapper to pass a specific request to the {@link WorkloadListener}s.
*/
public class WorkloadItem<T>
{
private T content;
public WorkloadItem(T content)
{
this.content = content;
}
/**
* Returns the content of this workload item
* @return the content
*/
public T getContent()
{
return content;
}
}
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package de.tud.kom.p2psim.api.application; package de.tud.kom.p2psim.api.application;
import de.tud.kom.p2psim.api.common.SimHost;
/** /**
* This is the Listener for an application, to get the call to do something. * This is the Listener for an application, to get the call to do something.
...@@ -36,13 +35,20 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -36,13 +35,20 @@ import de.tud.kom.p2psim.api.common.SimHost;
* *
* @author Christoph Muenker * @author Christoph Muenker
* @version 1.0, 14.06.2013 * @version 1.0, 14.06.2013
*
*
*
* 12.03.2017 Clemens Krug:
* The getApplication method has been removed since it did not comply to a
* typical Observer/Listener pattern. Instead {@link #doWork(WorkloadItem)} was added
* and the {@link Application}s should now handle the workloads accordingly.
*/ */
public interface WorkloadListener { public interface WorkloadListener
{
/** /**
* Gets the Application, which uses this Listener * Called when a {@link WorkloadItem} is ready.
* * @param item The workload item.
* @return The application which is using the listener.
*/ */
public Application getApplication(); void doWork(WorkloadItem item);
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.topology.movement.local; package de.tud.kom.p2psim.impl.topology.movement.local;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
...@@ -28,6 +29,7 @@ import com.graphhopper.GHRequest; ...@@ -28,6 +29,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.CmdArgs;
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;
...@@ -44,6 +46,9 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; ...@@ -44,6 +46,9 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/** /**
* 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
*
* 13.03.2017 Clemens Krug: Fixed an bug. When the GraphHopper routing had errors the nodes would move to the
* top right corner and not, as intended, straight to their destination.
* *
* @author Martin Hellwig * @author Martin Hellwig
* @version 1.0, 07.07.2015 * @version 1.0, 07.07.2015
...@@ -85,6 +90,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -85,6 +90,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private void init() { private void init() {
hopper = new GraphHopper().forServer(); hopper = new GraphHopper().forServer();
hopper.setOSMFile(osmFileLocation); hopper.setOSMFile(osmFileLocation);
try {
hopper.init(CmdArgs.readFromConfig("config/resourceAllocation/movements/config.properties", "graphhopper.config"));
} catch (IOException e) {
e.printStackTrace();
}
// where to store graphhopper files? // where to store graphhopper files?
if (uniqueFolders) { if (uniqueFolders) {
Monitor.log(RealWorldStreetsMovement.class, Level.WARN, Monitor.log(RealWorldStreetsMovement.class, Level.WARN,
...@@ -98,6 +110,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -98,6 +110,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
} }
hopper.setEncodingManager(new EncodingManager(movementType)); hopper.setEncodingManager(new EncodingManager(movementType));
hopper.importOrLoad(); hopper.importOrLoad();
init = true; init = true;
} }
...@@ -115,8 +128,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -115,8 +128,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
if(!init) init(); if(!init) init();
PositionVector newPosition = null; PositionVector newPosition = null;
if (destination if (destination.distanceTo(comp.getRealPosition()) > getMovementSpeed(comp))
.distanceTo(comp.getRealPosition()) > getMovementSpeed(comp)) { {
//if not set already for this node or new destination is different than last one //if not set already for this node or new destination is different than last one
PointList pointList; PointList pointList;
if(!movementPoints.containsKey(comp) || destination.distanceTo(movementPoints.get(comp).getDestination()) > 1.0) { if(!movementPoints.containsKey(comp) || destination.distanceTo(movementPoints.get(comp).getDestination()) > 1.0) {
...@@ -130,11 +143,11 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -130,11 +143,11 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
//If the requested point is not in the map data, simple return the destination as next point //If the requested point is not in the map data, simple return the destination as next point
if(rsp.hasErrors()) { if(rsp.hasErrors()) {
Monitor.log(this.getClass(), Monitor.Level.ERROR, "Routing request for Host %s with starting point (" + Monitor.log(this.getClass(), Monitor.Level.ERROR, "Routing request for Host %s with starting point (" +
"%f,%f) and destination (%f,%f) failed with error: %s.", comp.getHost().getId().valueAsString(),startPosition[0], startPosition[1], "%f,%f), destination (%f,%f) and type %s failed with error: %s.", comp.getHost().getId().valueAsString(),startPosition[0], startPosition[1],
destinationPosition[0], destinationPosition[1], rsp.getErrors()); destinationPosition[0], destinationPosition[1], movementType, rsp.getErrors());
pointList = new PointList(); pointList = new PointList();
pointList.add(new GHPoint(destination.getLatitude(), destination.getLongitude())); pointList.add(new GHPoint(destinationPosition[0], destinationPosition[1]));
movementPoints.put(comp, new RealWorldMovementPoints(comp.getRealPosition(), destination, pointList, 0)); movementPoints.put(comp, new RealWorldMovementPoints(comp.getRealPosition(), destination, pointList, 0));
} }
else { else {
......
...@@ -18,12 +18,22 @@ import java.util.HashSet; ...@@ -18,12 +18,22 @@ import java.util.HashSet;
* This class is meant to be used with the RealWorldStreetsMovement * This class is meant to be used with the RealWorldStreetsMovement
* and allows changes of the movement type and the used {@link ITransitionStrategy} mid-simulation * and allows changes of the movement type and the used {@link ITransitionStrategy} mid-simulation
* on a per-host basis. It acts like the {@link ModularMovementModel}, but each of the {@link SimLocationActuator}s * on a per-host basis. It acts like the {@link ModularMovementModel}, but each of the {@link SimLocationActuator}s
* can have a different movement type and {@link ITransitionStrategy}. All routes and target will be * can have a different movement type and {@link ITransitionStrategy}. All routes and targets will be
* calculated accordingly. <BR><BR> * calculated accordingly. <BR><BR>
* *
* Originally the whole movement system within the simonstrator platform was not intended to be manipulable
* by an application since only overlays were implemented which in a real world would reside on handheld devices
* for example and should therefore not be able to manipulate the movement of the node/user.
* But demand changed and for some systems it is inevitable to be able to control the movement. Therefore
* this class was created to fill the gap and provide access to the movement from outside the internal system.
*
* USAGE: * USAGE:
* So, since the movement of a person in real life could not be controlled by anyone but the person itself,
* the access to this class is only provided from the simrunner project since it is responsible for the simulation
* of the "real-life" parts of the simonstrator platform. From within this project you have access to the
* {@link de.tud.kom.p2psim.impl.topology.DefaultTopologyComponent} from where you can access this movement model.
* If you want to use different movement types, all you have to do is * If you want to use different movement types, all you have to do is
* (besides selecting this model it in your config) call the {@link #setMovementType(SimLocationActuator, String)} * (besides selecting this model in your config) call the {@link #setMovementType(SimLocationActuator, String)}
* for each of your components.<BR> * for each of your components.<BR>
* *
* The used {@link ITransitionStrategy} can be changed on runtime, too. However, the first * The used {@link ITransitionStrategy} can be changed on runtime, too. However, the first
...@@ -96,6 +106,7 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel ...@@ -96,6 +106,7 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
} else { } else {
if(transitions.containsKey(ms)) transitions.get(ms).reachedAttractionPoint(ms); if(transitions.containsKey(ms)) transitions.get(ms).reachedAttractionPoint(ms);
else transition.reachedAttractionPoint(ms); else transition.reachedAttractionPoint(ms);
System.err.println("Client "+ ms.getHost().getId().valueAsString() +" cant move.");
} }
} }
......
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