public class SinglePairShortestPathDijkstra extends SinglePairShortestPath
It solves the single-pair shortest path problem using a Dijkstra-based implementation.
It is a weighted algorithm, so it takes into account the cost of the edges to compute a minimum-cost shortest path. That is, the user may set for each edge type which attribute should be used to retrieve the cost of the edge. If no attribute is given for an edge type, this will assume the edge has a fixed cost (the default is 1). Only numerical attribute can be set as weight attributes (that is Long, Integer or Double attributes are allowed).
Check out the 'Algorithms' section in the SPARKSEE User Manual for more details on this.
Constructor and Description |
---|
SinglePairShortestPathDijkstra(Session session,
long src,
long dst)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addAllEdgeTypes(EdgesDirection dir)
Allows for traversing all edge types of the graph.
|
void |
addAllNodeTypes()
Allows for traversing all node types of the graph.
|
void |
addEdgeType(int type,
EdgesDirection dir)
Allows for traversing edges of the given type.
|
void |
addNodeType(int type)
Allows for traversing nodes of the given type.
|
void |
addWeightedEdgeType(int type,
EdgesDirection dir,
int attr)
Allows for traversing edges of the given type using the given attribute as the weight.
|
void |
excludeEdges(Objects edges)
Set which edges can't be used.
|
void |
excludeNodes(Objects nodes)
Set which nodes can't be used.
|
boolean |
exists()
Returns TRUE If a path exists or FALSE otherwise.
|
double |
getCost()
Gets the cost of the shortest path.
|
OIDList |
getPathAsEdges()
Gets the shortest path between the source node and the destination node as an ordered set of edges.
|
OIDList |
getPathAsNodes()
Gets the shortest path between the source node and the destination node as an ordered set of nodes.
|
void |
run()
Executes the algorithm.
|
void |
setDynamicEdgeCostCallback(SinglePairShortestPathDijkstraDynamicCost dynCostCalculator)
Set a class callback to dynamically calculate the cost of the edges.
|
void |
setMaximumHops(int maxhops)
Sets the maximum hops restriction.
|
void |
setUnweightedEdgeCost(double weight)
Sets the weight assigned to the unweighted edges.
|
close, isClosed
public SinglePairShortestPathDijkstra(Session session, long src, long dst)
session
- [in] Session to get the graph from and perform traversal.src
- [in] Source node.dst
- [dst] Destination node.public void excludeNodes(Objects nodes)
This will replace any previously specified set of excluded nodes. Should only be used to exclude the usage of specific nodes from allowed node types because it's less efficient than not allowing a node type.
excludeNodes
in class SinglePairShortestPath
nodes
- [in] A set of node identifiers that must be kept intact until the destruction of the class.public double getCost()
The cost is the sum of the weights of the edges in the shortest path.
getCost
in class SinglePairShortestPath
public void run()
run
in class SinglePairShortestPath
public void addAllEdgeTypes(EdgesDirection dir)
addAllEdgeTypes
in class SinglePairShortestPath
dir
- [in] Edge direction.public void excludeEdges(Objects edges)
This will replace any previously specified set of excluded edges. Should only be used to exclude the usage of specific edges from allowed edge types because it's less efficient than not allowing an edge type.
excludeEdges
in class SinglePairShortestPath
edges
- [in] A set of edge identifiers that must be kept intact until the destruction of the class.public void addEdgeType(int type, EdgesDirection dir)
addEdgeType
in class SinglePairShortestPath
type
- [in] Edge type.dir
- [in] Edge direction.public void setUnweightedEdgeCost(double weight)
All the edges from the types added without an explicit weight attribute will get this weight. The default weight for this edges is 1.
weight
- [in] The weight value for unweighted edges.public OIDList getPathAsNodes()
getPathAsNodes
in class SinglePairShortestPath
public void setDynamicEdgeCostCallback(SinglePairShortestPathDijkstraDynamicCost dynCostCalculator)
The callback can be set to NULL (the default) to use the normal attribute based cost weights. The given class must be kept alive by the user for as long as the algorithm is running.
dynCostCalculator
- [in] Class callback to calculate the edge costspublic void addNodeType(int type)
addNodeType
in class SinglePairShortestPath
type
- nullpublic boolean exists()
exists
in class SinglePairShortestPath
public OIDList getPathAsEdges()
getPathAsEdges
in class SinglePairShortestPath
public void addWeightedEdgeType(int type, EdgesDirection dir, int attr)
type
- [in] Edge type.dir
- [in] Edge direction.attr
- [in] Attribute to be used as the weight. It must be a global attribute or an attribute of the given edge type.public void setMaximumHops(int maxhops)
All paths longer than the maximum hops restriction will be ignored.
setMaximumHops
in class SinglePairShortestPath
maxhops
- [in] The maximum hops restriction. It must be positive or zero. Zero, the default value, means unlimited.public void addAllNodeTypes()
addAllNodeTypes
in class SinglePairShortestPath