public final class ShortestPaths extends Object
s
and a target node t
such that the sum of the edge costs is minimized.
k
shortest paths between a source
node s
and a target node t
such that the sum of the edge costs is minimized.
s
to all
other nodes such that the sum of the edge costs is minimized.
s
to a target node t
such that the sum of the edge costs is minimized.
Modifier and Type | Method and Description |
---|---|
static boolean |
acyclic(Graph graph,
Node s,
double[] cost,
double[] dist)
Solves the single-source shortest path problem for acyclic directed graphs.
|
static boolean |
acyclic(Graph graph,
Node s,
double[] cost,
double[] dist,
Edge[] pred)
Solves the single-source shortest path problem for acyclic directed graphs.
|
static boolean |
acyclic(Graph graph,
Node s,
IDataProvider cost,
INodeMap dist,
INodeMap pred)
Each edge is associated with an arbitrary double value that represents the cost of that edge.
|
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,
double[] cost,
double[] dist)
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)
Solves the single-source shortest path problem for arbitrary graphs.
|
static boolean |
bellmanFord(Graph graph,
Node s,
boolean directed,
IDataProvider cost,
INodeMap dist,
INodeMap pred)
Solves the single-source shortest path problem for arbitrary graphs.
|
static EdgeList |
constructEdgePath(Node s,
Node t,
Edge[] pred)
Convenience method that constructs an explicit
path of edges from the result returned by one of the
shortest paths methods defined in this class. |
static EdgeList |
constructEdgePath(Node s,
Node t,
IDataProvider pred)
Like
constructEdgePath(Node, Node, Edge[]) but the path edges are given by a IDataProvider . |
static NodeList |
constructNodePath(Node s,
Node t,
Edge[] pred)
Convenience method that constructs an explicit
path of nodes from the result returned by one of the
shortest paths methods defined in this class. |
static NodeList |
constructNodePath(Node s,
Node t,
IDataProvider pred)
Like
constructNodePath(Node, Node, Edge[]) but the path edges are given by a IDataProvider . |
static void |
dijkstra(Graph graph,
Node s,
boolean directed,
double[] cost,
double[] dist)
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)
Solves the single-source shortest path problem for arbitrary graphs.
|
static void |
dijkstra(Graph graph,
Node s,
boolean directed,
IDataProvider cost,
INodeMap dist,
INodeMap pred)
Solves the single-source shortest path problem for arbitrary graphs.
|
static void |
findShortestUniformPaths(Graph graph,
Node start,
IDataProvider targetMap,
boolean directed,
int maxLength,
EdgeList pathEdges,
NodeList pathNodes)
Finds all nodes and edges that belong to a shortest path from a
start node to a set of target nodes in the graph
not farther away than a given distance. |
static void |
findShortestUniformPaths(Graph graph,
Node start,
Node end,
boolean directed,
IEdgeMap pathMap)
Marks all edges that belong to a shortest path from
start node to target node. |
static YList |
kShortestPaths(Graph graph,
IDataProvider costDP,
Node start,
Node end,
int k)
This method finds the
k shortest paths connecting a pair of nodes in a directed graph with non-negative edge
costs. |
static ICursor |
kShortestPathsCursor(Graph graph,
IDataProvider costDP,
Node start,
Node end,
int k)
A variant of
kShortestPaths(Graph, IDataProvider, Node, Node, int) that returns the result as a special cursor
that calculates the next path in the sequence only when needed. |
static EdgeList[] |
shortestPair(Graph graph,
Node source,
Node target,
boolean directed,
IDataProvider costDP)
Returns two edge-disjoint paths in a non-negatively weighted directed graph, such that both paths connect nodes
s
and t and have minimum total length. |
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)
This method solves the single-source shortest path problem for arbitrary graphs.
|
static boolean |
singleSource(Graph graph,
Node s,
boolean directed,
IDataProvider cost,
INodeMap dist,
INodeMap pred)
This method solves the single-source shortest path problem for arbitrary graphs.
|
static EdgeList |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
double[] cost)
Similar to
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 EdgeList |
singleSourceSingleSink(Graph graph,
Node s,
Node t,
boolean directed,
IDataProvider cost)
Similar to
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider, INodeMap) 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,
IDataProvider cost,
INodeMap pred)
Like
singleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[]) but uses INodeMap s and
IDataProvider s instead of arrays. |
static void |
uniform(Graph graph,
Node s,
boolean directed,
double[] dist)
Solves the single-source shortest path problem for arbitrary graphs in which each edge has a
uniform cost of
1.0 . |
static void |
uniform(Graph graph,
Node s,
boolean directed,
double[] dist,
Edge[] pred)
Solves the single-source shortest path problem for arbitrary graphs in which each edge has a
uniform cost of
1.0 . |
static void |
uniform(Graph graph,
Node s,
boolean directed,
INodeMap dist,
INodeMap pred)
Like
uniform(Graph, Node, boolean, double[], Edge[]) but uses INodeMap s instead of arrays. |
static double[] |
uniformCost(Graph graph)
Convenience method that returns an array containing uniform edge costs of
1.0 for each edge of the given graph. |
public static final boolean acyclic(Graph graph, Node s, double[] cost, double[] dist)
Each edge is associated with an arbitrary double value that represents the cost of that edge.
This method yields the shortest distance from a given node s
to all other nodes.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startscost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.true
if the input graph is acyclic, false
otherwiseacyclic(Graph, Node, double[], double[], Edge[])
,
constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
public static final boolean acyclic(Graph graph, Node s, double[] cost, double[] dist, Edge[] pred)
Each edge is associated with an arbitrary double value that represents the cost of that edge.
This method yields the shortest distance from a given node s
to all other nodes.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startscost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.pred
- an array of Edge
s that will be filled during the execution and returns 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
.true
if the input graph is acyclic, false
otherwiseacyclic(Graph, Node, double[], double[], Edge[])
,
constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
public static final boolean acyclic(Graph graph, Node s, IDataProvider cost, INodeMap dist, INodeMap pred)
This method yields the shortest distance from a given node s
to all other nodes.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startscost
- the IDataProvider
that returns the double value (cost) for traversing each edgedist
- the INodeMap
that will be filled during the execution and returns a double value (shortest distance) from node s
to all other nodes or Double.POSITIVE_INFINITY
if no such paths existpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existstrue
if the input graph is acyclic, false
otherwiseacyclic(Graph, Node, double[], double[], Edge[])
public static final boolean allPairs(Graph graph, boolean directed, double[] cost, double[][] dist)
If the given graph contains a negative-cost cycle, then false
is returned and the values returned in dist
are left unspecified.
cost.length == graph.E()
dist
: [graph.N()] [graph.N()]]
O(graph.N()) * O(singleSource)
graph
- the input graphdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.true
if the given graph does not contain a negative-cost cycle, false
otherwisepublic static final boolean bellmanFord(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
Each edge is associated with an arbitrary double value that represents the cost of this edge.
In case the given weighted graph contains no negative cost cycles, this method will yield the shortest distance
from a given node 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
.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
bellmanFord(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final boolean bellmanFord(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
Each edge is associated with an arbitrary double value that represents the cost of this edge.
In case the given weighted graph contains no negative cost cycles, this method will yield the shortest distance
from a given node 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
.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.pred
- an array of Edge
s that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
bellmanFord(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final boolean bellmanFord(Graph graph, Node s, boolean directed, IDataProvider cost, INodeMap dist, INodeMap pred)
Each edge is associated with an arbitrary double value that represents the cost of this edge.
In case the given weighted graph contains no negative-cost cycles, this method will yield the shortest distance
from a given node 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 input graphs
- the source nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- the IDataProvider
that returns the double value (cost) for traversing each edgedist
- the INodeMap
that will be filled during the execution and returns a double value (shortest distance) from node s
to all other nodes or Double.POSITIVE_INFINITY
if no such paths existpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existsbellmanFord(Graph, Node, boolean, double[], double[], Edge[])
public static final EdgeList constructEdgePath(Node s, Node t, Edge[] pred)
path of edges
from the result returned by one of the
shortest paths methods defined in this class.
If there is no path from node s
to t
, then an empty list is returned.
s
- the start node of the shortest path which must be the same start node that was specified when pred
was
calculatedt
- the target node of the pathpred
- an array of Edge
s that will be filled during the execution and returns 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
.list
containing the edges on the shortest path from s
to t
in the correct orderconstructEdgePath(Node, Node, IDataProvider)
public static final EdgeList constructEdgePath(Node s, Node t, IDataProvider pred)
constructEdgePath(Node, Node, Edge[])
but the path edges are given by a IDataProvider
.
If there is no path from node s
to t
, then an empty list is returned.
s
- the start node of the shortest path which must be the same start node that was specified when pred
was
calculatedt
- the target node of the pathpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existslist
containing the edges on the shortest path from s
to t
in the correct orderconstructEdgePath(Node, Node, Edge[])
public static final NodeList constructNodePath(Node s, Node t, Edge[] pred)
path of nodes
from the result returned by one of the
shortest paths methods defined in this class.
If there is no path from node s
to t
, then an empty list is returned.
s
- the start node of the shortest path which must be the same start node that was specified when pred
was
calculatedt
- the target node of the pathpred
- an array of Edge
s that will be filled during the execution and returns 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
.list
containing the nodes on the shortest path from s
to t
in the correct orderconstructNodePath(Node, Node, IDataProvider)
public static final NodeList constructNodePath(Node s, Node t, IDataProvider pred)
constructNodePath(Node, Node, Edge[])
but the path edges are given by a IDataProvider
.
If there is no path from node s
to t
, then an empty list is returned.
s
- the start node of the shortest path which must be the same start node that was specified when pred
was
calculatedt
- the target node of the pathpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existslist
containing the nodes on the shortest path from s
to t
in the correct orderconstructNodePath(Node, Node, Edge[])
public static final void dijkstra(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
Each edge is associated with a non-negative double value that represents the cost of the edge.
This method yields the shortest distance from a given node s
to all other nodes.
The costs should be non-negative.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
dijkstra(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final void dijkstra(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
Each edge is associated with a non-negative double value that represents the cost of the edge.
This method yields the shortest distance from a given node s
to all other nodes.
The costs should be non-negative.
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.pred
- an array of Edge
s that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
dijkstra(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final void dijkstra(Graph graph, Node s, boolean directed, IDataProvider cost, INodeMap dist, INodeMap pred)
Each edge is associated with a non-negative double value that represents the cost of the edge.
This method yields the shortest distance from a given node s
to all other nodes.
The costs should be non-negative.
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- the IDataProvider
that returns the double value (cost) for traversing each edgedist
- the INodeMap
that will be filled during the execution and returns a double value (shortest distance) from node s
to all other nodes or Double.POSITIVE_INFINITY
if no such paths existpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existsconstructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
dijkstra(Graph, Node, boolean, double[], double[], Edge[])
public static final void findShortestUniformPaths(Graph graph, Node start, IDataProvider targetMap, boolean directed, int maxLength, EdgeList pathEdges, NodeList pathNodes)
start
node to a set of target nodes in the graph
not farther away than a given distance.
This method assumes that each edge of the input graph has a cost of 1.0.
maxLength
will not be considered.O(graph.N() + graph.E())
graph
- the input graphstart
- the start nodetargetMap
- the IDataProvider
that returns a boolean value indicating whether or not a node belongs to the set of target
nodesdirected
- true
if the graph should be considered as directed, false
otherwisemaxLength
- the maximum edge length of the shortest pathspathEdges
- a list
that will be filled during the execution and returns the edges on the shortest path from s
to t
in the correct orderpathNodes
- a list
that will be filled during the execution and returns the nodes on the shortest path from s
to t
in the correct orderpublic static final void findShortestUniformPaths(Graph graph, Node start, Node end, boolean directed, IEdgeMap pathMap)
start
node to target
node.
This method assumes that each edge of the input graph has a cost of 1.0.
O(graph.N() + graph.E())
graph
- the input graphstart
- the start nodeend
- the target nodedirected
- true
if the graph should be considered as directed, false
otherwisepathMap
- the IEdgeMap
that will be filled during the execution and returns a boolean value indicating whether or not the
edge belongs to a shortest path connecting the two nodespublic static final YList kShortestPaths(Graph graph, IDataProvider costDP, Node start, Node end, int k)
k
shortest paths connecting a pair of nodes in a directed graph with non-negative edge
costs.
The result will be returned as a list of EdgeList
objects.
The cost should be non-negative.
O(graph.E() + graph.N() * log(graph.N()) + k)
graph
- the input graphcostDP
- the IDataProvider
that returns a double value (cost) for traversing each edgestart
- the given start nodeend
- the given target nodek
- a non-negative integer valuelist
of EdgeList
objects each of which represents a path from start
node to target
node. The i
-th path in the list contains the i
-th shortest path between the start
and target
node.public static final ICursor kShortestPathsCursor(Graph graph, IDataProvider costDP, Node start, Node end, int k)
kShortestPaths(Graph, IDataProvider, Node, Node, int)
that returns the result as a special cursor
that calculates the next path in the sequence only when needed.
The returned cursor only supports the operation Ok
, Current
and
ICursor.next()
.
The cost should be non-negative.
O(graph.E() + graph.N() * log(graph.N()) + k)
graph
- the input graphcostDP
- the IDataProvider
that returns a double value (cost) for traversing each edgestart
- the given start nodeend
- the given target nodek
- a non-negative integer valuecursor
that calculates the next path in the sequence only when neededpublic static final EdgeList[] shortestPair(Graph graph, Node source, Node target, boolean directed, IDataProvider costDP)
s
and t
and have minimum total length.graph
- the input graphsource
- the source node of the shortest pairtarget
- the target node of the shortest pairdirected
- true
if the graph should be considered as directed, false
otherwisecostDP
- the IDataProvider
that returns a double value (cost) for traversing each edgeEdgeList
s holding the resulting edge-disjoint paths or null
if no such
edge-disjoint paths existpublic static final boolean singleSource(Graph graph, Node s, boolean directed, double[] cost, double[] dist)
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.true
if the weighted graph does not contain a negative-cost cycle, false
otherwiseconstructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
singleSource(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final boolean singleSource(Graph graph, Node s, boolean directed, double[] cost, double[] dist, Edge[] pred)
pred.length == graph.N()
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
dist
- an array of values that will be filled during the execution and returns 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
.pred
- an array of Edge
s that will be filled during the execution and returns 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
.true
if the weighted graph does not contain a negative-cost cycle, false
otherwiseconstructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
singleSource(Graph, Node, boolean, IDataProvider, INodeMap, INodeMap)
public static final boolean singleSource(Graph graph, Node s, boolean directed, IDataProvider cost, INodeMap dist, INodeMap pred)
graph
- the input graphs
- the source nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- the IDataProvider
that returns the double value (cost) for traversing each edgedist
- the INodeMap
that will be filled during the execution and returns a double value (shortest distance) from node s
to all other nodes or Double.POSITIVE_INFINITY
if no such paths existpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existstrue
if the weighted graph does not contain a negative-cost cycle, false
otherwiseconstructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
singleSource(Graph, Node, boolean, double[], double[], Edge[])
public static final EdgeList singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, double[] cost)
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.
Each edge is associated with a non-negative double value that represents the cost of the edge.
If the returned path is empty, then there is no path between the nodes.
The costs should be non-negative.
graph
- the input graphs
- the source nodet
- the sink nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
path of edges
between source and sinksingleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider)
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider, INodeMap)
public static final double singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, double[] cost, Edge[] pred)
Each edge is associated with a non-negative double value that represents the cost of the edge.
This method returns the shortest distance from node s
to node
t
. It also returns information to construct the actual path between these two nodes.
The costs should be non-negative.
cost.length == graph.E()
pred.length == graph.N()
O(graph.E() + graph.N() * log(graph.N())
graph
- the input graphs
- the source nodet
- the sink nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- an array of double values that returns the costs for traversing each edge; edge e
has cost
cost[e.index()]
pred
- an array of Edge
s that will be filled during the execution and returns 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
.s
and t
if a path between these two nodes exists or Double.POSITIVE_INFINITY
otherwiseconstructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider)
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider, INodeMap)
,
singleSourceSingleSink(Graph, Node, Node, boolean, double[])
public static final EdgeList singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, IDataProvider cost)
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider, INodeMap)
but instead of returning
the shortest distance between the source and sink the actual shortest edge path between these nodes will be returned.
Each edge is associated with a non-negative double value that represents the cost of the edge.
If the returned path is empty, then there is no path between the nodes.
The costs should be non-negative.
graph
- the input graphs
- the source nodet
- the sink nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- the IDataProvider
that returns the double value (cost) for traversing each edgepath of edges
between source and sinksingleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider, INodeMap)
,
singleSourceSingleSink(Graph, Node, Node, boolean, double[])
public static final double singleSourceSingleSink(Graph graph, Node s, Node t, boolean directed, IDataProvider cost, INodeMap pred)
singleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
but uses INodeMap
s and
IDataProvider
s instead of arrays.
Each edge is associated with a non-negative double value that represents the cost of the edge.
The costs should be non-negative.
graph
- the input graphs
- the source nodet
- the sink nodedirected
- true
if the graph should be considered as directed, false
otherwisecost
- the IDataProvider
that returns the double value (cost) for traversing each edgepred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existspath of edges
between source and sinksingleSourceSingleSink(Graph, Node, Node, boolean, double[], Edge[])
,
singleSourceSingleSink(Graph, Node, Node, boolean, IDataProvider)
,
singleSourceSingleSink(Graph, Node, Node, boolean, double[])
public static final void uniform(Graph graph, Node s, boolean directed, double[] dist)
1.0
.pred.length == graph.N()
O(graph.N() + graph.E())
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisedist
- an array of values that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
public static final void uniform(Graph graph, Node s, boolean directed, double[] dist, Edge[] pred)
1.0
.pred.length == graph.N()
O(graph.N() + graph.E())
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisedist
- an array of values that will be filled during the execution and returns 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
.pred
- an array of Edge
s that will be filled during the execution and returns 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
.constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
public static final void uniform(Graph graph, Node s, boolean directed, INodeMap dist, INodeMap pred)
uniform(Graph, Node, boolean, double[], Edge[])
but uses INodeMap
s instead of arrays.pred.length == graph.N()
O(graph.N() + graph.E())
graph
- the input graphs
- the node from which the shortest path search startsdirected
- true
if the graph should be considered as directed, false
otherwisedist
- the INodeMap
that will be filled during the execution and returns a double value (shortest distance) from node s
to all other nodes or Double.POSITIVE_INFINITY
if no such paths existpred
- the INodeMap
that will be filled during the execution and returns for each node t
the last edge on the
shortest path from s
to t
or null
if t == s
or no shortest path from s
to t
existsuniform(Graph, Node, boolean, double[], Edge[])
,
constructNodePath(Node, Node, Edge[])
,
constructEdgePath(Node, Node, Edge[])
public static final double[] uniformCost(Graph graph)
1.0
for each edge of the given graph.graph
- the input graph1.0
(i.e., for each edge e: cost[e.index()] == 1.0
)