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
8d14d16e
Commit
8d14d16e
authored
Apr 02, 2020
by
Julian Zobel
🦄
Browse files
Add probability to take an alternative route to a target location.
parent
6c9ef8af
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java
View file @
8d14d16e
...
...
@@ -54,11 +54,13 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModelViz
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.RouteSensorComponent
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.RandomAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.util.Either
;
import
de.tud.kom.p2psim.impl.util.Left
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
...
...
@@ -71,9 +73,20 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*
* @author Martin Hellwig
* @version 1.0, 07.07.2015
*
* - added a possibility to allow the usage of alternative routes
* - set the probability for this alternatives
* - allow a dynamic reload of graphhopper files when switching routing algorithms
* - allow to define blocked areas, that are not used for routing
*
* @author Julian Zobel
* @version 02.04.2020
*
*/
public
class
RealWorldStreetsMovement
extends
AbstractLocalMovementStrategy
{
private
Random
random
=
Randoms
.
getRandom
(
RealWorldStreetsMovement
.
class
);
private
static
PositionVector
worldDimensions
;
private
GraphHopper
hopper
;
private
LocationIndex
index
;
...
...
@@ -94,6 +107,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private
static
double
lonLeft
;
//Values from -180 to 180; Always smaller than lonRight
private
static
double
lonRight
;
//Values from -180 to 180
private
boolean
uniqueFolders
;
private
boolean
allowAlternativeRoutes
=
false
;
private
double
probabilityForAlternativeRoute
=
0.0
;
/**
* Tolerance in meters (if the node reached a waypoint up to "tolerance"
...
...
@@ -135,7 +151,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
// if we have blocked areas defined, the CH in Graphhopper needs to be disabled!
// this also requires a new import
if
(
blockedAreas
!=
null
&&
!
blockedAreas
.
isEmpty
())
{
if
(
(
blockedAreas
!=
null
&&
!
blockedAreas
.
isEmpty
())
||
allowAlternativeRoutes
)
{
hopper
.
setCHEnabled
(
false
);
}
...
...
@@ -202,8 +218,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
if
(
blockedAreas
!=
null
&&
!
blockedAreas
.
isEmpty
())
{
req
.
getHints
().
put
(
Routing
.
BLOCK_AREA
,
blockedAreas
);
}
if
(
allowAlternativeRoutes
)
{
req
.
setAlgorithm
(
Parameters
.
Algorithms
.
ALT_ROUTE
);
}
req
.
setAlgorithm
(
Parameters
.
Algorithms
.
ALT_ROUTE
);
GHResponse
rsp
=
hopper
.
route
(
req
);
...
...
@@ -222,18 +240,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
PointList
pointList
=
rsp
.
getBest
().
getPoints
();
if
(
rsp
.
hasAlternatives
())
{
// System.out.println(" >>");
// for (PathWrapper pw : rsp.getAll()) {
// System.out.println(pw.getDistance());
// ModularMovementModelViz.paths.add(pw.getPoints());
// }
// System.out.println(" ");
if
(
Math
.
random
()
<
0.01
)
{
// alternatives for routing are allowed for distances bigger than 50
if
(
allowAlternativeRoutes
&&
rsp
.
hasAlternatives
()
&&
rsp
.
getBest
().
getDistance
()
>
50
)
{
// alternative route is taken with a certain chance
if
(
random
.
nextDouble
()
<=
probabilityForAlternativeRoute
)
{
pointList
=
rsp
.
getAll
().
get
(
1
).
getPoints
();
}
}
}
//PointList pointList = rsp.getBest().getPoints();
...
...
@@ -459,6 +471,15 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public
void
setBlockedAreas
(
String
blockedAreas
)
{
if
(!
blockedAreas
.
isEmpty
())
{
this
.
blockedAreas
=
blockedAreas
;
}
}
}
public
void
setAllowAlternativeRoutes
(
boolean
allowAlternativeRoutes
)
{
this
.
allowAlternativeRoutes
=
allowAlternativeRoutes
;
}
public
void
setProbabilityForAlternativeRoute
(
double
p
)
{
this
.
probabilityForAlternativeRoute
=
p
;
}
}
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