|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--y.algo.ShortestPaths
Provides diverse algorithms and helper methods for solving the shortest path problem on weighted graphs.
Method Summary | |
static boolean |
acyclic(Graph graph,
Node s,
DataProvider cost,
NodeMap dist,
NodeMap pred)
Like ShortestPaths.acyclic(Graph, Node, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays. |
static boolean |
acyclic(Graph graph,
Node s,
double[] cost,
double[] dist)
This method solves the single-source shortest path problem for acyclic directed graphs. |
static boolean |
acyclic(Graph graph,
Node s,
double[] cost,
double[] dist,
Edge[] pred)
Like ShortestPaths.acyclic(Graph, Node, double[], double[]) but additionally this method
yields the path edges of each calculated shortest path. |
static boolean |
allPairs(Graph graph,
boolean directed,
double[] cost,
double[][] dist)
This method solves the all-pairs shortest path problem for graphs with arbitrary edge costs. |
static boolean |
bellmanFord(Graph graph,
Node s,
boolean directed,
DataProvider cost,
NodeMap dist,
NodeMap pred)
Like ShortestPaths.bellmanFord(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays. |
static boolean |
bellmanFord(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist)
This method solves the single-source shortest path problem for arbitrary graphs. |
static boolean |
bellmanFord(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist,
Edge[] pred)
Like ShortestPaths.bellmanFord(Graph, Node, boolean, double[], double[]) but additionally this method
yields the path edges of each calculated shortest path. |
static EdgeList |
constructEdgePath(Node s,
Node t,
DataProvider pred)
Like ShortestPaths.constructEdgePath(Node,Node,Edge[]) with the difference that
the path edges are given by a DataProvider. |
static EdgeList |
constructEdgePath(Node s,
Node t,
Edge[] pred)
Conveniance method that constructs an explicit edge path from the result yielded by one of the shortest paths methods defined in this class. |
static NodeList |
constructNodePath(Node s,
Node t,
DataProvider pred)
Like ShortestPaths.constructNodePath(Node,Node,Edge[]) with the difference that
the path edges are given by a DataProvider. |
static NodeList |
constructNodePath(Node s,
Node t,
Edge[] pred)
Conveniance method that constructs an explicit node path from the result yielded by one of the shortest paths methods defined in this class. |
static void |
dijkstra(Graph graph,
Node s,
boolean directed,
DataProvider cost,
NodeMap dist,
NodeMap pred)
Like ShortestPaths.dijkstra(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays. |
static void |
dijkstra(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist)
This method solves the single-source shortest path problem for arbitrary graphs. |
static void |
dijkstra(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist,
Edge[] pred)
Like ShortestPaths.dijkstra(Graph, Node, boolean, double[], double[]) but additionally this method
yields the path edges of each calculated shortest path. |
static void |
findShortestUniformPaths(Graph graph,
Node start,
Node end,
boolean directed,
EdgeMap pathMap)
Marks all edges that belong to a shortest path from start to end node.
|
static boolean |
singleSource(Graph graph,
Node s,
boolean directed,
DataProvider cost,
NodeMap dist,
NodeMap pred)
Like ShortestPaths.singleSource(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays. |
static boolean |
singleSource(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist)
This method solves the single-source shortest path problem for arbitrary graphs. |
static boolean |
singleSource(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist,
Edge[] pred)
Like ShortestPaths.singleSource(Graph, Node, boolean, double[], double[]) but additionally this method
yields the path edges of each calculated shortest path. |
static EdgeList |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
DataProvider cost)
Similar to ShortestPaths.singleSourceSingleSink(Graph,Node,Node,boolean,DataProvider,NodeMap)
but instead of returning the shortest distance between the source and sink
the actual shortest edge path between these nodes will be returned.
|
static double |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
DataProvider cost,
NodeMap pred)
Like ShortestPaths.singleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays. |
static EdgeList |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
double[] cost)
Similar to ShortestPaths.singleSourceSingleSink(Graph,Node,Node,boolean,double[],Edge[])
but instead of returning the shortest distance between the source and sink
the actual shortest edge path between these nodes will be returned.
|
static double |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
double[] cost,
Edge[] pred)
This method solves the single-source single-sink shortest path problem for arbitrary graphs. |
static void |
uniform(Graph graph,
Node s,
boolean directed,
double[] dist)
This method solves the single-source shortest path problem for arbitrary graphs where each edge has a uniform cost of 1.0. |
static void |
uniform(Graph graph,
Node s,
boolean directed,
double[] dist,
Edge[] pred)
Like ShortestPaths.uniform(Graph, Node, boolean, double[]) but additionally this method
yields the path edges of each calculated shortest path. |
static void |
uniform(Graph graph,
Node s,
boolean directed,
NodeMap dist,
NodeMap pred)
Like ShortestPaths.uniform(Graph, Node, boolean, double[], Edge[]) but uses NodeMaps instead of
arrays. |
static double[] |
uniformCost(Graph graph)
Conveniance method that returns an array containing uniform edge costs of 1.0 for each edge
of the given graph. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void uniform(Graph graph, Node s, boolean directed, double[] dist)
s
to all other nodes.
graph
- the graph being acted upons
- the start node for the shortest path searchdirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.dist
- return value that will hold the shortest distance from node s
to
all other nodes. The distance from s
to v
is
dist[v.index()]
. If there is no path from s
to v
then dist[v.index()] == Double.POSITIVE_INFINITY
.public static void uniform(Graph graph, Node s, boolean directed, double[] dist, Edge[] pred)
ShortestPaths.uniform(Graph, Node, boolean, double[])
but additionally this method
yields the path edges of each calculated shortest path.
pred
- return value that holds for each node t
the shortest
path edge pred[t.index()]
which is the last edge on the shortest
path from s
to t
. If t == s
or if there
is no shortest path from s
to t
then
pred[t.index()] == null
.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static void uniform(Graph graph, Node s, boolean directed, NodeMap dist, NodeMap pred)
ShortestPaths.uniform(Graph, Node, boolean, double[], Edge[])
but uses NodeMaps instead of
arrays.
dist
- return value. the map will provide a double value for each node.pred
- return value. the map will provide an Edge for each node.public static boolean acyclic(Graph graph, Node s, double[] cost, double[] dist)
s
to all other nodes.
graph
- the graph being acted upons
- the start node for the shortest path searchcost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.dist
- return value that will hold the shortest distance from node s
to
all other nodes. The distance from s
to v
is
dist[v.index()]
. If there is no path from s
to v
then dist[v.index()] == Double.POSITIVE_INFINITY
.
false if the input graph was not acyclic.
public static boolean acyclic(Graph graph, Node s, double[] cost, double[] dist, Edge[] pred)
ShortestPaths.acyclic(Graph, Node, double[], double[])
but additionally this method
yields the path edges of each calculated shortest path.
pred
- return value that holds for each node t
the shortest
path edge pred[t.index()]
which is the last edge on the shortest
path from s
to t
. If t == s
or if there
is no shortest path from s
to t
then
pred[t.index()] == null
.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static boolean acyclic(Graph graph, Node s, DataProvider cost, NodeMap dist, NodeMap pred)
ShortestPaths.acyclic(Graph, Node, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays.
cost
- must provide a double value for each edge.dist
- return value. the map will provide a double value for each node.pred
- return value. the map will provide an Edge for each node.public static void dijkstra(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
s
to all other nodes.
graph
- the graph being acted upons
- the start node for the shortest path searchdirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.cost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.dist
- return value that will hold the shortest distance from node s
to
all other nodes. The distance from s
to v
is
dist[v.index()]
. If there is no path from s
to v
then dist[v.index()] == Double.POSITIVE_INFINITY
.public static void dijkstra(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
ShortestPaths.dijkstra(Graph, Node, boolean, double[], double[])
but additionally this method
yields the path edges of each calculated shortest path.
pred
- return value that holds for each node t
the shortest
path edge pred[t.index()]
which is the last edge on the shortest
path from s
to t
. If t == s
or if there
is no shortest path from s
to t
then
pred[t.index()] == null
.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static void dijkstra(Graph graph, Node s, boolean directed, DataProvider cost, NodeMap dist, NodeMap pred)
ShortestPaths.dijkstra(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays.
cost
- must provide a double value for each edge.dist
- return value. the map will provide a double value for each node.pred
- return value. the map will provide an Edge for each node.public static double singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, double[] cost, Edge[] pred)
s
to node t
.
It also returns information to construct the actual path between these to nodes.
graph
- the graph being acted upons
- the source node for the shortest path searcht
- the sink node for the shortest path searchdirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.cost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.pred
- return value that holds for each node v
on the
the shortest the path from s
to t
an edge
pred[v.index()]
which is the last edge on
the shortest path from s
to v
. If v == s
or if there
is no shortest path from s
to v
then
pred[v.index()] == null
.
s
and t
if a path between these two
nodes exist and Double.POSITIVE_INFINITY
otherwise.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static EdgeList singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, double[] cost)
ShortestPaths.singleSourceSingleSink(Graph,Node,Node,boolean,double[],Edge[])
but instead of returning the shortest distance between the source and sink
the actual shortest edge path between these nodes will be returned.
If the returned path is empty then there is no path between the nodes.
public static EdgeList singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, DataProvider cost)
ShortestPaths.singleSourceSingleSink(Graph,Node,Node,boolean,DataProvider,NodeMap)
but instead of returning the shortest distance between the source and sink
the actual shortest edge path between these nodes will be returned.
If the returned path is empty then there is no path between the nodes.
public static double singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, DataProvider cost, NodeMap pred)
ShortestPaths.singleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays.
cost
- must provide a double value for each edge.pred
- return value. the map will provide an Edge for each node.public static boolean bellmanFord(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
s
to all other nodes.
If, on the other hand, the given graph contains negative-cost cycles this method will yield
no reasonable result which will be indicated by the return value false
.
graph
- the graph being acted upons
- the start node for the shortest path searchdirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.cost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.dist
- return value that will hold the shortest distance from node s
to
all other nodes. The distance from s
to v
is
dist[v.index()]
. If there is no path from s
to v
then dist[v.index()] == Double.POSITIVE_INFINITY
.
false
if this weighted graph contains a negative cost cycle,
true
otherwise.public static boolean bellmanFord(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
ShortestPaths.bellmanFord(Graph, Node, boolean, double[], double[])
but additionally this method
yields the path edges of each calculated shortest path.
pred
- return value that holds for each node t
the shortest
path edge pred[t.index()]
which is the last edge on the shortest
path from s
to t
. If t == s
or if there
is no shortest path from s
to t
then
pred[t.index()] == null
.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static boolean bellmanFord(Graph graph, Node s, boolean directed, DataProvider cost, NodeMap dist, NodeMap pred)
ShortestPaths.bellmanFord(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays.
cost
- must provide a double value for each edge.dist
- return value. the map will provide a double value for each node.pred
- return value. the map will provide an Edge for each node.public static boolean singleSource(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
graph
- the graph being acted upons
- the start node for the shortest path searchdirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.cost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.dist
- return value that will hold the shortest distance from node s
to
all other nodes. The distance from s
to v
is
dist[v.index()]
. If there is no path from s
to v
then dist[v.index()] == Double.POSITIVE_INFINITY
.
false
if this weighted graph contains a negative cost cycle,
true
otherwise.public static boolean singleSource(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
ShortestPaths.singleSource(Graph, Node, boolean, double[], double[])
but additionally this method
yields the path edges of each calculated shortest path.
pred
- return value that holds for each node t
the shortest
path edge pred[t.index()]
which is the last edge on the shortest
path from s
to t
. If t == s
or if there
is no shortest path from s
to t
then
pred[t.index()] == null
.ShortestPaths.constructNodePath(Node, Node, Edge[])
,
ShortestPaths.constructEdgePath(Node, Node, Edge[])
public static boolean singleSource(Graph graph, Node s, boolean directed, DataProvider cost, NodeMap dist, NodeMap pred)
ShortestPaths.singleSource(Graph, Node, boolean, double[], double[], Edge[])
but uses NodeMaps and DataProviders instead of arrays.
cost
- must provide a double value for each edge.dist
- return value. the map will provide a double value for each node.pred
- return value. the map will provide an Edge for each node.public static boolean allPairs(Graph graph, boolean directed, double[] cost, double[][] dist)
false
is
returned and the values returned in dist
are left unspecified.
graph
- the graph being acted upondirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.cost
- holds the costs for traversing each edge. Edge e
has cost cost[e.index()]
.dist
- return value that will hold the shortest path distances from all pairs of
nodes s
and t
in the graph.
The distance from s
to t
is
dist[s.index()][t.index()]
. If there is no path from s
to t
then dist[s.index()][t.index()] == Double.POSITIVE_INFINITY
.
public static void findShortestUniformPaths(Graph graph, Node start, Node end, boolean directed, EdgeMap pathMap)
start
to end
node.
This method assumes that each edge of the input graph has a cost of 1.0.
graph
- the input graphstart
- the start nodeend
- the end nodedirected
- whether or not to consider the graph as directed. If the graph is
to be considered undirected then each edge can be traversed in both directions and
the returned shortest paths can thus be undirected.pathMap
- the result. For each edge a boolean value will indicate whether or not
it belongs to a shortest path connecting the two nodes.public static double[] uniformCost(Graph graph)
1.0
for each edge
of the given graph.
cost[]
that contains uniform
edge costs of 1.0 for each edge e: cost[e.index()] == 1.0
.public static NodeList constructNodePath(Node s, Node t, Edge[] pred)
s
- the start node of the shortest path. This must be the
same start node that was specified when pred
was calculated.t
- the end node of the pathpred
- the shortest path edge result array returned by one of the
shortest path edge methods defined in this class.
s to t
in the correct order. If there
is no path from s
to t
then an empty
list is returned.
public static NodeList constructNodePath(Node s, Node t, DataProvider pred)
ShortestPaths.constructNodePath(Node,Node,Edge[])
with the difference that
the path edges are given by a DataProvider.
pred
- the shortest path edge result DataProvider returned by one of the
shortest path edge methods defined in this class.public static EdgeList constructEdgePath(Node s, Node t, Edge[] pred)
s
- the start node of the shortest path. This must be the
same start node that was specified when pred
was calculated.t
- the end node of the pathpred
- the shortest path edge result array returned by one of the
shortest path edge methods defined in this class.
s to t
in the correct order. If there
is no path from s
to t
then an empty
list is returned.
public static EdgeList constructEdgePath(Node s, Node t, DataProvider pred)
ShortestPaths.constructEdgePath(Node,Node,Edge[])
with the difference that
the path edges are given by a DataProvider.
pred
- the shortest path edge result DataProvider returned by one of the
shortest path edge methods defined in this class.
|
© Copyright 2000-2003, yWorks GmbH. All rights reserved. 2003 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |