com.mindfusion.diagramming
Class PathFinder

java.lang.Object
  extended by com.mindfusion.diagramming.PathFinder

public class PathFinder
extends java.lang.Object

PathFinder helps you find paths and cycles in a graph.


Constructor Summary
PathFinder()
           
 
Method Summary
static PathList findAllCycles(Diagram diagram)
          Finds all cycles in the specified diagram.
static PathList findAllPaths(Diagram diagram, DiagramNode from, DiagramNode to)
          Finds and returns all paths starting from node from and ending at node to.
static Path findCycle(Diagram diagram)
          Detects whether there is a cycle in a graph.
static Path findCycle(Diagram diagram, DiagramNode participant)
          Detects whether the specified node participates in a cycle.
static Path findLongestPath(Diagram diagram)
          Finds the longest path in the graph.
static Path findLongestPath(Diagram diagram, DiagramNode from, DiagramNode to)
          Finds the longest path between two nodes.
static Path findLongestPath(Diagram diagram, long timeLimit)
          Finds the longest path in the diagram.
static Path findShortestPath(Diagram diagram, DiagramNode from, DiagramNode to)
          Finds and returns the shortest path between from and to.
static Path findShortestPath(Diagram diagram, DiagramNode from, DiagramNode to, boolean useNodeWeights, boolean useLinkWeights)
          Finds and returns the shortest path between fromand to, considering the weight of the nodes, the weight of the links or both.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathFinder

public PathFinder()
Method Detail

findAllPaths

public static PathList findAllPaths(Diagram diagram,
                                    DiagramNode from,
                                    DiagramNode to)
Finds and returns all paths starting from node from and ending at node to.

Parameters:
diagram - The Diagram in which to look for paths.
from - The DiagramNode where the paths should start.
to - The DiagramNode where the paths should end.
Returns:
A PathList containing the found paths. The list is empty if there is no path found between the specified nodes.

findShortestPath

public static Path findShortestPath(Diagram diagram,
                                    DiagramNode from,
                                    DiagramNode to)
Finds and returns the shortest path between from and to.

Parameters:
diagram - The Diagram in which to look for a path.
from - The DiagramNode where the path should start.
to - The DiagramNode where the path should end.
Returns:
A Path object representing the found path, or null if there isn't any path connecting the specified nodes.

findShortestPath

public static Path findShortestPath(Diagram diagram,
                                    DiagramNode from,
                                    DiagramNode to,
                                    boolean useNodeWeights,
                                    boolean useLinkWeights)
Finds and returns the shortest path between fromand to, considering the weight of the nodes, the weight of the links or both.

Parameters:
diagram - The Diagram in which to look for a path.
from - The DiagramNode where the path should start.
to - The DiagramNode where the path should end.
useNodeWeights - true if the Weight attribute of nodes should be considered, otherwise false.
useLinkWeights - true if the Weight attribute of links should be considered, otherwise false.
Returns:
A Path object representing the found path, or null if there isn't any path connecting the specified nodes.

findLongestPath

public static Path findLongestPath(Diagram diagram,
                                   DiagramNode from,
                                   DiagramNode to)
Finds the longest path between two nodes.

Parameters:
diagram - The Diagram in which to look for a path.
from - The DiagramNode where the path should start.
to - The DiagramNode where the path should end.
Returns:
A Path object representing the found path, or null if there isn't any path connecting the specified nodes.

findLongestPath

public static Path findLongestPath(Diagram diagram)
Finds the longest path in the graph.

Parameters:
diagram - The Diagram in which to look for a path.
Returns:
A Path object representing the found path, or null if there aren't any linked nodes in the graph.

findLongestPath

public static Path findLongestPath(Diagram diagram,
                                   long timeLimit)
Finds the longest path in the diagram. The time limit specifies the maximal duration of the search process in milliseconds.

Parameters:
diagram - The Diagram in which to look for a path.
timeLimit - Specifies the maximal amount of time the algorithm is allowed to run.
Returns:
A Path object representing the found path, or null if there aren't any linked nodes in the graph.

findCycle

public static Path findCycle(Diagram diagram,
                             DiagramNode participant)
Detects whether the specified node participates in a cycle.

Parameters:
diagram - The Diagram in which to look for a cycle.
participant - A DiagramNode that should be in the cycle.
Returns:
A Path object representing the cycle that contains the specified node, or null if the node is not in a cycle.

findCycle

public static Path findCycle(Diagram diagram)
Detects whether there is a cycle in a graph.

Parameters:
diagram - The Diagram in which to look for a cycle.
Returns:
A Path object representing the first cycle found in the graph, or null if the graph does not contain any cycles.

findAllCycles

public static PathList findAllCycles(Diagram diagram)
Finds all cycles in the specified diagram.

Parameters:
diagram - The Diagram in which to look for cycles.
Returns:
A PathList containing the found cycles.