### Get Hops from a Starting Node Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Computes the hop distance to all nodes centered around a specified node. Uses forw_bfs() or back_bfs() depending on the forward parameter. Typical usage is shown with node 1 and 8. ```python >>> print graph.get_hops(1, 8) >>> [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)] # node 1 is at 0 hops # node 2 is at 1 hop # ... # node 8 is at 5 hops ``` -------------------------------- ### Graph.get_hops(start, forward=True) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Computes the hop distance from a specified start node to all reachable nodes. Distances are calculated based on either forward or backward edges. ```APIDOC ## Graph.get_hops(start, forward=True) ### Description Computes the hop distance to all nodes centered around a specified node. First order neighbours are at hop 1, their neigbours are at hop 2 etc. Uses [`forw_bfs()`](#altgraph.Graph.Graph.forw_bfs) or [`back_bfs()`](#altgraph.Graph.Graph.back_bfs) depending on the value of the forward parameter. If the distance between all neighbouring nodes is 1 the hop number corresponds to the shortest distance between the nodes. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start**: (type unknown) - Required - The node from which to compute hop distances. - **forward**: (boolean) - Optional - If True, uses forward edges; otherwise, uses backward edges. Defaults to True. ### Response #### Success Response - list: A list of tuples, where each tuple is (node, hop_distance). ``` -------------------------------- ### Basic Graph Creation and Dot Generation Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Demonstrates creating a graph, converting it to a dot representation, displaying it, and saving it to a file or image. Ensure graphviz is installed and in the system's PATH. ```python from altgraph import Graph, Dot # create a graph edges = [ (1,2), (1,3), (3,4), (3,5), (4,5), (5,4) ] graph = Graph.Graph(edges) # create a dot representation of the graph dot = Dot.Dot(graph) # display the graph dot.display() # save the dot representation into the mydot.dot file dot.save_dot(file_name='mydot.dot') # save dot file as gif image into the graph.gif file dot.save_img(file_name='graph', file_type='gif') ``` -------------------------------- ### Graph.forw_bfs_subgraph(start_id) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Generates a subgraph containing nodes reachable via a breadth-first search starting from a given node, following outgoing edges. ```APIDOC ## Graph.forw_bfs_subgraph(start_id) ### Description Return a subgraph consisting of the breadth first reachable nodes from *start_id* based on their outgoing edges. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start_id**: (type unknown) - Required - The starting node ID for the BFS. ### Response #### Success Response - subgraph: A graph object representing the reachable nodes. ``` -------------------------------- ### Graph.back_bfs(start, end=None) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes discovered through a breadth-first search starting from a given node, following incoming edges. The search can optionally stop at a specified end node. ```APIDOC ## Graph.back_bfs(start, end=None) ### Description Returns a list of nodes starting at *start* in some bread first search order (following incoming edges). When *end* is specified iteration stops at that node. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start**: (type unknown) - Required - The starting node for the BFS. - **end**: (type unknown) - Optional - The node at which to stop the BFS. ### Response #### Success Response - list: A list of nodes in BFS order. ``` -------------------------------- ### Graph.back_bfs_subgraph(start_id) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Generates a subgraph containing nodes reachable via a breadth-first search starting from a given node, following incoming edges. ```APIDOC ## Graph.back_bfs_subgraph(start_id) ### Description Return a subgraph consisting of the breadth first reachable nodes from *start_id* based on their incoming edges. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start_id**: (type unknown) - Required - The starting node ID for the BFS. ### Response #### Success Response - subgraph: A graph object representing the reachable nodes. ``` -------------------------------- ### altgraph.GraphAlgo.dijkstra Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphalgo.md Finds shortest paths from a start node to all other nodes using Dijkstra's algorithm. Assumes edge data represents edge length and works best with positive edge lengths. ```APIDOC ## altgraph.GraphAlgo.dijkstra(graph, start) ### Description Dijkstra’s algorithm for shortest paths. Finds shortest paths from the start node to all nodes nearer than or equal to the *end* node. The edge data is assumed to be the edge length. #### NOTE Dijkstra’s algorithm is only guaranteed to work correctly when all edge lengths are positive. This code does not verify this property for all edges (only the edges examined until the end vertex is reached), but will correctly compute shortest paths even for some graphs with negative edges, and will raise an exception if it discovers that a negative edge has caused it to make a mistake. ### Parameters #### Path Parameters - **graph**: (type not specified) - Description of the graph input. - **start**: (type not specified) - Description of the starting node. ### Method (Not specified, likely a function call within a Python context) ### Endpoint (Not applicable, this is a Python function) ### Request Example (Not applicable, this is a Python function) ### Response (Not specified, likely returns path information or distances) ``` -------------------------------- ### Valid Graphviz Style Attributes for Dot Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Provides examples of valid attributes for controlling graph layout, node appearance, and edge styles. These attributes are passed to the respective style methods. ```text rankdir = 'LR' (draws the graph horizontally, left to right) ranksep = number (rank separation in inches) style = 'filled' | 'invisible' | 'diagonals' | 'rounded' shape = 'box' | 'ellipse' | 'circle' | 'point' | 'triangle' style = 'dashed' | 'dotted' | 'solid' | 'invis' | 'bold' arrowhead = 'box' | 'crow' | 'diamond' | 'dot' | 'inv' | 'none' | 'tee' | 'vee' weight = number (the larger the number the closer the nodes will be) ``` -------------------------------- ### Graph.forw_bfs(start, end=None) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes discovered through a breadth-first search starting from a given node, following outgoing edges. The search can optionally stop at a specified end node. ```APIDOC ## Graph.forw_bfs(start, end=None) ### Description Returns a list of nodes starting at *start* in some bread first search order (following outgoing edges). When *end* is specified iteration stops at that node. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start**: (type unknown) - Required - The starting node for the BFS. - **end**: (type unknown) - Optional - The node at which to stop the BFS. ### Response #### Success Response - list: A list of nodes in BFS order. ``` -------------------------------- ### Forward Breadth-First Search Traversal Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes starting from a specified node in a breadth-first search order, following outgoing edges. Iteration can stop at a specified end node. ```python graph.forw_bfs(start) ``` -------------------------------- ### Forward Breadth-First Search Subgraph Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a subgraph containing nodes reachable from a start node via outgoing edges using a breadth-first search. ```python graph.forw_bfs_subgraph(start_id) ``` -------------------------------- ### altgraph.GraphAlgo.shortest_path Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphalgo.md Finds a single shortest path between a given start node and end node, using the same conventions as the dijkstra function. Returns a list of nodes in order along the shortest path. ```APIDOC ## altgraph.GraphAlgo.shortest_path(graph, start, end) ### Description Find a single shortest path from the given start node to the given end node. The input has the same conventions as [`dijkstra()`](#altgraph.GraphAlgo.dijkstra). The output is a list of the nodes in order along the shortest path. ### Parameters #### Path Parameters - **graph**: (type not specified) - Description of the graph input. - **start**: (type not specified) - Description of the starting node. - **end**: (type not specified) - Description of the ending node. ### Method (Not specified, likely a function call within a Python context) ### Endpoint (Not applicable, this is a Python function) ### Request Example (Not applicable, this is a Python function) ### Response - **path**: list - A list of nodes in order along the shortest path. ``` -------------------------------- ### Backward Breadth-First Search Traversal Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes starting from a specified node in a breadth-first search order, following incoming edges. Iteration can stop at a specified end node. ```python graph.back_bfs(start) ``` -------------------------------- ### Graph.iterdfs(start, end=None, forward=True) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Yields nodes during a depth-first traversal starting from a specified node. Traversal can be controlled by an optional end node and edge direction. ```APIDOC ## Graph.iterdfs(start, end=None, forward=True) ### Description Yield nodes in a depth first traversal starting at the *start* node. If *end* is specified traversal stops when reaching that node. If forward is True (the default) edges are traversed in forward direction, otherwise they are traversed in reverse direction. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start**: (type unknown) - Required - The starting node for the DFS traversal. - **end**: (type unknown) - Optional - The node at which to stop the traversal. - **forward**: (boolean) - Optional - If True, traverse edges in the forward direction; otherwise, traverse in reverse. Defaults to True. ### Response #### Success Response - Yields nodes during DFS traversal. ``` -------------------------------- ### Backward Breadth-First Search Subgraph Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a subgraph containing nodes reachable from a start node via incoming edges using a breadth-first search. ```python graph.back_bfs_subgraph(start_id) ``` -------------------------------- ### ObjectGraph.flatten() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Yields all nodes that are reachable from a starting node or the graph root, based on a condition. Nodes are only reachable from the root if there's a direct or indirect reference from the root. ```APIDOC ## ObjectGraph.flatten() Yield all nodes that are entirely reachable by *condition* starting fromt he given *start* node or the graph root. #### NOTE objects are only reachable from the graph root when there is a reference from the root to the node (either directly or through another node) ``` -------------------------------- ### Depth-First Traversal (Iterative) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Yields nodes in a depth-first traversal starting from a specified node. Can optionally stop at an end node and traverse edges in reverse. ```python graph.iterdfs(start) ``` -------------------------------- ### Graph.iterdata(start, end=None, condition=None, forward=True) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Yields associated data for nodes during a depth-first traversal, provided the node has data and meets an optional condition. Supports specifying an end node and edge direction. ```APIDOC ## Graph.iterdata(start, end=None, condition=None, forward=True) ### Description Yield the associated data for nodes in a depth first traversal starting at the *start* node. This method will not yield values for nodes without associated data. If *end* is specified traversal stops when reaching that node. If *condition* is specified and the condition callable returns False for the associated data this method will not yield the associated data and will not follow the edges for the node. If forward is True (the default) edges are traversed in forward direction, otherwise they are traversed in reverse direction. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **start**: (type unknown) - Required - The starting node for the DFS traversal. - **end**: (type unknown) - Optional - The node at which to stop the traversal. - **condition**: (callable) - Optional - A callable that takes associated data and returns False to stop traversal for that node. - **forward**: (boolean) - Optional - If True, traverse edges in the forward direction; otherwise, traverse in reverse. Defaults to True. ### Response #### Success Response - Yields associated data for nodes during DFS traversal. ``` -------------------------------- ### Directed and Non-Directed Graph Creation Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Shows how to create both directed and non-directed graphs using the Dot class by specifying the 'graphtype' parameter. ```python # create directed graph(default) dot = Dot.Dot(graph, graphtype="digraph") # create non-directed graph dot = Dot.Dot(graph, graphtype="graph") ``` -------------------------------- ### Customizing Graph, Node, and Edge Styles Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Illustrates how to customize the appearance of the overall graph, individual nodes, and edges using specific style attributes. Refer to graphviz documentation for available attributes. ```python # customizing the way the overall graph is drawn dot.style(size='10,10', rankdir='RL', page='5, 5' , ranksep=0.75) # customizing node drawing dot.node_style(1, label='BASE_NODE',shape='box', color='blue' ) dot.node_style(2, style='filled', fillcolor='red') # customizing edge drawing dot.edge_style(1, 2, style='dotted') dot.edge_style(3, 5, arrowhead='dot', label='binds', labelangle='90') dot.edge_style(4, 5, arrowsize=2, style='bold') ``` -------------------------------- ### ObjectGraph.msgin(level, text, *args) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Prints a debug message and increases the indentation level if the current debug level is less than or equal to the specified level. ```APIDOC ## ObjectGraph.msgin(level, text, \*args) Print a debug message when the current debug level is *level* or less, and increase the indentation level. ``` -------------------------------- ### Dot.display Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Displays the current graph using the 'dotty' command. If the mode is 'neato', the dot file is processed with the 'neato' command before displaying. This method blocks until the 'dotty' command exits. ```APIDOC ## Dot.display() ### Description Displays the current graph via dotty. If the *mode* is `"neato"` the dot file is processed with the neato command before displaying. This method won’t return until the dotty command exits. ### Method GET (or relevant method for display action) ### Endpoint `/display` (conceptual endpoint for display action) ``` -------------------------------- ### altgraph.Graph.Graph() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Constructs a new empty Graph object. Optionally, it can be initialized with a list of edges. ```APIDOC ## altgraph.Graph.Graph() ### Description Constructs a new empty [`Graph`](#altgraph.Graph.Graph) object. If the optional *edges* parameter is supplied, updates the graph by adding the specified edges. All of the elements in *edges* should be tuples with two or three elements. The first two elements of the tuple are the source and destination node of the edge, the optional third element is the edge data. The source and destination nodes are added to the graph when they aren’t already present. ### Method CONSTRUCTOR ### Parameters #### Optional Parameters - **edges** (list of tuples) - Optional - A list of tuples, where each tuple represents an edge. Tuples can have two elements (source, destination) or three elements (source, destination, edge_data). ``` -------------------------------- ### ObjectGraph.createNode(cls, name, *args, **kwds) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Creates a new node using the provided class and arguments, then adds it to the graph. Returns the newly created node. ```APIDOC ## ObjectGraph.createNode(self, cls, name, \*args, \*\*kwds) Creates a new node using `cls(*args, **kwds)` and adds that node using [`addNode()`](#altgraph.ObjectGraph.ObjectGraph.addNode). Returns the newly created node. ``` -------------------------------- ### Graph.forw_topo_sort() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Performs a forward topological sort on the graph, returning a list of nodes in a valid order. ```APIDOC ## Graph.forw_topo_sort() ### Description Return a list of nodes where the successors (based on outgoing edges) of any given node appear in the sequence after that node. ### Method FORW_TOPO_SORT ### Returns - (list) - A list of nodes in a topologically sorted order. ``` -------------------------------- ### altgraph.GraphUtil.generate_random_graph Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphutil.md Generates a graph with a specified number of nodes and edges, with options for self-loops and multi-edges. ```APIDOC ## altgraph.GraphUtil.generate_random_graph(node_num, edge_num[, self_loops[, multi_edges]]) ### Description Generates and returns a [`Graph`](graph.md#altgraph.Graph.Graph) instance with *node_num* nodes randomly connected by *edge_num* edges. When *self_loops* is present and True there can be edges that point from a node to itself. When *multi_edge* is present and True there can be duplicate edges. This method raises `GraphError `_) input file (including line endings). ### Returns An iterator yielding strings, where each string is a line from the dot file. ``` -------------------------------- ### altgraph.GraphUtil.generate_scale_free_graph Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphutil.md Generates a graph with a scale-free (powerlaw) connectivity. ```APIDOC ## altgraph.GraphUtil.generate_scale_free_graph(steps, growth_num) ### Description Generates and returns a [`Graph`](graph.md#altgraph.Graph.Graph) instance that will have *steps* *growth_num* nodes and a scale free (powerlaw) connectivity. Starting with a fully connected graph with *growth_num* nodes at every step *growth_num* nodes are added to the graph and are connected to existing nodes with a probability proportional to the degree of these existing nodes. #### WARNING The current implementation is basically untested, although code inspection seems to indicate an implementation that is consistent with the description at [Wolfram MathWorld](http://mathworld.wolfram.com/Scale-FreeNetwork.html) ### Parameters #### Path Parameters - **steps** (int) - Required - The number of steps to add nodes. - **growth_num** (int) - Required - The number of nodes to add at each step. ``` -------------------------------- ### Graph.describe_edge(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Provides detailed information about an edge, including its data, head, and tail. ```APIDOC ## Graph.describe_edge(edge) ### Description Return the *edge*, the associated data, its head and tail. ### Method DESCRIBE_EDGE ### Parameters - **edge** (any) - Required - The edge to describe. ### Returns - (tuple) - A tuple containing the edge, its data, head node, and tail node. ``` -------------------------------- ### ObjectGraph Class Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Represents a graph of objects that have a 'graphident' attribute. The graphident serves as the key for each object within the graph. It can optionally take a pre-existing Graph object and a debug level for controlling output. ```APIDOC ## class altgraph.ObjectGraph.ObjectGraph() A graph of objects that have a “graphident” attribute. The value of this attribute is the key for the object in the graph. The optional *graph* is a previously constructed [`Graph`](graph.md#altgraph.Graph.Graph). The optional *debug* level controls the amount of debug output (see [`msg()`](#altgraph.ObjectGraph.ObjectGraph.msg), [`msgin()`](#altgraph.ObjectGraph.ObjectGraph.msgin) and [`msgout()`](#altgraph.ObjectGraph.ObjectGraph.msgout)). ``` -------------------------------- ### ObjectGraph.debug Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md The current debug level setting for the ObjectGraph. ```APIDOC ## ObjectGraph.debug The current debug level. ``` -------------------------------- ### Graph.describe_node(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Provides detailed information about a node, including its data and associated edges. ```APIDOC ## Graph.describe_node(node) ### Description Returns *node*, the node’s data and the lists of outgoing and incoming edges for the node. ### Method DESCRIBE_NODE ### Parameters - **node** (hashable object) - Required - The node to describe. ### Returns - (tuple) - A tuple containing the node, its data, and lists of outgoing and incoming edges. Note: The edge lists should not be modified. ``` -------------------------------- ### Topological Sort (Backward) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes where successors (based on incoming edges) appear after the node in the sequence. Useful for dependency ordering. ```python graph.back_topo_sort() ``` -------------------------------- ### ObjectGraph.createReferences(fromnode, tonode) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Creates a reference (edge) between two nodes. Nodes can be specified as objects or their graphident. If fromnode is None, tonode becomes a root for the graph. ```APIDOC ## ObjectGraph.createReferences(fromnode, tonode) Creates a reference from *fromnode* to *tonode*. The optional *edge_data* is associated with the edge. *Fromnode* and *tonode* can either be node objects or the graphident values for nodes. When *fromnode* is `None` *tonode* is a root for the graph. ``` -------------------------------- ### Graph.back_topo_sort() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes sorted topologically based on incoming edges. Successors appear after their predecessors in the list. ```APIDOC ## Graph.back_topo_sort() ### Description Return a list of nodes where the successors (based on incoming edges) of any given node appear in the sequence after that node. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters None ### Response #### Success Response - list: A list of nodes in topologically sorted order. ``` -------------------------------- ### ObjectGraph.nodes() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Yields all nodes currently in the graph. ```APIDOC ## ObjectGraph.nodes() Yield all nodes in the graph. ``` -------------------------------- ### ObjectGraph.msg(level, text, *args) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Prints a debug message if the current debug level is less than or equal to the specified level. ```APIDOC ## ObjectGraph.msg(level, text, \*args) Print a debug message at the current indentation level when the current debug level is *level* or less. ``` -------------------------------- ### Graph.connected() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Checks if the graph is connected, meaning every node is reachable from every other node. ```APIDOC ## Graph.connected() ### Description Returns True iff every node in the graph can be reached from every other node. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters None ### Response #### Success Response - boolean: True if the graph is connected, False otherwise. ``` -------------------------------- ### altgraph.GraphUtil.filter_stack Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphutil.md Performs a depth-first walk of the graph and applies filter functions to node data. ```APIDOC ## altgraph.GraphUtil.filter_stack(graph, head, filters) ### Description Perform a depth-first oder walk of the graph starting at *head* and apply all filter functions in *filters* on the node data of the nodes found. Returns (*visited*, *removes*, *orphans*), where * *visited*: the set of visited nodes * *removes*: the list of nodes where the node data doesn’t match all *filters*. * *orphans*: list of tuples (*last_good*, *node*), where node is not in *removes* and one of the nodes that is connected by an incoming edge is in *removes*. *Last_good* is the closest upstream node that is not in *removes*. ### Parameters #### Path Parameters - **graph** (Graph) - Required - The graph to traverse. - **head** (Node) - Required - The starting node for the traversal. - **filters** (list) - Required - A list of filter functions to apply to node data. ``` -------------------------------- ### Graph.__iter__() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Iterates over all nodes in the graph. ```APIDOC ## Graph.__iter__() ### Description Yield all nodes in the graph. ### Method ITER ### Returns - (iterator) - An iterator yielding all nodes in the graph. ``` -------------------------------- ### Check Graph Connectivity Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns True if every node in the graph can be reached from every other node. This indicates a strongly connected graph. ```python graph.connected() ``` -------------------------------- ### altgraph.Dot.save_image Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Saves the current graph representation as an image file. The image is written to a file with the specified base name and a suffix determined by the file type. The default file type is 'gif'. If the mode is 'neato', the dot file is processed with the 'neato' command first. Calling without an argument to save to a default 'out' file is deprecated. ```APIDOC ## altgraph.Dot.save_image(file_name) ### Description Saves the current graph representation as an image file. The output is written into a file whose basename is *file_name* and whose suffix is *file_type*. The *file_type* specifies the type of file to write, the default is `"gif"`. If the *mode* is `"neato"` the dot file is processed with the neato command before displaying. #### NOTE For backward compatibility reasons this method can also be called without an argument, it will then write the graph with a fixed basename (`"out"`). This feature is deprecated and should not be used. ### Parameters #### Path Parameters - **file_name** (str) - Optional - The base name for the output image file. If not provided, defaults to "out" (deprecated). #### Query Parameters - **file_type** (str) - Optional - The type of image file to generate (e.g., "png", "svg"). Defaults to "gif". ``` -------------------------------- ### Depth-First Traversal with Data (Iterative) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Yields associated data for nodes in a depth-first traversal, skipping nodes without data or those failing a condition. Supports stopping at an end node and reverse edge traversal. ```python graph.iterdata(start) ``` -------------------------------- ### ObjectGraph.get_edges(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Returns two iterators for a given node: one for outgoing edges and one for incoming edges. If the node is None, it returns the roots of the graph. The incoming edges iterator might yield None if the node is a graph root. ```APIDOC ## ObjectGraph.get_edges(node) Returns two iterators that yield the nodes reaching by outgoing and incoming edges for *node*. Note that the iterator for incoming edgets can yield `None` when the *node* is a root of the graph. Use `None` for *node* to fetch the roots of the graph. ``` -------------------------------- ### Graph.all_edges(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of all edges (incoming and outgoing) connected to a specified node. ```APIDOC ## Graph.all_edges(node) ### Description Return the list of incoming and outgoing edges for *node*. ### Method ALL_EDGES ### Parameters - **node** (hashable object) - Required - The node for which to retrieve all connected edges. ### Returns - (list) - A list of all incoming and outgoing edges. ``` -------------------------------- ### Graph.node_list() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list containing all visible nodes in the graph. ```APIDOC ## Graph.node_list() ### Description Return a list with all visible nodes in the graph. ### Method NODE_LIST ### Returns - (list) - A list of all visible nodes. ``` -------------------------------- ### ObjectGraph.updateEdgeData(fromNode, toNode, edgeData) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Replaces the data for an existing edge between fromNode and toNode with the provided edgeData. Raises KeyError if the edge does not exist. ```APIDOC ## ObjectGraph.updateEdgeData(fromNode, toNode, edgeData) Replace the data associated with the edge from *fromNode* to *toNode* by *edgeData*. Raises `KeyError` when the edge does not exist. ``` -------------------------------- ### Calculate Local Clustering Coefficient Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the local clustering coefficient of a specific node. This is the proportion of actual edges between neighbors to the maximum possible edges between them. ```python graph.clust_coef(node) ``` -------------------------------- ### Graph.restore_all_nodes() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Restores all nodes that were previously hidden. ```APIDOC ## Graph.restore_all_nodes() ### Description Restores all hidden nodes. ### Method RESTORE_ALL_NODES ``` -------------------------------- ### ObjectGraph.findNode(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Finds and returns a node in the graph. Accepts a node object or its graphident. Returns Node if not found. ```APIDOC ## ObjectGraph.findNode(node) Returns a given node in the graph, or `Node` when it cannot be found. *Node* is either an object with a *graphident* attribute or the *graphident* attribute itself. ``` -------------------------------- ### altgraph.Dot.__iter__ Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Alias for the iterdot() method, providing an alternative way to iterate through the lines of a Graphviz input file. ```APIDOC ## altgraph.Dot.__iter__() ### Description Alias for the [`iterdot()`](#altgraph.Dot.iterdot) method. ### Returns An iterator yielding strings, where each string is a line from the dot file. ``` -------------------------------- ### Graph.edge_by_id(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the head and tail nodes of a given edge ID. ```APIDOC ## Graph.edge_by_id(edge) ### Description Return the head and tail of the *edge*. ### Method EDGE_BY_ID ### Parameters - **edge** (any) - Required - The edge ID. ### Returns - (tuple) - A tuple containing the head and tail nodes of the edge. ``` -------------------------------- ### Graph.head(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the head node of a given edge. ```APIDOC ## Graph.head(edge) ### Description Return the head of an *edge*. ### Method HEAD ### Parameters - **edge** (any) - Required - The edge. ### Returns - (hashable object) - The head node of the edge. ``` -------------------------------- ### Graph.inc_edges(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of all incoming edges to a specified node. ```APIDOC ## Graph.inc_edges(node) ### Description Return the list of incoming edges for *node*. ### Method INC_EDGES ### Parameters - **node** (hashable object) - Required - The node for which to retrieve incoming edges. ### Returns - (list) - A list of incoming edges. ``` -------------------------------- ### Graph.edge_list() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list containing all visible edges in the graph. ```APIDOC ## Graph.edge_list() ### Description Returns a list with all visible edges in the graph. ### Method EDGE_LIST ### Returns - (list) - A list of all visible edges. ``` -------------------------------- ### altgraph.Dot.edge_style Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Sets the style of an edge to the given attributes. The edge will be added to the graph when it isn’t already present, but head and tail must both be valid nodes. Refer to 'Valid Attributes' for more information on attributes. ```APIDOC ## altgraph.Dot.edge_style(head, tail, **attr) ### Description Sets the style of an edge to the given attributes. The edge will be added to the graph when it isn’t already present, but *head* and *tail* must both be valid nodes. See [Valid Attributes]() for more information about the attributes. ### Parameters #### Path Parameters - **head** (Node) - Required - The head node of the edge. - **tail** (Node) - Required - The tail node of the edge. #### Keyword Arguments - **attr** (dict) - Arbitrary keyword arguments representing edge attributes. ``` -------------------------------- ### Graph.all_nbrs(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of all nodes connected to the specified node by either incoming or outgoing edges. ```APIDOC ## Graph.all_nbrs(node) ### Description Returns a list of nodes connected by an incoming or outgoing edge. ### Method ALL_NBRS ### Parameters - **node** (hashable object) - Required - The node for which to find all neighbors. ### Returns - (list) - A list of all connected nodes. ``` -------------------------------- ### ObjectGraph.addNode(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Adds a node to the graph. If the node was previously removed, re-adding it will reinstate it. ```APIDOC ## ObjectGraph.addNode(node) Adds a *node* to the graph. #### NOTE re-adding a node that was previously removed using [`removeNode()`](#altgraph.ObjectGraph.ObjectGraph.removeNode) will reinstate the previously removed node. ``` -------------------------------- ### altgraph.Graph.node_data(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Retrieves the data associated with a specific node. ```APIDOC ## altgraph.Graph.node_data(node) ### Description Return the data associated with the *node* when it was added. ### Method NODE_DATA ### Parameters - **node** (hashable object) - Required - The node whose data is to be retrieved. ### Returns - (any) - The data associated with the node. ``` -------------------------------- ### ObjectGraph.edgeData(fromNode, toNode) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Retrieves the data associated with the edge between fromNode and toNode. Raises KeyError if the edge does not exist. ```APIDOC ## ObjectGraph.edgeData(fromNode, toNode): ### Return the edge data associated with the edge from *fromNode* ### to *toNode*. Raises :exc:`KeyError` when no such edge exists. ``` -------------------------------- ### Graph.restore_all_edges() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Restores all edges that were previously hidden, excluding those connected to hidden nodes. ```APIDOC ## Graph.restore_all_edges() ### Description Restore all edges that were hidden before, except for edges referring to hidden nodes. ### Method RESTORE_ALL_EDGES ``` -------------------------------- ### Graph.tail(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the tail node of a given edge. ```APIDOC ## Graph.tail(edge) ### Description Return the tail of an *edge*. ### Method TAIL ### Parameters - **edge** (any) - Required - The edge. ### Returns - (hashable object) - The tail node of the edge. ``` -------------------------------- ### altgraph.GraphStat.degree_dist Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graphstat.md Calculates the degree distribution of a graph by grouping the number of edges per node into specified bins. It can count incoming or outgoing edges and supports custom limits for binning. ```APIDOC ## altgraph.GraphStat.degree_dist(graph, bin_num=10, limits=None, mode='out') ### Description Groups the number of edges per node into *bin_num* bins and returns the list of those bins. Every item in the result is a tuple with the center of the bin and the number of items in that bin. When the *limits* argument is present it must be a tuple with the mininum and maximum number of edges that get binned (that is, when *limits* is `(4, 10)` only nodes with between 4 and 10 edges get counted). The *mode* argument is used to count incoming (`'inc'`) or outgoing (`'out'`) edges. The default is to count the outgoing edges. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **graph**: The input graph. * **bin_num** (int) - Optional - The number of bins to group the edge counts into. Defaults to 10. * **limits** (tuple) - Optional - A tuple specifying the minimum and maximum number of edges to consider for binning. If `None`, all edges are considered. * **mode** (str) - Optional - Specifies whether to count incoming ('inc') or outgoing ('out') edges. Defaults to 'out'. ``` -------------------------------- ### Graph.inc_nbrs(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes that have direct incoming edges to the specified node. ```APIDOC ## Graph.inc_nbrs(node) ### Description Return a list of all nodes connected by incoming edges. ### Method INC_NBRS ### Parameters - **node** (hashable object) - Required - The node for which to find incoming neighbors. ### Returns - (list) - A list of nodes connected by incoming edges. ``` -------------------------------- ### Graph.all_degree(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the total number of edges (incoming and outgoing) connected to a specified node. ```APIDOC ## Graph.all_degree(node) ### Description Return the number of edges (incoming or outgoing) for *node*. ### Method ALL_DEGREE ### Parameters - **node** (hashable object) - Required - The node for which to calculate the total degree. ### Returns - (int) - The total number of edges connected to the node. ``` -------------------------------- ### Graph.update_edge_data(edge, data) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Replaces the data associated with an existing edge. ```APIDOC ## Graph.update_edge_data(edge, data) ### Description Replace the edge data for *edge* by *data*. Raises `KeyError` when the edge does not exist. ### Method UPDATE_EDGE_DATA ### Parameters - **edge** (any) - Required - The edge whose data is to be updated. - **data** (any) - Required - The new data to associate with the edge. ``` -------------------------------- ### Graph.out_nbrs(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of nodes directly reachable from the specified node via outgoing edges. ```APIDOC ## Graph.out_nbrs(node) ### Description Return a list of all nodes connected by outgoing edges. ### Method OUT_NBRS ### Parameters - **node** (hashable object) - Required - The node for which to find outgoing neighbors. ### Returns - (list) - A list of nodes connected by outgoing edges. ``` -------------------------------- ### Graph.number_of_nodes() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the count of visible nodes currently in the graph. ```APIDOC ## Graph.number_of_nodes() ### Description Return the number of visible nodes in the graph. ### Method NUMBER_OF_NODES ### Returns - (int) - The number of visible nodes. ``` -------------------------------- ### Graph.add_node(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Adds a new node to the graph. Arbitrary data can be attached to the node. ```APIDOC ## Graph.add_node(node) ### Description Adds a new node to the graph if it is not already present. The new node must be a hashable object. Arbitrary data can be attached to the node via the optional *node_data* argument. ### Method ADD_NODE ### Parameters - **node** (hashable object) - Required - The node to add to the graph. - **node_data** (any) - Optional - Arbitrary data to associate with the node. ``` -------------------------------- ### Graph.add_edge(head_id, tail_id) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Adds a directed edge between two nodes. Nodes are created if they do not exist. ```APIDOC ## Graph.add_edge(head_id, tail_id) ### Description Adds a directed edge from *head_id* to *tail_id*. Arbitrary data can be added via *edge_data*. When *create_nodes* is *True* (the default), *head_id* and *tail_id* will be added to the graph when they aren’t already present. ### Method ADD_EDGE ### Parameters - **head_id** (hashable object) - Required - The source node of the edge. - **tail_id** (hashable object) - Required - The destination node of the edge. - **edge_data** (any) - Optional - Arbitrary data to associate with the edge. - **create_nodes** (bool) - Optional - If True (default), creates head_id and tail_id if they don't exist. ``` -------------------------------- ### Graph.restore_edge(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Restores a previously hidden edge. ```APIDOC ## Graph.restore_edge(edge) ### Description Restores a previously hidden *edge*. ### Method RESTORE_EDGE ### Parameters - **edge** (any) - Required - The edge to restore. ``` -------------------------------- ### Graph.number_of_edges() Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns the count of visible edges currently in the graph. ```APIDOC ## Graph.number_of_edges() ### Description Return the number of visible edges. ### Method NUMBER_OF_EDGES ### Returns - (int) - The number of visible edges. ``` -------------------------------- ### ObjectGraph.filterStack(filters) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Filters the ObjectGraph in-place by removing edges to nodes that do not match all provided filters. Returns a tuple of (nodes_visited, nodes_removed, nodes_orphaned). ```APIDOC ## ObjectGraph.filterStack(filters) Filter the ObjectGraph in-place by removing all edges to nodes that do not match every filter in the given filter list Returns a tuple containing the number of: (*nodes_visited*, *nodes_removed*, *nodes_orphaned*) ``` -------------------------------- ### altgraph.Dot.save_dot Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/dot.md Saves the current graph representation into the specified file. For backward compatibility, it can be called without an argument to write to a fixed temporary file, though this usage is deprecated. ```APIDOC ## altgraph.Dot.save_dot(filename) ### Description Saves the current graph representation into the given file. #### NOTE For backward compatibility reasons this method can also be called without an argument, it will then write the graph into a fixed filename (present in the attribute `Graph.temp_dot`). This feature is deprecated and should not be used. ### Parameters #### Path Parameters - **filename** (str) - Optional - The name of the file to save the graph to. If not provided, a default temporary file is used (deprecated). ``` -------------------------------- ### Graph.out_edges(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Returns a list of all outgoing edges from a specified node. ```APIDOC ## Graph.out_edges(node) ### Description Return the list of outgoing edges for *node*. ### Method OUT_EDGES ### Parameters - **node** (hashable object) - Required - The node for which to retrieve outgoing edges. ### Returns - (list) - A list of outgoing edges. ``` -------------------------------- ### ObjectGraph.graph Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md An attribute that holds the Graph object containing the graph data. ```APIDOC ## ObjectGraph.graph An [`Graph`](graph.md#altgraph.Graph.Graph) object that contains the graph data. ``` -------------------------------- ### Graph.edge_data(edge) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Retrieves the data associated with a specific edge. ```APIDOC ## Graph.edge_data(edge) ### Description Return the data associated with the *edge*. ### Method EDGE_DATA ### Parameters - **edge** (any) - Required - The edge for which to retrieve data. ### Returns - (any) - The data associated with the edge. ``` -------------------------------- ### Graph.restore_node(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Restores a previously hidden node and its associated edges. ```APIDOC ## Graph.restore_node(node) ### Description Restores a previously hidden *node*. The incoming and outgoing edges of the node are also restored. ### Method RESTORE_NODE ### Parameters - **node** (hashable object) - Required - The node to restore. ``` -------------------------------- ### Graph.clust_coef(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Calculates the local clustering coefficient for a given node, representing the proportion of actual edges between its neighbors compared to the maximum possible edges. ```APIDOC ## Graph.clust_coef(node) ### Description Returns the local clustering coefficient of node. The local cluster coefficient is the proportion of the actual number of edges between neighbours of node and the maximum number of edges between those nodes. ### Method N/A (Method call) ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **node**: (type unknown) - Required - The node for which to calculate the clustering coefficient. ### Response #### Success Response - float: The local clustering coefficient of the node. ``` -------------------------------- ### ObjectGraph.__contains__(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Checks if a node is present in the graph. Accepts a node object or its graphident. ```APIDOC ## ObjectGraph.__contains__(node) Returns True if *node* is a member of the graph. *Node* is either an object with a *graphident* attribute or the *graphident* attribute itself. ``` -------------------------------- ### altgraph.ObjectGraph.getIdent(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Returns the graphident of a node if it is part of the graph. Accepts either a node object or its graphident. ```APIDOC ## altgraph.ObjectGraph.getIdent(node) Same as `getRawIdent()`, but only if the node is part of the graph. *Node* can either be an actual node object or the graphident of a node. ``` -------------------------------- ### ObjectGraph.getRawIdent(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/objectgraph.md Returns the graphident attribute of a node. If the node is None, it returns the graph itself. ```APIDOC ## ObjectGraph.getRawIdent(node) Returns the *graphident* attribute of *node*, or the graph itself when *node* is `None`. ``` -------------------------------- ### Graph.__contains__(node) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Checks if a node exists in the graph using the 'in' operator. ```APIDOC ## Graph.__contains__(node) ### Description Returns True iff *node* is a node in the graph. This method is accessed through the *in* operator. ### Method CONTAINS ### Parameters - **node** (hashable object) - Required - The node to check for. ### Returns - (bool) - True if the node is in the graph, False otherwise. ``` -------------------------------- ### Graph.edge_by_node(head, tail) Source: https://github.com/ronaldoussoren/altgraph/blob/master/doc/graph.md Retrieves the edge ID for an edge between two specified nodes. ```APIDOC ## Graph.edge_by_node(head, tail) ### Description Return the edge ID for an edge from *head* to *tail*, or `None` when no such edge exists. ### Method EDGE_BY_NODE ### Parameters - **head** (hashable object) - Required - The source node of the edge. - **tail** (hashable object) - Required - The destination node of the edge. ### Returns - (any or None) - The edge ID if the edge exists, otherwise None. ```