|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pathfinding.alg.floydwarshall.FloydWarshall<NODE>
public class FloydWarshall<NODE>
Floyd-Warshall algorithm for precomputing all-possible paths within the IPFKnownMap
.
It precomputes all the paths inside the environment using Floyd-Warshall algorithm (time: O(n^3)) in the form of matrix.
Use isReachable(Object, Object)
, getPathCost(Object, Object)
and getPath(Object, Object)
to obtain information about computed paths.
the info about the path.
getPath(Object, Object)
is caching retrieved paths using SoftReference
s.
If needed you may call compute()
to recompute paths, this call is needed if you set new map / agent view
using setMap(IPFKnownMap)
or FloydWarshall#setMapView(IPFMapView)
.
Based upon the implementation from Martin Krulis with his kind consent, thank you! Even though it was heavily recreated by now ;-)
NOTE: requires O(map.nodes.size^2) of memory! So be careful.
NOTE: you should read javadocs for IPFMap
, IPFKnownMap
and IPFMapView
to understand how you can separate
your map representation from various agent "views on the map" (i.e., how to provide customized path finding
for different agents, e.g., fish vs. human)
Nested Class Summary | |
---|---|
static class |
FloydWarshall.PathMatrixNode<N>
Class describing cell inside the FloydWarshall matrix holding additional informations relating to the path between two nodes. |
Constructor Summary | |
---|---|
FloydWarshall(IPFKnownMap<NODE> map)
FloydWarshall configured with "map" with no agent-specific view on the map, IPFMapView.DefaultView is used. |
|
FloydWarshall(IPFKnownMap<NODE> map,
IPFKnownMapView<NODE> view)
FloydWarshall configured with "map" and agent-specific view on the map, if "view" is null, IPFMapView.DefaultView is going to be used. |
|
FloydWarshall(IPFKnownMap<NODE> map,
IPFKnownMapView<NODE> view,
Logger log)
FloydWarshall configured with "map" and agent-specific view on the map, if "view" is null, IPFMapView.DefaultView is going to be used. |
|
FloydWarshall(IPFKnownMap<NODE> map,
Logger log)
FloydWarshall configured with "map" with no agent-specific view on the map, IPFMapView.DefaultView is used. |
Method Summary | |
---|---|
void |
cacheAllPaths()
|
void |
compute()
Force FloydWarshall to refresh its path matrix, useful if you modify the map or view using setMap(IPFKnownMap)
or setMapView(IPFKnownMapView) . |
long |
getAproxMemory()
Returns approximation of memory consumption of this object in bytes for 32-bit JVM, might be as twice for 64-bit JVM! |
Logger |
getLog()
Returns logger used by this object. |
IPFKnownMap<NODE> |
getMap()
Map abstraction the FloydWarshall is working with. |
IPFKnownMapView<NODE> |
getMapView()
Returns agent-specific map view for the map. |
FloydWarshall.PathMatrixNode<NODE>[][] |
getMatrix()
Returns matrix of nodes as computed by FloydWarshall algorithm. |
Integer |
getNodeIndex(NODE node)
Returns index of the node inside getMatrix() . |
List<NODE> |
getPath(NODE from,
NODE to)
Returns path between navpoints 'from' -> 'to'. |
int |
getPathCost(NODE from,
NODE to)
Calculate's distance between two nav points (using pathfinding). |
FloydWarshall.PathMatrixNode<NODE> |
getPathMatrixNode(NODE nodeFrom,
NODE nodeTo)
Returns PathMatrixNode describing path from "nodeFrom" to "nodeTo". |
boolean |
isReachable(NODE from,
NODE to)
Whether node 'to' is reachable (path exists) from the node 'from'. |
void |
setLog(Logger log)
Sets logger used by this object. |
void |
setMap(IPFKnownMap<NODE> map)
Sets map abstraction into the FloydWarshall. |
void |
setMapView(IPFKnownMapView<NODE> mapView)
Sets agent-specific map view for the map. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FloydWarshall(IPFKnownMap<NODE> map)
IPFMapView.DefaultView
is used.
compute()
method is immediately called from within this constructor.
map
- public FloydWarshall(IPFKnownMap<NODE> map, IPFKnownMapView<NODE> view)
IPFMapView.DefaultView
is going to be used.
compute()
method is immediately called from within this constructor.
map
- view
- may be nullpublic FloydWarshall(IPFKnownMap<NODE> map, Logger log)
IPFMapView.DefaultView
is used.
compute()
method is immediately called from within this constructor.
map
- log
- may be nullpublic FloydWarshall(IPFKnownMap<NODE> map, IPFKnownMapView<NODE> view, Logger log)
IPFMapView.DefaultView
is going to be used.
compute()
method is immediately called from within this constructor.
map
- view
- may be nulllog
- may be nullMethod Detail |
---|
public Logger getLog()
public void setLog(Logger log)
log
- public IPFKnownMap<NODE> getMap()
public void setMap(IPFKnownMap<NODE> map)
map
- public IPFKnownMapView<NODE> getMapView()
public void setMapView(IPFKnownMapView<NODE> mapView)
mapView
- public void compute()
setMap(IPFKnownMap)
or setMapView(IPFKnownMapView)
.
Called automatically from constructors!
public void cacheAllPaths()
public long getAproxMemory()
public FloydWarshall.PathMatrixNode<NODE> getPathMatrixNode(NODE nodeFrom, NODE nodeTo)
PathMatrixNode
describing path from "nodeFrom" to "nodeTo".
nodeFrom
- nodeTo
-
public boolean isReachable(NODE from, NODE to)
from
- to
-
public int getPathCost(NODE from, NODE to)
Throws exception if object is disabled, see FloydWarshallMap#setEnabled(boolean)
. Note that the object
is enabled by default.
Integer.MAX_VALUE
if there's no path.public List<NODE> getPath(NODE from, NODE to)
Path is automatically cached using SoftReference
.
from
- to
-
public FloydWarshall.PathMatrixNode<NODE>[][] getMatrix()
public Integer getNodeIndex(NODE node)
getMatrix()
. Note that if node that is not inside the matrix is passed,
this will return null!
node
-
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |