Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
829d5123
Commit
829d5123
authored
Mar 13, 2017
by
Clemens Krug
Browse files
Working on routing problems
parent
15bca905
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/application/WorkloadItem.java
0 → 100644
View file @
829d5123
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
;
}
}
src/de/tud/kom/p2psim/api/application/WorkloadListener.java
View file @
829d5123
...
...
@@ -20,7 +20,6 @@
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.
...
...
@@ -36,13 +35,20 @@ import de.tud.kom.p2psim.api.common.SimHost;
*
* @author Christoph Muenker
* @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
*
* @return The application which is using the listener.
* Called when a {@link WorkloadItem} is ready.
* @param item The workload item.
*/
public
Application
getApplication
(
);
void
doWork
(
WorkloadItem
item
);
}
src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java
View file @
829d5123
...
...
@@ -20,6 +20,7 @@
package
de.tud.kom.p2psim.impl.topology.movement.local
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.UUID
;
...
...
@@ -28,6 +29,7 @@ import com.graphhopper.GHRequest;
import
com.graphhopper.GHResponse
;
import
com.graphhopper.GraphHopper
;
import
com.graphhopper.routing.util.EncodingManager
;
import
com.graphhopper.util.CmdArgs
;
import
com.graphhopper.util.PointList
;
import
com.graphhopper.util.shapes.GHPoint
;
import
com.graphhopper.util.shapes.GHPoint3D
;
...
...
@@ -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
*
* 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
* @version 1.0, 07.07.2015
...
...
@@ -85,6 +90,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private
void
init
()
{
hopper
=
new
GraphHopper
().
forServer
();
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?
if
(
uniqueFolders
)
{
Monitor
.
log
(
RealWorldStreetsMovement
.
class
,
Level
.
WARN
,
...
...
@@ -98,6 +110,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
}
hopper
.
setEncodingManager
(
new
EncodingManager
(
movementType
));
hopper
.
importOrLoad
();
init
=
true
;
}
...
...
@@ -115,8 +128,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
if
(!
init
)
init
();
PositionVector
newPosition
=
null
;
if
(
destination
.
distanceTo
(
comp
.
getRealPosition
())
>
getMovementSpeed
(
comp
))
{
if
(
destination
.
distanceTo
(
comp
.
getRealPosition
())
>
getMovementSpeed
(
comp
))
{
//if not set already for this node or new destination is different than last one
PointList
pointList
;
if
(!
movementPoints
.
containsKey
(
comp
)
||
destination
.
distanceTo
(
movementPoints
.
get
(
comp
).
getDestination
())
>
1.0
)
{
...
...
@@ -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
(
rsp
.
hasErrors
())
{
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
],
destinationPosition
[
0
],
destinationPosition
[
1
],
rsp
.
getErrors
());
"%f,%f)
,
destination (%f,%f)
and type %s
failed with error: %s."
,
comp
.
getHost
().
getId
().
valueAsString
(),
startPosition
[
0
],
startPosition
[
1
],
destinationPosition
[
0
],
destinationPosition
[
1
],
movementType
,
rsp
.
getErrors
());
pointList
=
new
PointList
();
pointList
.
add
(
new
GHPoint
(
destination
.
getLatitude
(),
destination
.
getLongitude
()
));
pointList
.
add
(
new
GHPoint
(
destination
Position
[
0
],
destinationPosition
[
1
]
));
movementPoints
.
put
(
comp
,
new
RealWorldMovementPoints
(
comp
.
getRealPosition
(),
destination
,
pointList
,
0
));
}
else
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMultiTypeMovementModel.java
View file @
829d5123
...
...
@@ -18,12 +18,22 @@ import java.util.HashSet;
* This class is meant to be used with the RealWorldStreetsMovement
* 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
* 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 target
s
will be
* 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:
* 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
* (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>
*
* The used {@link ITransitionStrategy} can be changed on runtime, too. However, the first
...
...
@@ -96,6 +106,7 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
}
else
{
if
(
transitions
.
containsKey
(
ms
))
transitions
.
get
(
ms
).
reachedAttractionPoint
(
ms
);
else
transition
.
reachedAttractionPoint
(
ms
);
System
.
err
.
println
(
"Client "
+
ms
.
getHost
().
getId
().
valueAsString
()
+
" cant move."
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment