MultiGraph
Base class for undirected multigraphs.
Self-loops and multiedges are allowed.
Attributes
- edges
-
Returns the edges of the graph.
- nodes
-
Returns the nodes of the graph.
Methods
|
Method Name |
Description |
|---|---|
|
Computes the core numbers and stores the results as node attributes on the graph. | |
|
Adds a single edge to the graph. | |
|
Adds edges to the graph. | |
|
Adds a node to the graph. | |
|
Adds the specified nodes to the graph. | |
|
Computes a topological ordering and stores the results as node attributes of the graph. | |
|
Adds weighted edges to the graph. | |
|
Returns an iterator over (node, adjacency dict) for all nodes. | |
|
Specifies whether or not the graph allows multiedges. | |
|
Specifies whether or not the graph allows self-loops. | |
|
Applies a function to all node or edge attributes and updates them. | |
|
Computes an approximation of the graph’s diameter. | |
|
Computes a graph’s articulation point count. | |
|
Finds the articulation points (cut points) of a graph. | |
|
Computes a graph’s degree assortativity. | |
|
Computes a graph’s nominal assortativity. | |
|
Computes a graph’s numeric assortativity. | |
|
Computes a graph’s average shortest path. | |
|
Computes the distribution of the number of edges in each biconnected components by using numpy.histogram. | |
|
Computes the distribution of the number of nodes in each biconnected components by using numpy.histogram. | |
|
Computes the number of edges within each biconnected component. | |
|
Computes the number of nodes within each biconnected component. | |
|
Computes a graph’s biconnected component count. | |
|
Computes the graph’s biconnected components for an undirected graph. | |
|
Computes the block-cut tree of a graph. | |
|
Computes weighted or unweighted betweenness centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted closeness centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted degree centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted eigenvector centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted hub and authority centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted influence centrality and stores the results as attributes on the graph. | |
|
Computes weighted or unweighted PageRank centrality and stores the results as attributes on the graph. | |
|
Removes all nodes and edges from the graph. | |
|
Removes all edges from the graph but retains nodes. | |
|
Computes the distribution of the number of edges in each connected component by using numpy.histogram. | |
|
Computes the distribution of the number of nodes in each connected component by using numpy.histogram. | |
|
Computes the number of edges within each connected component. | |
|
Computes the number of nodes within each connected component. | |
|
Computes a graph’s connected component count. | |
|
Computes the connected components of a graph. | |
|
Returns a copy of the input graph. | |
|
Computes a core decomposition of the graph. | |
|
Counts the number of cycles in a graph. | |
|
Returns the degree of nodes. | |
|
Computes the density of the graph. | |
|
Computes a graph’s diameter. | |
|
Removes edge attributes if they exist. | |
|
Removes node attributes if they exist. | |
|
Enumerates the cycles in a graph and returns the edges of the cycles. | |
|
Enumerates the cycles in a graph and returns the nodes of the cycles. | |
|
Enumerates the cycles in a graph and returns the cycle graph objects. | |
|
Enumerates the paths in a graph and returns the edges of the paths. | |
|
Enumerates the paths in a graph and returns the nodes of the paths. | |
|
Enumerates the paths in a graph and returns the Path graph objects. | |
|
Enumerates the shortest paths in a graph that visit the indicated sequence nodes in order. | |
|
Enumerates the shortest paths in a graph and returns the edges of the paths. | |
|
Enumerates the shortest paths in a graph and returns the nodes of the paths. | |
|
Enumerates the shortest paths in a graph and returns the Path graph objects. | |
|
Constructs a metagraph from the input graph. | |
|
Returns a list of up to n largest biconnected components. | |
|
Returns a list of up to n largest connected (with highest number of nodes) components of a graph. | |
|
Checks the edges of the input graph for the specified edge attribute. | |
|
Checks the nodes of the input graph for the specified node attribute. | |
|
Returns the intersection of input graphs by finding the intersections of their nodes and edges. | |
|
Specifies whether or not the input graph is biconnected. | |
|
Determines whether the input graph is bipartite. | |
|
Specifies whether or not the input graph is connected. | |
|
Determines whether the input graph is a simple cycle. | |
|
Determines whether the input graph is a directed acyclic graph (DAG). | |
|
Specifies whether or not the graph is directed. | |
|
Determines whether the graph is Hamiltonian (has a Hamiltonian cycle) or not. | |
|
Specifies whether or not the graph is immutable. | |
|
Specifies whether or not the graph allows multiedges. | |
|
Determines whether the input graph is a simple path. | |
|
Specifies whether the input graph is strongly connected. | |
|
Specifies whether the input graph is weakly connected. | |
|
Computes the communities of the graph by using the label propagation algorithm. | |
|
Computes community assignments for all nodes in the graph by using the label propagation algorithm. | |
|
Computes a graph’s leaf node count. | |
|
Computes the local transitivity (clustering coefficient) and stores the results as node attributes on the graph. | |
|
Computes the communities of the graph by using the Louvain algorithm. | |
|
Computes community assignments for all nodes in the graph by using the Louvain algorithm. | |
|
Calculates the maximum flow from a source node to a sink node in a graph. | |
|
Enumerates all maximal cliques of the graph. | |
|
Calculates a minimum cut of a graph. | |
|
Calculates a minimum s-t cut of a graph. | |
|
Calculates the minimum-cost network flow for the graph. | |
|
Calculates a minimum spanning tree (MST) or forest of a graph. | |
|
Returns a minimum-weight full matching of the bipartite graph self. | |
|
Returns an iterator over all neighbors of node n. | |
|
Returns an unused key for the edges between nodes u and v. | |
|
Computes node clique numbers and stores the results as attributes on the graph. | |
|
Returns the number of edges in the graph. | |
|
Returns the number of nodes in the graph. | |
|
Computes a projected graph. | |
|
Computes an Adamic-Adar projected graph. | |
|
Computes a common neighbors projected graph. | |
|
Computes a cosine projected graph. | |
|
Computes a Sørensen-Dice projected graph. | |
|
Computes a Jaccard projected graph. | |
|
Queries for the subgraph isomorphisms of q within g. | |
|
Computes the reach graph for the source or set of sources. | |
|
Computes a separate reach graph for each given source node. | |
|
Removes a single edge from the graph. | |
|
Removes edges from the graph. | |
|
Removes isolated nodes from a graph. | |
|
Removes a single node from the graph. | |
|
Removes nodes from the graph. If a node does not exist in the graph, it is silently ignored. | |
|
Sets edge attributes by using a given value or dictionary of values. | |
|
Sets node attributes from a given value or dictionary of values. | |
|
Calculates the shortest path distances in a graph. | |
|
Computes Adamic-Adar node similarity. | |
|
Computes common neighbors node similarity. | |
|
Computes cosine node similarity. | |
|
Computes Sørensen-Dice node similarity. | |
|
Computes a node similarity graph. | |
|
Computes an Adamic-Adar node similarity graph. | |
|
Computes a common neighbors node similarity graph. | |
|
Computes a cosine node similarity graph. | |
|
Computes a Sørensen-Dice node similarity graph. | |
|
Computes a Jaccard node similarity graph. | |
|
Computes Jaccard node similarity. | |
|
Computes a graph’s singleton node count. | |
|
Returns a directed copy of the input graph. | |
|
Creates an immutable graph from the input graph. | |
|
Creates a mutable graph from the input graph. | |
|
Returns the graph edges as a Pandas DataFrame. | |
|
Returns the graph nodes as a Pandas DataFrame. | |
|
Returns a directed copy of the input graph. | |
|
Finds a topological ordering of the graph’s nodes. | |
|
Calculates the transitive closure of a graph. | |
|
Computes a graph’s triangle count. | |
|
Calculates a traveling salesman problem (TSP) tour of a graph. | |
|
Returns the union of input graphs by finding the unions of their nodes and edges. | |
|
Solves the vehicle routing problem. | |
|
Solves the vehicle routing problem with time windows. |
add_core_number_attr()
Computes the core numbers and stores the results as node attributes on the graph.
Parameters
- maxtime : float or None, optional
-
Specifies the maximum amount of time for core decomposition to spend. The default is None.
- inplace : bool, optional
-
Specifies whether to add the core numbers as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph with core numbers that are stored as a node attribute named core. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
add_edge()
Adds a single edge to the graph.
Parameters
- u : numeric or str
-
Specifies the from node.
- v : numeric or str
-
Specifies the to node.
- key : numeric or str
-
Specifies the key of the edge to add to the graph. The default is None.
Returns
- numeric or str
-
Returns the key of the edge that is added to the graph.
Examples
G.add_edge(1,2,key='A',weight=3,type='parent')
add_edges_from()
Adds edges to the graph.
Parameters
- edges : an iterable container of edges
-
Specifies the edges to add to the graph.
Returns
- list
-
Returns the keys of the edges that are added to the graph.
Examples
G.add_edges_from([("A","B",0,{"weight":1,"color":"blue"}),
("C","D",0,{"weight":2,"color":"red"})])
G.add_edges_from([["X","Y",0],["Y","Z",0], weight=1,color= "blue")
add_node()
Adds a node to the graph.
Parameters
- node : str or number or tuple
-
Specifies the ID of the node to add to the graph. If the value is a tuple, the first element should contain the node ID, and the second element is a dictionary that represents the node’s attributes.
add_nodes_from()
Adds the specified nodes to the graph.
Parameters
- nodes : an iterable container of nodes
-
Specifies the nodes to add to the graph.
Examples
G.add_nodes_from([('X', {"weight":11,"color": "blue"}), ("Y", {"color": "blue"})])
G.add_nodes_from(('X', 'Y'), weight=1,color= "blue")
G.add_nodes_from(['X', 'Y'])
add_topological_order_attr()
Computes a topological ordering and stores the results as node attributes of the graph.
Parameters
- inplace : bool, optional
-
Specifies whether or not to add the topological order values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a directed graph whose topological order is stored as a node attribute named top_order. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
add_weighted_edges_from()
Adds weighted edges to the graph.
Parameters
- edges : an iterable container of edges
-
Specifies the weighted edges to add to the graph.
- weight : str
-
Specifies the attribute name for the weighted edges to add. The default is ‘weight’.
adjacency()
Returns an iterator over (node, adjacency dict) for all nodes.
For directed graphs, only outgoing adjacencies are returned.
Returns
- iterator
-
Returns an iterator over (node, adjacency dictionary) for all nodes in the graph.
allows_multiedges()
Specifies whether or not the graph allows multiedges.
Returns
- bool
-
Indicates whether or not the graph allows multiedges.
allows_selfloops()
Specifies whether or not the graph allows self-loops.
Returns
- bool
-
Indicates whether or not the graph allows self-loops.
apply()
Applies a function to all node or edge attributes and updates them.
#use apply to fillna >>> sasnet.apply(G, edge_attr_handler=lambda data:{‘w’:0 if ‘w’ not in data else data[‘w’]},inplace=True) >>> assert G.edges[(1,2)][‘w’] == 0 >>> print(G.nodes(data=True)) #use apply to negate an attribute >>> sasnet.apply(G, node_attr_handler=lambda data:{‘x’: -data[‘x’]},inplace=True) >>> assert G.nodes[1][‘x’]== -10
Parameters
- node_attr_handler : function or None, optional
-
Specifies the function to apply to node attributes. The default is None.
- edge_attr_handler : function or None, optional
-
Specifies the function to apply to edge attributes. The default is None.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not to modify the input graph. The default is False.
Returns
- SAS graph object or None.
-
Returns the resulting graph after the function is applied, or returns nothing if the inplace parameter value is True.
Examples
import sasviya.network as sasnet
G = sasnet.Graph([[1,2,{}],[1,3,{'w':1}],[1,4,{'w':2}]])
sasnet.set_node_attributes(G,{1:10,2:20,3:30,4:40},name='x',inplace=True)
#use apply to fillna >>> sasnet.apply(G, edge_attr_handler=lambda data:{‘w’:0 if ‘w’ not in data else data[‘w’]},inplace=True) >>> assert G.edges[(1,2)][‘w’] == 0 >>> print(G.nodes(data=True)) #use apply to negate an attribute >>> sasnet.apply(G, node_attr_handler=lambda data:{‘x’: -data[‘x’]},inplace=True) >>> assert G.nodes[1][‘x’]== -10
approximate_diameter()
Computes an approximation of the graph’s diameter.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted approximate diameter is computed.
Returns
- float
-
Returns the approximate diameter.
articulation_point_count()
Computes a graph’s articulation point count.
Returns
- int
-
Returns the number of articulation points.
articulation_points()
Finds the articulation points (cut points) of a graph.
Returns
- list
-
Returns a list of articulation points in the graph.
assortativity_degree()
Computes a graph’s degree assortativity.
Parameters
- source_direction : {‘in’, ‘out’}
-
Specifies the degree type (in-degree or out-degree) for the source node in a directed graph.
- target_direction : {‘in’, ‘out’}
-
Specifies the degree type (in-degree or out-degree) for the target node in a directed graph.
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted assortativity degree is computed.
Returns
- float
-
Returns the degree assortativity.
assortativity_nominal()
Computes a graph’s nominal assortativity.
Parameters
- node_attr : str
-
Specifies the name of the nominal node attribute to use.
Returns
- float
-
Returns the nominal assortativity.
assortativity_numeric()
Computes a graph’s numeric assortativity.
Parameters
- node_attr : str
-
Specifies the name of the numeric node attribute to use.
Returns
- float
-
Returns the numeric assortativity.
average_shortest_path()
Computes a graph’s average shortest path.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted average shortest path is computed.
Returns
- float
-
Returns the average shortest path.
biconcomp_distribution_edges()
Computes the distribution of the number of edges in each biconnected components by using numpy.histogram.
Parameters
- bins : int or list or str or None, optional
-
Specifies the bins for the distribution calculation. The default is None. When bins is None, bins are defined as the list of unique component sizes. When bins is int (an integer), it specifies the number of equal-width bins. When bins is a list, it specifies bin ranges and should be monotonically increasing. For example, a value of [a1, a2, a3, a4] results in the following bin ranges: [a1, a2) (inclusive of a1 but exclusive of a2), [a2, a3), and [a3, a4]. When bins is str (a string), it specifies the method to use for calculating the bin ranges. For example, ‘stone’,’auto’,’doane’,’fd’,’rice’,’scott’,’sqrt’,’sturges’. See https://numpy.org/doc/stable/reference/generated/numpy.histogram.html for more information about the bins parameter.
Returns
- dict
-
Returns a dictionary where the key is the bin’s lower-bound value and the value is the number of biconnected components whose edge count is within the range of the bin.
biconcomp_distribution_nodes()
Computes the distribution of the number of nodes in each biconnected components by using numpy.histogram.
Parameters
- bins : int or list or str or None, optional
-
Specifies the bins for the distribution calculation. The default is None. When bins is None, bins are defined as the list of unique component sizes. When bins is int (an integer), it specifies the number of equal-width bins. When bins is a list, it specifies bin ranges and should be monotonically increasing. For example, a value of [a1, a2, a3, a4] results in the following bin ranges: [a1, a2) (inclusive of a1 but exclusive of a2), [a2, a3), and [a3, a4]. When bins is str (a string), it specifies the method to use for calculating the bin ranges. For example, ‘stone’,’auto’,’doane’,’fd’,’rice’,’scott’,’sqrt’,’sturges’. See https://numpy.org/doc/stable/reference/generated/numpy.histogram.html for more information about the bins parameter.
Returns
- dict
-
Returns a dictionary where the key is the bin’s lower-bound value and the value is the number of biconnected components whose node count is within the range of the bin.
biconcomp_size_edges()
Computes the number of edges within each biconnected component.
Returns
- dict
-
Returns a dictionary in which the keys are biconnected component IDs and the values are the number of edges within each component.
biconcomp_size_nodes()
Computes the number of nodes within each biconnected component.
Returns
- dict
-
Returns a dictionary in which the keys are biconnected component IDs and the values are the number of nodes within each component.
biconnected_component_count()
Computes a graph’s biconnected component count.
Returns
- int
-
Returns the number of biconnected components.
biconnected_components()
Computes the graph’s biconnected components for an undirected graph.
Parameters
- order_by : ‘node’ or ‘edge’ or None, optional
-
Specifies the parameter that is used to sort the components by the number of nodes or edges within each component. The default is None, which means that the components are not sorted.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
- ascending : bool, optional
-
Specifies whether to sort in ascending or descending order, when you specify the order_by parameter. The default is False.
Yields
- generator
-
Returns the result as a generator of biconnected component subgraphs. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
block_cut_tree()
Computes the block-cut tree of a graph.
Parameters
- return_nodes_map : bool, optional
-
Specifies whether or not to also compute the block-cut tree node map. The default is False.
Returns
- SAS graph object
-
Returns a graph that represents the block-cut tree. When return_nodes_map = True, the output graph has the nodes_map attribute, which contains a dictionary that maps its nodes to a list of nodes in the original graph. Note: If a block is empty (that is, the corresponding biconnected component contains only articulation points), that block does not appear as a key in the nodes_map dictionary.
centrality_betweenness()
Computes weighted or unweighted betweenness centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that unweighted betweenness centrality is computed.
- sample_percent : int, optional
-
Specifies the percentage of source nodes to sample for the approximate betweenness calculation. This parameter value should be in the range (0, 100]. The default is 100.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the node and edge attributes between_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_closeness()
Computes weighted or unweighted closeness centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted closeness centrality is computed.
- nopath : {‘diameter’, ‘harmonic’, or ‘zero’}, optional
-
Specifies a method to use for accounting for the shortest path distance between two nodes when a path does not exist. The valid values are as follows: - ‘diameter’ uses the graph diameter (plus one) as the shortest path distance between disconnected nodes. - ‘harmonic’ uses the harmonic formula for calculating closeness centrality. - ‘zero’ uses zero as the shortest path distance between disconnected nodes.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the closeness centrality node attributes centr_close_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_degree()
Computes weighted or unweighted degree centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted degree centrality is computed.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the degree centrality node attributes centr_degree_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_eigenvector()
Computes weighted or unweighted eigenvector centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted eigenvector centrality is computed.
- maxiters : int, optional
-
Specifies the maximum number of iterations in order to limit the amount of computation time that is spent when convergence is slow. The default is 10,000.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the degree centrality node attributes centr_eigen_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_hub_authority()
Computes weighted or unweighted hub and authority centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted hub and authority centrality is computed.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the hub and authority centrality node attributes centr_hub_* and centr_auth_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_influence()
Computes weighted or unweighted influence centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted influence centrality is computed.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the first- and second-order influence centrality node attributes centr_influence1_* and centr_influence2_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
centrality_pagerank()
Computes weighted or unweighted PageRank centrality and stores the results as attributes on the graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that unweighted PageRank centrality is computed.
- alpha : float, optional
-
Specifies the damping parameter for the PageRank centrality (or algorithm). The default is 0.85.
- tolerance : float, optional
-
Specifies the tolerance parameter for the PageRank centrality (or algorithm). The default is 1E-9.
- inplace : bool, optional
-
Specifies whether to add the centrality values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that contains the PageRank centrality node attributes centr_pagerank_*. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
clear()
Removes all nodes and edges from the graph.
clear_edges()
Removes all edges from the graph but retains nodes.
concomp_distribution_edges()
Computes the distribution of the number of edges in each connected component by using numpy.histogram.
Parameters
- bins : int or list or str, optional
-
Specifies the bins for the distribution calculation. The default is None. When bins is None, bins are defined as the list of unique component sizes. When bins is an integer (int), it represents the number of equal-width bins. When bins is a list, it specifies bin ranges and it should be monotonically increasing. For example, a value of [a1, a2, a3, a4] results in the following bin ranges: [a1, a2) (inclusive of a1 but exclusive of a2), [a2, a3), and [a3, a4]. When bins is a string (str), it specifies the method to be used for calculating the bin ranges. For example, ‘stone’, ‘auto’, ‘doane’, ‘fd’, ‘rice’, ‘scott’, ‘sqrt’, ‘sturges’. See https://numpy.org/doc/stable/reference/generated/numpy.histogram.html for more information about the bins parameter.
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
Returns
- dict
-
Returns a dictionary where the key is the bin’s lower-bound value and the value is the number of components whose edge count within the range of the bin.
concomp_distribution_nodes()
Computes the distribution of the number of nodes in each connected component by using numpy.histogram.
Parameters
- bins : int or list or str or None, optional
-
Specifies the bins for the distribution calculation. The default is None. When bins is None, bins are defined as the list of unique component sizes. When bins is an integer (int), it represents the number of equal-width bins. When bins is a list, it specifies bin ranges and it should be monotonically increasing. For example, a value of [a1, a2, a3, a4] results in the following bin ranges: [a1, a2) (inclusive of a1 but exclusive of a2), [a2, a3), and [a3, a4]. When bins is a string (str), it specifies the method to use for calculating the bin ranges. For example, ‘stone’, ‘auto’, ‘doane’, ‘fd’, ‘rice’, ‘scott’, ‘sqrt’, ‘sturges’. See https://numpy.org/doc/stable/reference/generated/numpy.histogram.html for more information about the bins parameter.
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
Returns
- dict
-
Returns a dictionary where the key is the bin’s lower-bound value and the value is the number of components whose node count is within the range of the bin.
concomp_size_edges()
Computes the number of edges within each connected component.
Parameters
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
Returns
- dict
-
Returns a dictionary in which the keys are connected component IDs and the values are the number of edges within each component.
concomp_size_nodes()
Computes the number of nodes within each connected component.
Parameters
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
Returns
- dict
-
Returns a dictionary in which the keys are connected component IDs and the values are the number of nodes within each component.
connected_component_count()
Computes a graph’s connected component count.
Returns
- int
-
Returns the number of connected components.
connected_components()
Computes the connected components of a graph.
Parameters
- order_by : ‘node’ or ‘edge’ or None, optional
-
Specifies whether to sort the components by the number of nodes or edges within each component. The default is None, which means that the components are not sorted.
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
- ascending : bool, optional
-
Specifies whether to sort in ascending or descending order, when you specify the order_by parameter. The default is False.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one connected component. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
copy()
Returns a copy of the input graph.
Parameters
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, meaning that the node and edge attributes of the graph are retained.
Returns
- SAS graph object
-
Returns an independent copy of the input.
core_decomposition()
Computes a core decomposition of the graph.
Parameters
- maxtime : float or None, optional
-
Specifies the maximum amount of time for core decomposition to spend. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one k-core in increasing core number. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
cycle_count()
Counts the number of cycles in a graph.
Parameters
- maxcycles : int or ‘ALL’, optional
-
Specifies the maximum number of cycles to count. The default is ‘ALL’.
- minlength : int, optional
-
Specifies the minimum number of edges in cycles that are counted. The default is 1.
- maxlength : int, optional
-
Specifies the maximum number of edges in cycles that are counted. The default is None.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None. When the value is None, a weight of 1 is assumed for all nodes.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None. When the value is None, a weight of 1 is assumed for all edges.
- minedgewt : float or None, optional
-
Specifies the minimum sum of edge weights in a cycle. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum sum of edge weights in a cycle. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum sum of node weights in a cycle. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum sum of node weights in a cycle. The default is None.
- maxtime : float or None, optional
-
Specifies the approximate maximum number of seconds to spend on enumeration. The default is None.
- source : node or None, optional
-
Specifies the source node for cycle calculations. The default is None.
Returns
- int
-
Returns a count of cycles in the graph.
degree()
Returns the degree of nodes.
Parameters
- n : single node or container of nodes or None, optional
-
Specifies which nodes to include. The default is None, which means that the degree of every node is returned.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None.
Returns
- int or dictionary
-
Returns the degree of specified node(s).
density()
Computes the density of the graph.
Returns
- float
-
Returns the density of the graph.
diameter()
Computes a graph’s diameter.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted diameter is computed.
Returns
- int or float
-
Returns the diameter.
drop_edge_attributes()
Removes edge attributes if they exist.
Parameters
- attributes_subset : str or list, optional
-
Specifies the edge attribute or a list of the edge attributes to remove; for example, ‘weight’ or [‘weight’,’color’]. By default, all edge attributes are removed.
- edges_subset : list or iterable of edges, optional
-
Specifies the edges to remove attributes from; for example, [(1,2),(2,3)]. By default the attributes for all edges are removed.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
Returns
- SAS graph object or None
-
If the inplace parameter value is True, the graph is modified by removing the specified edge attributes. If the inplace parameter value is False, a copy of the input graph with the modified edge attributes is returned.
drop_node_attributes()
Removes node attributes if they exist.
Parameters
- attributes_subset : str or list, optional
-
Specifies the node attribute or list of node attributes to remove; for example, [‘weight’,’color’]. By default, all node attributes are removed.
- nodes_subset : list or iterable of nodes, optional
-
Specifies the nodes to drop attributes from; for example, [1,2,3] or (1,2,3) or [1] or (1,). By default, the attributes for all nodes are removed.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
Returns
- SAS graph object or None
-
If the inplace parameter value is True, the graph is modified by removing the specified node attributes. If the inplace parameter value is False, a copy of the input graph with the modified node attributes is returned.
enumerate_cycle_edges()
Enumerates the cycles in a graph and returns the edges of the cycles.
Parameters
- maxcycles : int or ‘ALL’, optional
-
Specifies the maximum number of cycles to count. The default is ‘ALL’.
- minlength : int, optional
-
Specifies the minimum number of edges in cycles that are counted. The default is 1.
- maxlength : int, optional
-
Specifies the maximum number of edges in cycles that are counted. The default is None.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None. When the value is None, a weight of 1 is assumed for all nodes.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None. When the value is None, a weight of 1 is assumed for all edges.
- minedgewt : float or None, optional
-
Specifies the minimum sum of edge weights in a cycle. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum sum of edge weights in a cycle. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum sum of node weights in a cycle. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum sum of node weights in a cycle. The default is None.
- maxtime : float or None, optional
-
Specifies the approximate maximum number of seconds to spend on enumeration. The default is None.
- source : node or None, optional
-
Specifies the source node for cycle calculations. The default is None.
Yields
- generator
-
Yields a generator of cycles, each of which is given as a list of the cycles’ edges. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_cycle_nodes()
Enumerates the cycles in a graph and returns the nodes of the cycles.
Parameters
- maxcycles : int or ‘ALL’, optional
-
Specifies the maximum number of cycles to count. The default is ‘ALL’.
- minlength : int, optional
-
Specifies the minimum number of edges in cycles that are counted. The default is 1.
- maxlength : int, optional
-
Specifies the maximum number of edges in cycles that are counted. The default is None.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None. When the value is None, a weight of 1 is assumed for all nodes.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None. When the value is None, a weight of 1 is assumed for all edges.
- minedgewt : float or None, optional
-
Specifies the minimum sum of edge weights in a cycle. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum sum of edge weights in a cycle. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum sum of node weights in a cycle. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum sum of node weights in a cycle. The default is None.
- maxtime : float or None, optional
-
Specifies the approximate maximum number of seconds to spend on enumeration. The default is None.
- source : node or None, optional
-
Specifies the source node for cycle calculations. The default is None.
Yields
- generator
-
Yields a generator of cycles, each of which is given as a list of the cycles’ nodes. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_cycles()
Enumerates the cycles in a graph and returns the cycle graph objects.
Parameters
- maxcycles : int or ‘ALL’, optional
-
Specifies the maximum number of cycles to count. The default is ‘ALL’.
- minlength : int, optional
-
Specifies the minimum number of edges in cycles that are counted. The default is 1.
- maxlength : int, optional
-
Specifies the maximum number of edges in cycles that are counted. The default is None.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None. When the value is None, a weight of 1 is assumed for all nodes.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None. When the value is None, a weight of 1 is assumed for all edges.
- minedgewt : float or None, optional
-
Specifies the minimum sum of edge weights in a cycle. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum sum of edge weights in a cycle. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum sum of node weights in a cycle. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum sum of node weights in a cycle. The default is None.
- maxtime : float or None, optional
-
Specifies the approximate maximum number of seconds to spend on enumeration. The default is None.
- source : node or None, optional
-
Specifies the source node for cycle calculations. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one cycle of the same type as the input graph. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_path_edges()
Enumerates the paths in a graph and returns the edges of the paths.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- minlength : int, optional
-
Specifies the minimum number of edges in paths that are returned. The default is 1.
- maxlength : int or None, optional
-
Specifies the maximum number of edges in paths that are returned. The default is None.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None, which means that a weight of 1 is assumed for all nodes.
- minedgewt : float or None, optional
-
Specifies the minimum edge weight of edges in paths that are returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum edge weight of edges in paths that are returned. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum node weight of nodes in paths that are returned. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum node weight of nodes in paths that are returned. The default is None.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for enumeration to spend. The default is None.
Yields
- generator
-
Yields a generator of Path objects, each of which is given as a list of the paths’ edges. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_path_nodes()
Enumerates the paths in a graph and returns the nodes of the paths.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- minlength : int, optional
-
Specifies the minimum number of edges in paths that are returned. The default is 1.
- maxlength : int or None, optional
-
Specifies the maximum number of edges in paths that are returned. The default is None.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None, which means that a weight of 1 is assumed for all nodes.
- minedgewt : float or None, optional
-
Specifies the minimum edge weight of edges in paths that are returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum edge weight of edges in paths that are returned. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum node weight of nodes in paths that are returned. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum node weight of nodes in paths that are returned. The default is None.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for enumeration to spend. The default is None.
Yields
- generator
-
Yields a generator of Path objects, each of which is given as a list of the paths’ nodes. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_paths()
Enumerates the paths in a graph and returns the Path graph objects.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- minlength : int, optional
-
Specifies the minimum number of edges in paths that are returned. The default is 1.
- maxlength : int or None, optional
-
Specifies the maximum number of edges in paths that are returned. The default is None.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None, which means that a weight of 1 is assumed for all nodes.
- minedgewt : float or None, optional
-
Specifies the minimum edge weight of edges in paths that are returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum edge weight of edges in paths that are returned. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum node weight of nodes in paths that are returned. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum node weight of nodes in paths that are returned. The default is None.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for enumeration to spend. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one Path object. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_sequence_shortest_paths()
Enumerates the shortest paths in a graph that visit the indicated sequence nodes in order.
Parameters
- sequence : iterable of nodes
-
Specifies the order in which to visit the required nodes.
- pathsperpair : int, optional
-
Specifies the maximum number of shortest paths to return. The default is 1.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted shortest path is computed.
- minedgewt : float or None, optional
-
Specifies the minimum total edge weight for each shortest path that is returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum total edge weight for each shortest path that is returned. The default is None.
- maxabsobjgap : nonnegative float or None, optional
-
Specifies the maximum weight by which a returned path can exceed the optimum shortest path weight. The default is None.
- maxrelobjgap : nonnegative float or None, optional
-
Specifies the maximum factor by which a returned path can exceed the optimum shortest path weight. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of Path objects; each object represents a subpath between a sequence of nodes. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_shortest_path_edges()
Enumerates the shortest paths in a graph and returns the edges of the paths.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- pathsperpair : int, optional
-
Specifies the maximum number of shortest paths to return for each source-sink pair. The default is 1.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted shortest path is computed.
- minedgewt : float or None, optional
-
Specifies the minimum total edge weight for each shortest path that is returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum total edge weight for each shortest path that is returned. The default is None.
- maxabsobjgap : nonnegative float or None, optional
-
Specifies the maximum weight by which a returned path can exceed the optimum shortest path weight. The default is None.
- maxrelobjgap : nonnegative float or None, optional
-
Specifies the maximum factor by which a returned path can exceed the optimum shortest path weight. The default is None.
Yields
- generator
-
Yields a generator of paths; each path is given as a list of the paths’ edges. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_shortest_path_nodes()
Enumerates the shortest paths in a graph and returns the nodes of the paths.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- pathsperpair : int, optional
-
Specifies the maximum number of shortest paths to return for each source-sink pair. The default is 1.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted shortest path is computed.
- minedgewt : float or None, optional
-
Specifies the minimum total edge weight for each shortest path that is returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum total edge weight for each shortest path that is returned. The default is None.
- maxabsobjgap : nonnegative float or None, optional
-
Specifies the maximum weight by which a returned path can exceed the optimum shortest path weight. The default is None.
- maxrelobjgap : nonnegative float or None, optional
-
Specifies the maximum factor by which a returned path can exceed the optimum shortest path weight. The default is None.
Yields
- generator
-
Yields a generator of paths; each path is given as a list of the paths’ nodes. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
enumerate_shortest_paths()
Enumerates the shortest paths in a graph and returns the Path graph objects.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as source nodes.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) for shortest path enumeration. The default is None, which means that all nodes within the graph are used as sink nodes.
- pathsperpair : int, optional
-
Specifies the maximum number of shortest paths to return for each source-sink pair. The default is 1.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted shortest path is computed.
- minedgewt : float or None, optional
-
Specifies the minimum total edge weight for each shortest path that is returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum total edge weight for each shortest path that is returned. The default is None.
- maxabsobjgap : nonnegative float or None, optional
-
Specifies the maximum weight by which a returned path can exceed the optimum shortest path weight. The default is None.
- maxrelobjgap : nonnegative float or None, optional
-
Specifies the maximum factor by which a returned path can exceed the optimum shortest path weight. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of Path objects; each object represents one shortest path. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
get_meta_graph()
Constructs a metagraph from the input graph.
Parameters
- node_type : str
-
Specifies the node attribute to consider in constructing the metagraph.
- edge_type : str, optional
-
Specifies the edge attribute to consider in constructing the metagraph. By default, all connections between nodes are considered the same.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
Returns
- SAS graph object
-
Returns the metagraph, which has an edge attribute count and determines the number of unique connections between pairs of nodes.
get_nlargest_biconcomps()
Returns a list of up to n largest biconnected components.
Parameters
- n : int
-
Specifies the number of graphs to return.
- order_by : ‘node’ or ‘edge’ or None
-
Specifies whether to sort the biconnected components by the number of nodes or edges within those components. The default is None, which means that the biconnected components are not sorted.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
- ascending : bool
-
Specifies whether to sort in ascending or descending order, when you specify the order_by parameter. When the value is True, the smallest biconnected components are returned instead. The default is False.
Returns
- list
-
Returns a list of n largest or smallest biconnected components of a graph.
get_nlargest_concomps()
Returns a list of up to n largest connected (with highest number of nodes) components of a graph.
Parameters
- n : int
-
Specifies the number of graphs to return.
- order_by : ‘node’ or ‘edge’
-
Specifies whether to sort the component by number of nodes or edges within that component. The default is None, which means that the result is not sorted.
- strongly : bool, optional
-
Specifies whether or not the connected components must be strongly connected. When the value is False, only weakly connected components are found. This parameter is supported only for directed graphs. The default is True.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
- ascending : bool, optional
-
Specifies whether to sort in ascending or descending order, when you specify the order_by parameter. The default is False.
Returns
- list
-
Returns a list of the n largest connected components of a graph.
has_edge_attribute()
Checks the edges of the input graph for the specified edge attribute.
Parameters
- name : str
-
Specifies the name of the edge attribute.
- all_edges : bool, optional
-
Specifies whether or not to check for the existence of the edge attribute in all or any of the edges. The default is False.
Returns
- bool
-
If the all_edges parameter value is True, the value True is returned if that edge attribute exists in all edges; otherwise the value False is returned. If the all_edges parameter value is False, the value True is returned if at least one edge in the graph has that specified edge attribute.
has_node_attribute()
Checks the nodes of the input graph for the specified node attribute.
Parameters
- name : str
-
Specifies the name of the node attribute.
- all_nodes : bool, optional
-
Specifies whether or not to check for the existence of the node attribute in all or any of the nodes. The default is False.
Returns
- bool
-
If the all_nodes parameter value is True, the value True is returned if that node attribute exists in all node; otherwise the value False is returned. If the all_nodes parameter value is False, the value True is returned if at least one node in the graph has that specified node attribute.
intersection()
Returns the intersection of input graphs by finding the intersections of their nodes and edges.
The node attributes and edge attributes are aggregated using the rules that are defined by the nodes_attrs_agg and edges_attrs_agg parameters.
Parameters
- rhs : SAS graph object
-
Specifies the other graph, of the same type as self, with which to intersect.
- nodes_attrs_agg : function or str or dict or None, optional
-
Specifies how to aggregate node attributes. The value can be a function, such as mean or np.sum; a string in the list {‘first’,’last’,’mean’}; or a dictionary that maps node attributes to functions. The default is None.
- edges_attrs_agg : function or str or dict or None, optional
-
Specifies how to aggregate edge attributes. The value can be a function, such as mean or np.sum; a string in the list {‘first’,’last’,’mean’}; or a dictionary that maps edge attributes to functions. The default is None.
Returns
- SAS graph object
-
Returns a graph that is constructed by the intersection of the two graphs.
is_biconnected()
Specifies whether or not the input graph is biconnected.
Returns
- bool
-
Indicates whether the input graph is biconnected (True) or not (False).
is_bipartite()
Determines whether the input graph is bipartite.
Returns
- bool
-
Indicates whether the input graph is bipartite.
is_connected()
Specifies whether or not the input graph is connected.
Returns
- bool
-
Indicates whether the input graph is connected (True) or not (False).
is_cycle()
Determines whether the input graph is a simple cycle.
Returns
- bool
-
Indicates whether the input graph is a simple cycle (True) or not (False).
is_dag()
Determines whether the input graph is a directed acyclic graph (DAG).
Returns
- bool
-
Indicates whether the input graph is a directed acyclic graph (DAG).
is_directed()
Specifies whether or not the graph is directed.
Returns
- bool
-
Indicates whether or not the graph is directed.
is_hamiltonian()
Determines whether the graph is Hamiltonian (has a Hamiltonian cycle) or not.
Parameters
- maxtime : float or None, optional
-
Specifies the maximum amount of time to determine whether or not the graph is Hamiltonian. The default is None.
Returns
- bool or None
-
Indicates whether or not the input graph is determined to be Hamiltonian. Returns None if no determination is made.
is_immutable()
Specifies whether or not the graph is immutable.
Returns
- bool
-
Indicates whether or not the graph is immutable.
is_multigraph()
Specifies whether or not the graph allows multiedges.
Returns
- bool
-
Indicates whether or not the graph allows multiedges.
is_path()
Determines whether the input graph is a simple path.
Returns
- bool
-
Indicates whether the input graph is a simple path (True) or not (False).
is_strongly_connected()
Specifies whether the input graph is strongly connected.
Returns
- bool
-
Indicates whether the input graph is strongly connected (True) or not (False).
is_weakly_connected()
Specifies whether the input graph is weakly connected.
Returns
- bool
-
Indicates whether the input graph is weakly connected (True) or not (False).
label_propagation()
Computes the communities of the graph by using the label propagation algorithm.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- maxiters : int, optional
-
Specifies the number of iterations that the algorithm can run. The default is 100.
- tolerance : float, optional
-
Specifies the value for which the algorithm stops iterating when the fraction of label changes for all nodes in the graph is less than the value. The default is 0.05.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one community. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
label_propagation_nodes()
Computes community assignments for all nodes in the graph by using the label propagation algorithm.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- maxiters : int, optional
-
Specifies the number of iterations that the algorithm can run. The default is 100.
- tolerance : float, optional
-
Specifies the value for which the algorithm stops iterating when the fraction of label changes for all nodes in the graph is less than the value. The default is 0.05.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
- inplace : bool, optional
-
Specifies whether to add the community values as attributes to the input graph directly or to create a copy of the graph. The default is False.
Returns
- SAS graph object or None
-
Returns a graph that contains the node attribute community, which denotes the community assignment for each node. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
leaf_node_count()
Computes a graph’s leaf node count.
Returns
- int
-
Returns the number of leaf nodes.
local_transitivity()
Computes the local transitivity (clustering coefficient) and stores the results as node attributes on the graph.
Parameters
- inplace : bool, optional
-
Specifies whether to add the transitivity values as attributes to the input graph directly or to create a copy of the graph. The default is False.
Returns
- SAS graph object or None
-
Returns a graph that contains node attribute ‘transitivity’. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
louvain()
Computes the communities of the graph by using the Louvain algorithm.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- resolution : float, optional
-
Specifies the factor in the modularity equation that affects the expected number of links between two nodes. A higher value produces more communities. The default is 1.
- tolerance : float, optional
-
Specifies the value for which the algorithm stops iterating when the fraction of modularity gain between two consecutive iterations is less than the value. The default is 0.001.
- maxiters : int, optional
-
Specifies the number of iterations that the algorithm can run. The default is 100.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one community. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
louvain_nodes()
Computes community assignments for all nodes in the graph by using the Louvain algorithm.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- resolution : float, optional
-
Specifies the factor in the modularity equation that affects the expected number of links between two nodes. A higher value produces more communities. The default is 1.
- tolerance : float, optional
-
Specifies the value for which the algorithm stops iterating when the fraction of modularity gain between two consecutive iterations is less than the value. The default is 0.001.
- maxiters : int, optional
-
Specifies the number of iterations that the algorithm can run. The default is 100.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
- inplace : bool, optional
-
Specifies whether to add the community values as attributes to the input graph directly or to create a copy of the graph. The default is False.
Returns
- SAS graph object or None
-
Returns a graph that contains the node attribute community, which denotes the community assignment for each node. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
maxflow()
Calculates the maximum flow from a source node to a sink node in a graph.
Parameters
- source : number or str
-
Specifies the source node for the maximum flow.
- sink : number or str
-
Specifies the sink node for the maximum flow.
- capacity_attr : str, optional
-
Specifies the name of the edge attribute that contains the capacity of the edge. The default is ‘upper’.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the edge attribute flow, which contains the flow values. This graph has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is True, the graph is modified in place and None is returned. When the inplace parameter value is False, the returned graph contains only the flow edges.
maximal_cliques()
Enumerates all maximal cliques of the graph.
Parameters
- maxcliques : int or ‘ALL’, optional
-
Specifies the maximum number of enumerated cliques to return. The default is ‘ALL’.
- node_weight : str or None, optional
-
Specifies the node attribute that corresponds to the node weight. The default is None, which means that a weight of 1 is assumed for all nodes.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- minsize : int, optional
-
Specifies the minimum number of nodes in a clique. The default is 1.
- maxsize : int or None, optional
-
Specifies the maximum number of nodes in a clique. The default is None.
- minedgewt : float or None, optional
-
Specifies the minimum sum of edge weights in a clique. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum sum of edge weights in a clique. The default is None.
- minnodewt : float or None, optional
-
Specifies the minimum sum of node weights in a clique. The default is None.
- maxnodewt : float or None, optional
-
Specifies the maximum sum of node weights in a clique. The default is None.
- maxtime : float or None, optional
-
Specifies the approximate maximum number of seconds for enumeration to spend. The default is None.
- order_by : ‘node’ or None, optional
-
Specifies whether to sort the cliques by the number of nodes within each clique. The default is None, which means that the result is not sorted.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
- ascending : bool, optional
-
Specifies whether to sort in ascending or descending order, when you specify the order_by parameter. The default is False.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one maximal clique. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
min_cut()
Calculates a minimum cut of a graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that an unweighted minimum cut is calculated.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the edge attribute ‘mincut’, which indicates the edges to include in the minimum cut set, and the node attribute ‘mincut_partition’, which indicates the node partition of the calculated minimum cut. This graph has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is True, the graph is modified in place and None is returned. When the inplace parameter value is False, a modified copy of the graph is returned.
min_s_t_cut()
Calculates a minimum s-t cut of a graph.
Parameters
- source : number or str
-
Specifies the source node (s) for the minimum s-t cut.
- sink : number or str
-
Specifies the sink node (t) for the minimum s-t cut.
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that an unweighted minimum s-t cut is calculated.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the edge attribute s_t_cut, which indicates the edges to include in the minimum s-t cut set; and the node attribute s_t_cut_partition, which indicates the node partition of the calculated minimum s-t cut. This graph has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is True, the graph is modified in place and None is returned. When the inplace parameter value is False, a modified copy of the graph is returned.
mincostflow()
Calculates the minimum-cost network flow for the graph.
Parameters
- demand_lower_attr : str, optional
-
Specifies the name of the node attribute that contains the lower bound of the node supply. The default is ‘lower’.
- demand_upper_attr : str, optional
-
Specifies the name of the node attribute that contains the upper bound of the node supply. The default is ‘upper’.
- capacity_lower_attr : str, optional
-
Specifies the name of the edge attribute that contains the capacity lower bound of the edge. The default is ‘lower’.
- capacity_upper_attr : str, optional
-
Specifies the name of the edge attribute that contains the capacity upper bound of the edge. The default is ‘upper’.
- cost_attr : str, optional
-
Specifies the name of the edge attribute that contains the edge cost. The default is ‘weight’.
- maxtime : float or None, optional
-
Specifies the maximum amount of time to allow for computing the minimum-cost network flow. The default is None.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the edge attributes flow and reduced_cost, which contain the flow and reduced cost values, respectively; and the node attribute dual, which contains the optimal dual value. This graph has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is True, the graph is modified in place and None is returned.
minimum_spanning_tree()
Calculates a minimum spanning tree (MST) or forest of a graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- source : number or str or None
-
Specifies the source node for a directed MST. The default is None.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the edge attribute ‘mst’, which indicates the edges to include in the spanning tree or forest. This graph has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is True, the graph is modified in place and None is returned. When the inplace parameter value is False, the returned graph contains only the spanning tree or forest edges.
minimum_weight_full_matching()
Returns a minimum-weight full matching of the bipartite graph self.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a directed graph whose edges identify the assignment mapping in the minimum-weight full matching solution. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
neighbors()
Returns an iterator over all neighbors of node n.
Parameters
- n : node
-
Specifies a node in the graph.
Returns
- iterator
-
Returns an iterator over all neighbors of node n.
new_edge_key()
Returns an unused key for the edges between nodes u and v.
Parameters
- u : numeric or str
-
Specifies the from node to add to the graph.
- v : numeric or str
-
Specifies the to node to add to the graph.
Returns
- int
-
Returns a unique edge key value.
node_clique_numbers()
Computes node clique numbers and stores the results as attributes on the graph.
Parameters
- inplace : bool, optional
-
Specifies whether to add the clique number values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the value of the inplace parameter is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph or modifies the existing graph to contain the node attribute clique_number, which includes the clique number of each node. The graph g has the attribute g.solution_summary, which contains information about the results of the algorithm.
number_of_edges()
Returns the number of edges in the graph.
When you specify u and v, the number of edges between u and v is returned. When you specify u but v is None, the number of edges that connect to u is returned. When you specify v but u is None, the number of edges that connect to v is returned.
Parameters
- u : numeric or str or None, optional
-
Specifies the from node. The default is None.
- v : numeric or str or None, optional
-
Specifies the to node. The default is None.
Returns
- int
-
Returns the number of edges in the graph. When you specify u and v, the number of edges between u and v is returned. When you specify u but v is None, the number of edges that connect to u is returned. When you specify v but u is None, the number of edges that connect to v is returned.
number_of_nodes()
Returns the number of nodes in the graph.
Returns
- int
-
Returns the number of nodes in the graph.
projected_graph()
Computes a projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in self other than nodes.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the converging method is used. When the directed_method parameter is specified for an undirected graph, a ValueError is raised.
- multigraph : bool, optional
-
Specifies whether or not to return a multigraph. When the value is True, the algorithm returns a multigraph in which the multiple edges represent multiple shared neighbors. The edge attribute ‘neighbor’ stores the label of the shared neighbor. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the neighbors subset of nodes. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
projected_graph_adamic_adar()
Computes an Adamic-Adar projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in g other than nodes.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the converging method is used.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the neighbors subset of nodes. The strength of association in the calculated projection is represented by the ‘adamic_adar’ edge attribute.
projected_graph_common_neighbors()
Computes a common neighbors projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in g other than those that are specified by the nodes parameter.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the converging method is used.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the neighbors subset of nodes. The strength of association in the calculated projection is represented by the ‘common_neighbors’ edge attribute.
projected_graph_cosine()
Computes a cosine projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in g other than those that are specified by the nodes parameter.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the ‘converging’ method is used.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the neighbors subset of nodes. The strength of association in the calculated projection is represented by the ‘cosine’ edge attribute.
projected_graph_dice()
Computes a Sørensen-Dice projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in g other than those that are specified by the nodes parameter.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the ‘converging’ method is used.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the subset of nodes that are specified by the neighbors parameter. The strength of association in the calculated projection is represented by the ‘dice’ edge attribute.
projected_graph_jaccard()
Computes a Jaccard projected graph.
Parameters
- nodes : list or iterable
-
Specifies the subset of nodes to project onto.
- neighbors : list or iterable, optional
-
Specifies the subset of nodes to project through. By default, this subset consists of all nodes in g other than those that are specified by the nodes parameter.
- directed_method : {‘converging’, ‘diverging’, ‘transitive’}, optional
-
Specifies a method to use for projecting directed graphs. By default, the ‘converging’ method is used.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph representation of the node pairs with common neighbors among the neighbors subset of nodes. The strength of association in the calculated projection is represented by the ‘jaccard’ edge attribute.
query()
Queries for the subgraph isomorphisms of q within g.
Parameters
- q : graph
-
Specifies the query graph.
- expr : _Expression or None, optional
-
Specifies additional logic to filter the query results. The default is None.
- induced : bool, optional
-
Specifies whether or not to return only node-induced matches. The default is False.
- break_symmetry : bool, optional
-
Specifies whether or not to break symmetry and eliminate automorphic relationships between matches. The default is False.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one isomorphic mapping from q to self. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
reach_graph()
Computes the reach graph for the source or set of sources.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to compute the reach network.
- max_reach : int, optional
-
Specifies the number of steps (or hops) to traverse from the source nodes. The default is 1.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Returns
- SAS graph object
-
Returns a graph that represents the reach network. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
reach_graph_per_source()
Computes a separate reach graph for each given source node.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to compute the reach network.
- max_reach : int, optional
-
Specifies the number of steps (or hops) to traverse from the source nodes. The default is 1.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of subgraphs; each subgraph represents one reach network. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
remove_edge()
Removes a single edge from the graph.
Parameters
- u : numeric or str
-
Specifies the from node.
- v : numeric or str
-
Specifies the to node.
- key : numeric or str or None
-
Specifies the edge key. The default is None, which means that when there are multiple edges between u and v, the most recently added edge is removed.
Examples
G.remove_edge(1,2)
remove_edges_from()
Removes edges from the graph.
Parameters
- edges : an iterable container of edges
-
When you specify two-tuples (u, v), the most recently added edge between u and v is removed. When you specify three-tuples (u, v, key) or four-tuples (u, v, key, data), the edge between u and v with the specified key is removed, where data are ignored.
remove_isolated_nodes()
Removes isolated nodes from a graph.
Parameters
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not to modify the input graph. The default is False.
Returns
- SAS graph object or None
-
Returns the resulting graph after isolated nodes are removed, or returns nothing if the inplace parameter value is True.
remove_node()
Removes a single node from the graph.
Parameters
- node : numeric or str
-
Specifies the node to remove from the graph.
remove_nodes_from()
Removes nodes from the graph. If a node does not exist in the graph, it is silently ignored.
Parameters
- nodes : an iterable container of nodes
-
Specifies the nodes to remove from the graph.
set_edge_attributes()
Sets edge attributes by using a given value or dictionary of values.
Parameters
- values : scalar or dict-like or Pandas DataFrame
-
Specifies what the edge attribute should be set to. When this parameter is set to a Pandas DataFrame, it is expected to have from, to, and edge_key (only for multigraphs) columns, and the other columns are treated as edge attributes to add. When values is a dictionary, the keys are edges and the values are either edge attribute values or dictionaries of attribute name-value pairs. For multigraphs, the edge tuples must be of the form (u, v, key). For simple graphs, the keys must be tuples of the form (u, v). When this parameter is not set to a dictionary, it is treated as a single attribute value that is then applied to every edge in self. The attribute name is specified by the name parameter.
- name : str or None, optional
-
Specifies the name of the edge attribute to set if the values parameter is set to a scalar. The default is None.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not to modify the graph in place. The default is False.
Returns
- SAS graph object or None
-
If the inplace parameter value is False, a copy of the input graph with the new edge attributes is returned. If the inplace parameter value is True, the graph is modified by setting the specified edge attributes.
set_node_attributes()
Sets node attributes from a given value or dictionary of values.
Parameters
- values : scalar or dict-like or Pandas DataFrame
-
Specifies what the node attribute should be set to. When values is not a dictionary, it is treated as a single attribute value that is then applied to every node in self. This means that if you provide a mutable object, such as a list, updates to that object are reflected in the node attribute for every node. The attribute name is specified by the name parameter. When values is a dictionary, the keys are nodes and the values are either node attribute values or dictionaries of attribute name-value pairs.
- name : str or None, optional
-
Specifies the name of the node attribute to set if the values parameter is set to a scalar. The default is None.
- immutable : bool or None, optional
-
Specifies whether or not to return an immutable copy. The default is None, which means that the mutability matches the input graph.
- inplace : bool, optional
-
Specifies whether or not the graph is modified in place. The default is False.
Returns
- SAS graph object or None
-
If the inplace parameter value is True, the graph is modified by setting the specified node attributes. If the inplace parameter value is False, a copy of the input graph with the new node attributes is returned.
shortest_path_distances()
Calculates the shortest path distances in a graph.
Parameters
- source : node or iterable of nodes or None, optional
-
Specifies the source node(s) and restricts enumeration to the shortest paths that contain the specified source node(s). The default is None.
- sink : node or iterable of nodes or None, optional
-
Specifies the sink node(s) and restricts enumeration to the shortest paths that contain the specified sink node(s). The default is None.
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that the unweighted shortest path is computed.
- minedgewt : float or None, optional
-
Specifies the minimum total edge weight for each shortest path that is returned. The default is None.
- maxedgewt : float or None, optional
-
Specifies the maximum total edge weight for each shortest path that is returned. The default is None.
Returns
- dict
-
Returns a dictionary where each key is a (source, sink) tuple and its value is the corresponding shortest source-sink path distance.
similarity_adamic_adar()
Computes Adamic-Adar node similarity.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to calculate similarity.
- sink : node or iterable of nodes, optional
-
Specifies one or more source nodes from which to calculate similarity. By default, all nodes are sinks.
- top_k : int, optional
-
Specifies the maximum number of highest-similarity source-sink pairs to return.
- bottom_k : int, optional
-
Specifies the maximum number of lowest-similarity source-sink pairs to return.
- exclude_source : bool, optional
-
Specifies whether or not to exclude the source-source pairs from the returned results. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned results. The default is False.
Returns
- OrderedDict
-
Returns an ordered dictionary, sorted in decreasing order of similarity. The key is the (source, sink) tuple, and the value is the computed similarity score.
similarity_common_neighbors()
Computes common neighbors node similarity.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to calculate similarity.
- sink : node or iterable of nodes, optional
-
Specifies one or more source nodes from which to calculate similarity. By default, all nodes are sinks.
- top_k : int, optional
-
Specifies the maximum number of highest-similarity source-sink pairs to return.
- bottom_k : int, optional
-
Specifies the maximum number of lowest-similarity source-sink pairs to return.
- exclude_source : bool, optional
-
Specifies whether or not to exclude the source-source pairs from the returned results. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned results. The default is False.
Returns
- OrderedDict
-
Returns an ordered dictionary, sorted in decreasing order of similarity. The key is the (source, sink) tuple, and the value is the computed similarity score.
similarity_cosine()
Computes cosine node similarity.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to calculate similarity.
- sink : node or iterable of nodes, optional
-
Specifies one or more source nodes from which to calculate similarity. By default, all nodes are sinks.
- top_k : int, optional
-
Specifies the maximum number of highest-similarity source-sink pairs to return.
- bottom_k : int, optional
-
Specifies the maximum number of lowest-similarity source-sink pairs to return.
- exclude_source : bool, optional
-
Specifies whether or not to exclude the source-source pairs from the returned results. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned results. The default is False.
Returns
- OrderedDict
-
Returns an ordered dictionary, sorted in decreasing order of similarity. The key is the (source, sink) tuple, and the value is the computed similarity score.
similarity_dice()
Computes Sørensen-Dice node similarity.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to calculate similarity.
- sink : node or iterable of nodes, optional
-
Specifies one or more source nodes from which to calculate similarity. By default, all nodes are sinks.
- top_k : int, optional
-
Specifies the maximum number of highest-similarity source-sink pairs to return.
- bottom_k : int, optional
-
Specifies the maximum number of lowest-similarity source-sink pairs to return.
- exclude_source : bool, optional
-
Specifies whether or not to exclude the source-source pairs from the returned results. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned results. The default is False.
Returns
- OrderedDict
-
Returns an ordered dictionary, sorted in decreasing order of similarity. The key is the (source, sink) tuple, and the value is the computed similarity score.
similarity_graph()
Computes a node similarity graph.
Parameters
- measure : str, one of {‘adamic_adar’, ‘common_neighbors’, ‘cosine’, ‘dice’, ‘jaccard’}
-
Specifies the metric to be used to compute the node similarity.
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the edge attribute that corresponds to the measure name. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_graph_adamic_adar()
Computes an Adamic-Adar node similarity graph.
Parameters
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the ‘adamic_adar’ edge attribute. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_graph_common_neighbors()
Computes a common neighbors node similarity graph.
Parameters
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the ‘common_neighbors’ edge attribute. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_graph_cosine()
Computes a cosine node similarity graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the edge attribute that corresponds to the edge weight. The default is None, which means that a weight of 1 is assumed for all edges.
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the ‘cosine’ edge attribute. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_graph_dice()
Computes a Sørensen-Dice node similarity graph.
Parameters
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the dice edge attribute. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_graph_jaccard()
Computes a Jaccard node similarity graph.
Parameters
- min_score : float, optional
-
Specifies the minimum similarity score for edges in the output graph. The default is sys.float_info.epsilon.
- max_score : float, optional
-
Specifies the maximum similarity score for edges in the output graph. The default is np.inf.
- exclude_source : bool, optional
-
Specifies whether or not to exclude self-loops from the returned graph. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned graph. The default is False.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node attributes of the graph are retained. Note that the edge attributes are not carried over to the output graph.
Returns
- MultiGraph
-
Returns a MultiGraph representation of the node pairs whose similarity scores are in the range of min_score to max_score. The calculated similarity is represented by the ‘jaccard’ edge attribute. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
similarity_jaccard()
Computes Jaccard node similarity.
Parameters
- source : node or iterable of nodes
-
Specifies one or more source nodes from which to calculate similarity.
- sink : node or iterable of nodes, optional
-
Specifies one or more source nodes from which to calculate similarity. By default, all nodes are sinks.
- top_k : int, optional
-
Specifies the maximum number of highest-similarity source-sink pairs to return.
- bottom_k : int, optional
-
Specifies the maximum number of lowest-similarity source-sink pairs to return.
- exclude_source : bool, optional
-
Specifies whether or not to exclude the source-source pairs from the returned results. The default is False.
- exclude_existing_neighbors : bool, optional
-
Specifies whether or not to exclude source-sink pairs that are joined by an existing link from the returned results. The default is False.
Returns
- OrderedDict
-
Returns an ordered dictionary, sorted in decreasing order of similarity. The key is the (source, sink) tuple, and the value is the computed similarity score.
singleton_node_count()
Computes a graph’s singleton node count.
Returns
- int
-
Returns the number of singleton nodes.
to_directed()
Returns a directed copy of the input graph.
Returns
- SAS graph object
-
Returns a directed copy of the input graph.
to_immutable()
Creates an immutable graph from the input graph.
Returns
- SAS graph object
-
Returns an immutable SAS graph object.
to_mutable()
Creates a mutable graph from the input graph.
Returns
- SAS graph object
-
Returns a mutable SAS graph object.
to_pandas_edges()
Returns the graph edges as a Pandas DataFrame.
Parameters
- data : bool or list, optional
-
Specifies whether or not to retain attributes. The default is True. When the value is True (or when a list is given), the Pandas DataFrame includes all edge attributes (or all listed edge attributes).
Returns
- dataframe
-
Returns a Pandas DataFrame that includes the graph edges.
to_pandas_nodes()
Returns the graph nodes as a Pandas DataFrame.
Parameters
- data : bool or list, optional
-
Specifies whether or not to retain attributes. The default is True. When the value is True (or when a list is given), the Pandas DataFrame includes all the node attributes (or all the listed attributes).
Returns
- dataframe
-
Returns a Pandas DataFrame that includes the graph nodes.
to_undirected()
Returns a directed copy of the input graph.
Returns
- SAS graph object
-
Returns a directed copy of the input graph.
topological_ordering()
Finds a topological ordering of the graph’s nodes.
Yields
- generator
-
Yields a generator of nodes in topological order. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
transitive_closure()
Calculates the transitive closure of a graph.
Returns
- SAS graph object
-
Returns the transitive closure of the input graph that is returned as a SAS MultiGraph or MultiDiGraph object. This graph has the solution_summary attribute, which contains information about the results of the algorithm.
triangle_count()
Computes a graph’s triangle count.
Returns
- int
-
Returns the number of triangles.
tsp_tour()
Calculates a traveling salesman problem (TSP) tour of a graph.
Parameters
- edge_weight : str or None, optional
-
Specifies the numeric edge attribute that corresponds to the edge weight. The default is None, which means that an unweighted TSP is calculated.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for solving a TSP. The default is None.
- minobjective : float, optional
-
Specifies a minimum value such that when a solution is found whose objective is less than or equal to this value, the algorithm stops.
- inplace : bool, optional
-
Specifies whether to add the TSP order values as attributes to the input graph directly or to create a copy of the graph. The default is False.
- use_milp : bool, optional
-
Specifies whether or not to use a mixed integer linear programming (MILP) solver to solve a TSP. The default is True.
- data : bool, optional
-
Specifies whether or not to retain attributes. When the value is True and the inplace parameter value is False (default values), the node and edge attributes of the graph are retained. This parameter has no effect when the inplace parameter is set to True.
Returns
- SAS graph object or None
-
Returns a graph that has the solution_summary attribute, which contains information about the results of the algorithm. When the inplace parameter value is False, the returned graph is a Cycle that contains the calculated TSP tour edges. When the inplace parameter value is True, the graph is modified in place and None is returned. The modified graph contains the edge attributes tsp and tsp_order and the node attribute tsp_order.
union()
Returns the union of input graphs by finding the unions of their nodes and edges.
The node attributes and edge attributes are aggregated using the rules that are defined by the nodes_attrs_agg and edges_attrs_agg parameters.
Parameters
- rhs : SAS graph object
-
Specifies the other graph, of the same type as self, with which to find the union.
- nodes_attrs_agg : function or str or dict or None, optional
-
Specifies how to aggregate node attributes. The value can be a function, such as mean or np.sum; a string in the list {‘first’,’last’,’mean’}; or a dictionary that maps node attributes to functions. The default is None.
- edges_attrs_agg : function or str or dict or None, optional
-
Specifies how to aggregate edge attributes. The value can be a function, such as mean or np.sum; a string in the list {‘first’,’last’,’mean’}; or a dictionary that maps edge attributes to functions. The default is None.
Returns
- SAS graph object
-
Returns a graph that is constructed by the union of the two graphs.
vrp()
Solves the vehicle routing problem.
Parameters
- capacity : float
-
Specifies the capacity of each vehicle.
- depot : node
-
Specifies the depot node for the vehicle routing problem.
- node_demand : str or dict or iterable
-
Specifies the quantity of goods to deliver to or pick up from a customer. The default is ‘demand’.
- edge_cost : str or dict or iterable
-
Specifies the cost of traversing each edge. The default is ‘weight’.
- minroutes : int, optional
-
Specifies the minimum number of routes that are allowed to service demand.
- maxroutes : int, optional
-
Specifies the maximum number of routes that are allowed to service demand.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for solving the vehicle routing problem. The default is None.
- minobjective : float, optional
-
Specifies a minimum value such that when a solution is found whose objective is less than or equal to this value, the algorithm stops.
- use_milp : bool, optional
-
Specifies whether or not to use a mixed integer linear programming (MILP) solver to solve the vehicle routing problem. The default is True.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of Cycle objects; each cycle represents one route. The generator has the solution_summary attribute, which contains information about the results of the algorithm.
vrptw()
Solves the vehicle routing problem with time windows.
Parameters
- capacity : float
-
Specifies the capacity of each vehicle.
- depot : node
-
Specifies the depot node for the vehicle routing problem.
- node_demand : str or dict or iterable
-
Specifies the quantity of goods to deliver to or pick up from a customer. The default is ‘demand’.
- edge_cost : str or dict or iterable
-
Specifies the cost of traversing each edge.
- travel_time : str or dict or iterable
-
Specifies attributes or values that define the time that it takes to traverse each edge. The default is ‘weight’.
- timewindow_lower : str or dict or iterable or None, optional
-
Specifies attributes or values that define the lower time limits within which a delivery vehicle can arrive at the customer nodes. The default is None.
- timewindow_upper : str or dict or iterable or None, optional
-
Specifies attributes or values that define the upper time limits within which a delivery vehicle can arrive at the customer nodes. The default is None.
- service_time : str or dict or iterable or None, optional
-
Specifies attributes or values that define the service time of the nodes. The default is None.
- minroutes : int, optional
-
Specifies the minimum number of routes that are allowed to service demand.
- maxroutes : int, optional
-
Specifies the maximum number of routes that are allowed to service demand.
- maxtime : float or None, optional
-
Specifies the maximum amount of time for solving the vehicle routing problem. The default is None.
- data : bool, optional
-
Specifies whether or not to retain attributes. The default is True, which means that the node and edge attributes of the graph are retained.
Yields
- generator
-
Yields a generator of Cycle objects; each cycle represents one route. The generator has the solution_summary attribute, which contains information about the results of the algorithm.