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
4173f2cc
Commit
4173f2cc
authored
Mar 24, 2020
by
Julian Zobel
Committed by
Julian Zobel
Mar 24, 2020
Browse files
Update of GraphHopper Routing API to allow the blockager of paths and areas.
(cherry picked from commit
40a16a77
)
parent
5e563801
Changes
2
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
4173f2cc
...
@@ -103,10 +103,22 @@
...
@@ -103,10 +103,22 @@
</repository>
</repository>
<!-- uk maven central, since the local central server is slow as hell -->
<!-- uk maven central, since the local central server is slow as hell -->
<!--
<repository>
<repository>
<id>uk.maven.org</id>
<id>uk.maven.org</id>
<url>http://uk.maven.org/maven2</url>
<url>http://uk.maven.org/maven2</url>
</repository>
</repository>
-->
<repository>
<id>
Google Maven Central
</id>
<url>
https://maven-central.storage.googleapis.com/repos/central/data/
</url>
<snapshots>
<updatePolicy>
always
</updatePolicy>
</snapshots>
<releases>
<updatePolicy>
always
</updatePolicy>
</releases>
</repository>
...
@@ -349,10 +361,11 @@
...
@@ -349,10 +361,11 @@
<artifactId>jung-samples</artifactId> <version>2.0.1</version> </dependency> -->
<artifactId>jung-samples</artifactId> <version>2.0.1</version> </dependency> -->
<!-- OSM-Data for movement models -->
<!-- OSM-Data for movement models -->
<!--
<dependency>
<dependency>
<groupId>com.graphhopper</groupId>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper</artifactId>
<artifactId>graphhopper</artifactId>
<version>
0.
7
.0
</version>
<version>0.
8
.0</version>
<exclusions>
<exclusions>
<exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<groupId>org.slf4j</groupId>
...
@@ -360,7 +373,19 @@
...
@@ -360,7 +373,19 @@
</exclusion>
</exclusion>
</exclusions>
</exclusions>
</dependency>
</dependency>
-->
<dependency>
<groupId>
com.graphhopper
</groupId>
<artifactId>
graphhopper-core
</artifactId>
<version>
0.13.0
</version>
</dependency>
<dependency>
<groupId>
com.graphhopper
</groupId>
<artifactId>
graphhopper-reader-osm
</artifactId>
<version>
0.13.0
</version>
</dependency>
<!-- Json (used for OSM-Movement-Model) -->
<!-- Json (used for OSM-Movement-Model) -->
<dependency>
<dependency>
<groupId>
org.json
</groupId>
<groupId>
org.json
</groupId>
...
...
src/de/tud/kom/p2psim/impl/topology/movement/local/RealWorldStreetsMovement.java
View file @
4173f2cc
...
@@ -32,15 +32,18 @@ import com.graphhopper.GHRequest;
...
@@ -32,15 +32,18 @@ import com.graphhopper.GHRequest;
import
com.graphhopper.GHResponse
;
import
com.graphhopper.GHResponse
;
import
com.graphhopper.GraphHopper
;
import
com.graphhopper.GraphHopper
;
import
com.graphhopper.PathWrapper
;
import
com.graphhopper.PathWrapper
;
import
com.graphhopper.reader.osm.GraphHopperOSM
;
import
com.graphhopper.routing.util.EdgeFilter
;
import
com.graphhopper.routing.util.EdgeFilter
;
import
com.graphhopper.routing.util.EncodingManager
;
import
com.graphhopper.routing.util.EncodingManager
;
import
com.graphhopper.routing.util.TraversalMode
;
import
com.graphhopper.routing.util.TraversalMode
;
import
com.graphhopper.routing.weighting.BlockAreaWeighting
;
import
com.graphhopper.storage.index.LocationIndex
;
import
com.graphhopper.storage.index.LocationIndex
;
import
com.graphhopper.storage.index.QueryResult
;
import
com.graphhopper.storage.index.QueryResult
;
import
com.graphhopper.util.DistanceCalc2D
;
import
com.graphhopper.util.DistanceCalc2D
;
import
com.graphhopper.util.EdgeIteratorState
;
import
com.graphhopper.util.EdgeIteratorState
;
import
com.graphhopper.util.Instruction
;
import
com.graphhopper.util.Instruction
;
import
com.graphhopper.util.InstructionList
;
import
com.graphhopper.util.InstructionList
;
import
com.graphhopper.util.Parameters.Routing
;
import
com.graphhopper.util.PointList
;
import
com.graphhopper.util.PointList
;
import
com.graphhopper.util.shapes.GHPoint
;
import
com.graphhopper.util.shapes.GHPoint
;
...
@@ -55,6 +58,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder;
...
@@ -55,6 +58,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
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
/**
* 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
...
@@ -81,6 +85,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -81,6 +85,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private
String
movementType
;
//car, bike or foot
private
String
movementType
;
//car, bike or foot
private
String
defaultMovement
;
private
String
defaultMovement
;
private
String
navigationalType
;
//fastest,
private
String
navigationalType
;
//fastest,
private
String
blockedAreas
;
// default null
private
static
double
latLower
;
//Values from -90 to 90; always smaller than latUpper
private
static
double
latLower
;
//Values from -90 to 90; always smaller than latUpper
private
static
double
latUpper
;
//Values from -90 to 90
private
static
double
latUpper
;
//Values from -90 to 90
private
static
double
lonLeft
;
//Values from -180 to 180; Always smaller than lonRight
private
static
double
lonLeft
;
//Values from -180 to 180; Always smaller than lonRight
...
@@ -93,6 +98,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -93,6 +98,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
*/
*/
private
double
tolerance
=
1
;
private
double
tolerance
=
1
;
@XMLConfigurableConstructor
({
"blockedAreas"
})
public
RealWorldStreetsMovement
(
String
blockedAreas
)
{
this
();
this
.
setBlockedAreas
(
blockedAreas
);
}
public
RealWorldStreetsMovement
()
{
public
RealWorldStreetsMovement
()
{
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
.
getWorldDimensions
();
...
@@ -100,13 +111,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -100,13 +111,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
latUpper
=
GPSCalculation
.
getLatUpper
();
latUpper
=
GPSCalculation
.
getLatUpper
();
lonLeft
=
GPSCalculation
.
getLonLeft
();
lonLeft
=
GPSCalculation
.
getLonLeft
();
lonRight
=
GPSCalculation
.
getLonRight
();
lonRight
=
GPSCalculation
.
getLonRight
();
}
}
private
void
init
()
{
private
void
init
()
{
hopper
=
new
GraphHopper
().
forServer
();
hopper
=
new
GraphHopper
OSM
().
forServer
();
hopper
.
set
OSM
File
(
osmFileLocation
);
hopper
.
set
DataReader
File
(
osmFileLocation
);
// 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
,
...
@@ -118,12 +128,27 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -118,12 +128,27 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
hopper
.
setGraphHopperLocation
(
graphFolderFiles
+
"/"
hopper
.
setGraphHopperLocation
(
graphFolderFiles
+
"/"
+
osmFileLocation
.
hashCode
()
+
movementType
);
+
osmFileLocation
.
hashCode
()
+
movementType
);
}
}
hopper
.
setEncodingManager
(
new
EncodingManager
(
movementType
));
hopper
.
setEncodingManager
(
EncodingManager
.
create
(
movementType
));
hopper
.
importOrLoad
();
// 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
())
{
hopper
.
setCHEnabled
(
false
);
}
// try to load a cached import. If the cached import was with a different CH_ENABLED setting then now specified, this will fail.
// in this case, clean cache and re-import.
try
{
hopper
.
importOrLoad
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"[RealWorldStreetMovement] GraphHopper graph file must be imported again!"
);
hopper
.
clean
();
hopper
.
importOrLoad
();
}
index
=
hopper
.
getLocationIndex
();
index
=
hopper
.
getLocationIndex
();
init
=
true
;
init
=
true
;
}
}
@Override
@Override
public
Either
<
PositionVector
,
Boolean
>
nextPosition
(
public
Either
<
PositionVector
,
Boolean
>
nextPosition
(
...
@@ -168,7 +193,15 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -168,7 +193,15 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
setWeighting
(
navigationalType
).
setWeighting
(
navigationalType
).
setVehicle
(
movementType
).
setVehicle
(
movementType
).
setLocale
(
Locale
.
GERMANY
);
setLocale
(
Locale
.
GERMANY
);
GHResponse
rsp
=
hopper
.
route
(
req
);
// blocks one or multiple given areas from being used by the routing
// https://github.com/graphhopper/graphhopper/blob/master/docs/web/api-doc.md#flexible
if
(
blockedAreas
!=
null
&&
!
blockedAreas
.
isEmpty
())
{
req
.
getHints
().
put
(
Routing
.
BLOCK_AREA
,
blockedAreas
);
}
GHResponse
rsp
=
hopper
.
route
(
req
);
//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 ("
+
...
@@ -223,8 +256,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -223,8 +256,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
RouteSegmentImpl
segment
=
null
;
RouteSegmentImpl
segment
=
null
;
PointList
points
=
instr
.
getPoints
();
PointList
points
=
instr
.
getPoints
();
String
name
=
instr
.
getName
();
String
name
=
instr
.
getName
();
if
(
name
.
isEmpty
())
{
if
(
name
.
isEmpty
())
{
name
=
Integer
.
toString
(
instr
.
getPoints
().
toGHPoint
(
0
).
hashCode
());
name
=
Integer
.
toString
(
instr
.
getPoints
().
get
(
0
).
hashCode
());
//name = Integer.toString(instr.getPoints().toGHPoint(0).hashCode()); @deprecated for old GraphHopper version
}
}
for
(
GHPoint
point
:
points
)
{
for
(
GHPoint
point
:
points
)
{
if
(
segment
==
null
)
{
if
(
segment
==
null
)
{
...
@@ -399,4 +433,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
...
@@ -399,4 +433,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public
void
setCreateUniqueFolders
(
boolean
uniqueFolders
)
{
public
void
setCreateUniqueFolders
(
boolean
uniqueFolders
)
{
this
.
uniqueFolders
=
uniqueFolders
;
this
.
uniqueFolders
=
uniqueFolders
;
}
}
public
void
setBlockedAreas
(
String
blockedAreas
)
{
if
(!
blockedAreas
.
isEmpty
())
{
this
.
blockedAreas
=
blockedAreas
;
}
}
}
}
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