Graph Construction
- abstract protected function loadEdges($nodes) — Load the edges for a list of nodes. You must override this method. You will be passed a list of nodes, and should return a dictionary mapping each node to the list of nodes that can be reached by following its the edges which originate at it: for example, the child nodes of an object which has a parent-child relationship to other objects.
- final public function addNodes($nodes) — Seed the graph with known nodes. Often, you will provide the candidate edges that a user is trying to create here, or the initial set of edges you know about.
- final public function loadGraph() — Load the graph, building it out so operations can be performed on it. This constructs the graph level-by-level, calling @{method:loadEdges} to expand the graph at each stage until it is complete.
Cycle Detection
- final public function detectCycles($node) — Detect if there are any cycles reachable from a given node.
- private function performCycleDetection($node, $visited) — Internal cycle detection implementation. Recursively walks the graph, keeping track of where it's been, and returns the first cycle it finds.
Graph Exploration
Other Methods
- final public function getNodes()
- final public function getNodesInTopologicalOrder() — Get the nodes in topological order.
- final public function getNodesInRoughTopologicalOrder() — Get the nodes in topological order, or some roughly similar order if the graph contains cycles.