|
AddNode(TGGraphNode)
|
Adds the specified node to the graph.
|
|
Assign(TPersistent)
|
Represents method Assign(TPersistent).
|
|
BeginUpdate
|
Enables the graph to track when it is changing.
Call BeginUpdate before directly modifying the graph (adding or deleting nodes), and EndUpdate after. Changing existing nodes (such as its Caption) will still generate events, to temporarily prevent events call the node's BeginUpdate method or call BeginUpdateNodes to prevent events for all the nodes in the graph. When implementing properties or methods that change the graph in descendants of the graph, call BeginUpdate before the changes are made, and EndUpdate when the changes are complete.
The BeginUpdate method may be nested inside other BeginUpdate method calls. The graph will not fire an OnChange event until an equal number of EndUpdate method calls are made. Therefore, always ensure you protect the calling of the EndUpdate method call in a try-finally block.
Note
|
OnChange events will not fire. However, OnAddNode and OnRemoveNode events will still fire so that you can keep external data sets synchonized with the graph.
|
|
|
BeginUpdateNodes
|
Enables the graph to track when its nodes are changing.
Call BeginUpdateNodes before directly modifying nodes, and EndUpdateNodes after. The BeginUpdateNodes method calls every node's BeginUpdate method. Any new nodes created inside a BeginUpdateNodes/EndUpdateNodes block will also have its BeginUpdate methods called.
The BeginUpdateNodes method may be nested inside other BeginUpdateNodes method calls. The graph will not fire an OnNodeChange event until an equal number of EndUpdateNodes method calls are made. Therefore, always ensure you protect the calling of the EndUpdateNodes method call in a try-finally block.
|
|
Change
|
Called when the graph is changed.
Calls the OnChange event handler
|
|
Clear
|
Clears the graph of all nodes and edges.
|
|
ClosestNode(TGGraphNode,Boolean)
|
Returns the node that is closest to the ANode parameter and has its Visited property equal to the Visited parameter.
This method assumes that every node Weight in the graph equals the length to get from ANode to that node. The InitializeNodes method can be used to set the weights of all nodes to MaxInt. The EnumerateShortestPaths and ShortestPath methods call this method as they build up the paths between Anode and every other node; they also set the Weight of each node to the shortest path length.
Note
|
The ClosestNode method only works with weighted graphs (a graph of TWeightedNodes and TWeightedEdges).
|
|
|
CreateNode(String)
|
Creates a new node and adds it to the graph. The Caption of the node is set to the NodeName parameter. The node class created is the default for the graph (usually GGraph.TGGraphNode class). To create nodes of other types, create the node and pass in the graph (see Example).
|
|
DefineProperties(TFiler)
|
Represents method DefineProperties(TFiler).
|
|
DepthFirstSearch(TGGraphNode)
|
Searches the graph for all nodes reachable from ANode. The method marks every node reachable with Visited = True. The method searches the graph using a depth first search.
The InitializeNodes method must be called to initialize the graph before performing your search. The method TraverseFrom combines calls to these two methods.
|
|
EndUpdate
|
Enables the graph to track when it has finished changing.
Call BeginUpdate before directly modifying the graph (adding or deleting nodes), and EndUpdate after. Changing existing nodes (such as its Caption) will still generate events, to temporarily prevent events call the node's BeginUpdate method or call BeginUpdateNodes to prevent events for all the nodes in the graph. When implementing properties or methods that change the graph in descendants of the graph, call BeginUpdate before the changes are made, and EndUpdate when the changes are complete.
The BeginUpdate method may be nested inside other BeginUpdate method calls. The graph will not fire an OnChange event until an equal number of EndUpdate method calls are made. Therefore, always ensure you protect the calling of the EndUpdate method call in a try-finally block.
Note
|
OnChange events will not fire. However, OnAddNode and OnRemoveNode events will still fire so that you can keep external data sets synchonized with the graph.
|
|
|
EndUpdateNodes
|
Enables the graph to track when its nodes are changing.
Call BeginUpdateNodes before directly modifying nodes, and EndUpdateNodes after. The BeginUpdateNodes method calls every node's BeginUpdate method. Any new nodes created inside a BeginUpdateNodes/EndUpdateNodes block will also have its BeginUpdate methods called.
The BeginUpdateNodes method may be nested inside other BeginUpdateNodes method calls. The graph will not fire an OnNodeChange event until an equal number of EndUpdateNodes method calls are made. Therefore, always ensure you protect the calling of the EndUpdateNodes method call in a try-finally block.
|
|
EnumerateShortestPaths(TGGraphNode)
|
Finds the shortest paths and their lengths between the StartNode and every other node in the graph. After calling this method, every node will contain the length from the StartNode to that node (in the Weight property) and the shortest path (in the ShortestPath property).
Note
|
The EnumerateShortestPaths method only works with weighted graphs (a graph of TWeightedNodes and TWeightedEdges).
|
|
|
Extract(String)
|
Overloaded. Removes the node with the specified Caption from the graph without deleting it. The graph searches for a node that matches the Caption parameter, if no node is found this method returns nil.
Usually, deleting a node also frees the node. This method allows the node to be extracted without deleting it. You are responsible for freeing the extracted node. After extraction, the Graph property of the node is nil. To add the node back, set the Graph property.
The overloaded Extract method extracts the specified node. In other words, the graph doesn't have to search for a node that matches the Caption string.
Note
|
The extracted node's edges are deleted as a node cannot be connected to nodes in a graph and yet not be part of the graph.
|
|
|
Extract(TGGraphNode)
|
Overloaded. Removes the specified node from the graph without deleting it.
Usually, deleting a node also frees the node. This method allows the node to be extracted without deleting it. You are responsible for freeing the extracted node. After extraction, the Graph property of the node is nil. To add the node back, set the Graph property.
The overloaded Extract method extracts a node based on its Caption property. In other words, the graph searches for a node that matches the Caption string.
Note
|
The extracted node's edges are deleted as a node cannot be connected to nodes in a graph and yet not be part of the graph.
|
|
|
FindNode(String)
|
Searches the graph for a node that has its Caption property equal to the specified parameter. It returns the first node with this caption. If no node is found, the function returns nil.
|
|
GetNodeCount
|
Returns the number of nodes in the graph
|
|
GetNodes
|
Returns an iterator over the entire graph. Call GetNodes to return an iterator from which you can access all the nodes in the graph. Every call to GetNodes returns a new iterator.
The GetNodes method provides a base class means of accessing all the nodes in the list. If you know the type of the descendant graph, you can use their access methods (such as the Node property of the TGGraph class).
Note
|
There is no ordering implied with the GetNodes function.
|
Warning
|
Do not use the enumeration to delete or add items to the graph as the behavior will be unpredictable (similar to a common TList programming error: for i := 0 to List.Count - 1 do; List.Delete(i); which only deletes every other item in the list).
|
|
|
InitializeNodes(TGGraphNode,Boolean)
|
Initializes all the nodes in the graph. It sets each node's Visited property to the Value parameter. If the node is a TWeightedNode descendant, it also sets their Weight property to MaxInt and clears the ShortestPath property (and adds StartNode as an item).
|
|
Loaded
|
Represents method Loaded.
|
|
LoadNodesProperty(TReader)
|
Loads nodes and edges from the TReader stream
|
|
ModifySuccessor(TGGraphNode,TGGraphNode,TGGraphEdge)
|
This method is called from within the TopologicalOrder algorithm to modify the successors of a node as we traverse the graph.
|
|
NewNode
|
Creates a new node for the graph
|
|
NewNodeId
|
Returns a unique node id.
|
|
NodeChange(TGGraphNode)
|
Called when a node changes.
Calls the OnNodeChange event handler.
|
|
RemoveNode(String)
|
Overloaded. Removes the node with the specified Caption from the graph and frees the node. The graph searches for a node that matches the Caption parameter, if no node is found this method returns nil.
All edges to and from the node are also deleted. The overloaded RemoveNode method removes the specified node. In other words, the graph doesn't have to search for a node that matches the Caption string.
Note
|
To remove a node without freeing it, use the Extract methods.
|
|
|
RemoveNode(TGGraphNode)
|
Overloaded. Removes the node from the graph and frees the node.
All edges to and from the node are also deleted. The overloaded RemoveNode method removes a node based on its Caption property. In other words, the graph searches for a node that matches the Caption string.
Note
|
To remove a node without freeing it, use the Extract methods.
|
|
|
RemovePredecessors(TGGraphNode)
|
Removes all predecessor edges of a node, i.e., all edges that point to the node from other nodes (including itself).
|
|
SetDirected(Boolean)
|
Specifies whether the graph is directed (edges have a direction) or not.
|
|
ShortestPath(TGGraphNode)
|
Finds the lengths of the shortest paths from the given node to every other node in the graph. After calling this method, the Weight property of every node equals the shortest path length between the StartNode parameter and that node.
Use EnumerateShortestPaths to not only find the length between nodes but also the actual shortest path.
Note
|
The ShortestPath method only works with weighted graphs (a graph of TWeightedNodes and TWeightedEdges).
|
|
|
StoreNodesProperty(TWriter)
|
Saves nodes and edges to the TWriter stream
|
|
TextChange(TGGraphNode,String)
|
Called when a node's Caption is changing.
Calls the OnNodeCaptionChange event handler.
|
|
TopologicalOrder(TStrings)
|
Returns a list of all the nodes in the graph in topological order. If the function succeeds the Acyclic property is set to True.
The user is responsible for freeing the TStrings result whether the function succeeded or not. You may pass in the TStrings to use in the OrderedNodes parameter.
A topological ordering of the nodes in a graph is a linear ordering which has the property that if node i is a predecessor of node j then node i precedes node j in the linear ordering. A topological order can be used to check if a graph is feasible (nothing is a prerequisite of itself, a cycle) and provides an order for performing each node in an Activity on Vertex (AOV) network. For example, you can use a graph to represent the classes a computer science student must take to graduate with a computer science degree. The nodes represent each class and the edges represent the prerequisites for the class, i.e., a student must take "Introduction to Programming" class before he/she can take the "Data Structures" class. The TopologicalOrder method will return one way the student can take the classes in the correct order, prerequisites first.
Note
|
Undirected graphs always fail as there are always loops.
|
|
|
TraverseFrom(TGGraphNode)
|
Searches the graph for all nodes reachable from ANode. The method marks every node reachable with Visited = True. The method uses the InitializeNodes and DepthFirstSearch methods to do its work.
|