grape.general_graph.GeneralGraph¶
-
class
GeneralGraph
[source]¶ Class GeneralGraph for directed graphs (DiGraph).
Constructs a new graph given an input file. A DiGraph stores nodes and edges with optional data or attributes. DiGraphs hold directed edges. Nodes can be arbitrary python objects with optional key/value attributes. Edges are represented as links between nodes with optional key/value attributes.
Initialize a graph with edges, name, or graph attributes.
- Parameters
incoming_graph_data (input graph (optional, default: None)) – Data to initialize graph. If None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a 2D NumPy array, a SciPy sparse matrix, or a PyGraphviz graph.
attr (keyword arguments, optional (default= no attributes)) – Attributes to add to graph as key=value pairs.
See also
convert
Examples
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G = nx.Graph(name="my graph") >>> e = [(1, 2), (2, 3), (3, 4)] # list of edges >>> G = nx.Graph(e)
Arbitrary graph attribute pairs (key=value) may be assigned
>>> G = nx.Graph(e, day="Friday") >>> G.graph {'day': 'Friday'}
-
__init__
()[source]¶ Initialize a graph with edges, name, or graph attributes.
- Parameters
incoming_graph_data (input graph (optional, default: None)) – Data to initialize graph. If None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a 2D NumPy array, a SciPy sparse matrix, or a PyGraphviz graph.
attr (keyword arguments, optional (default= no attributes)) – Attributes to add to graph as key=value pairs.
See also
convert()
Examples
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G = nx.Graph(name="my graph") >>> e = [(1, 2), (2, 3), (3, 4)] # list of edges >>> G = nx.Graph(e)
Arbitrary graph attribute pairs (key=value) may be assigned
>>> G = nx.Graph(e, day="Friday") >>> G.graph {'day': 'Friday'}
Methods
__init__
()Initialize a graph with edges, name, or graph attributes.
add_edge
(u_of_edge, v_of_edge, **attr)Add an edge between u and v.
add_edges_from
(ebunch_to_add, **attr)Add all the edges in ebunch_to_add.
add_node
(node_for_adding, **attr)Add a single node node_for_adding and update node attributes.
add_nodes_from
(nodes_for_adding, **attr)Add multiple nodes.
add_weighted_edges_from
(ebunch_to_add[, weight])Add weighted edges in ebunch_to_add with specified weight attr
adjacency
()Returns an iterator over (node, adjacency dict) tuples for all nodes.
betweenness_centrality_kernel
(nodes, …)Compute betweenness centrality, from shortest path list.
Choose the most appropriate way to compute the all-pairs shortest path depending on graph size and density.
clear
()Remove all nodes and edges from the graph.
clear_data
(attributes_to_remove)Delete attributes for all nodes in the graph.
clear_edges
()Remove all edges from the graph without altering nodes.
closeness_centrality_kernel
(nodes, …)Compute betweenness centrality, from shortest path list.
Betweenness_centrality calculation
Closeness centrality calculation.
Degree centrality measure of each node calculation.
Efficiency calculation.
In-degree centrality calculation.
Local efficiency calculation.
Nodal efficiency calculation.
Outdegree centrality calculation.
Compute service for every node, together with edge splitting.
construct_path_kernel
(nodes, predecessor)Reconstruct source-target paths starting from predecessors matrix, and populate the dictionary of shortest paths.
copy
([as_view])Returns a copy of the graph.
degree_centrality_kernel
(nodes, graph_size)Compute degree centrality.
Serial SSSP algorithm based on Dijkstra’s method.
edge_subgraph
(edges)Returns the subgraph induced by the specified edges.
efficiency_kernel
(nodes, shortest_path_length)Compute efficiency, starting from path length attribute.
Initialization of Floyd Warshall APSP algorithm.
floyd_warshall_kernel
(distance, predecessor, …)Floyd Warshall’s APSP inner iteration.
Serial Floyd Warshall’s APSP algorithm.
get_edge_data
(u, v[, default])Returns the attribute dictionary associated with edge (u, v).
has_edge
(u, v)Returns True if the edge (u, v) is in the graph.
has_node
(n)Returns True if the graph contains the node n.
has_predecessor
(u, v)Returns True if node u has predecessor v.
has_successor
(u, v)Returns True if node u has successor v.
indegree_centrality_kernel
(nodes, graph_size)Compute in-degree centrality.
is_directed
()Returns True if graph is directed, False otherwise.
is_multigraph
()Returns True if graph is a multigraph, False otherwise.
load
(filename)Load input file.
local_efficiency_kernel
(nodes, nodal_efficiency)Compute local efficiency, starting from nodal efficiency attribute.
nbunch_iter
([nbunch])Returns an iterator over nodes contained in nbunch that are also in the graph.
neighbors
(n)Returns an iterator over successor nodes of n.
nodal_efficiency_kernel
(nodes, efficiency, …)Compute nodal efficiency, starting from efficiency attribute.
number_of_edges
([u, v])Returns the number of edges between two nodes.
number_of_nodes
()Returns the number of nodes in the graph.
order
()Returns the number of nodes in the graph.
outdegree_centrality_kernel
(nodes, graph_size)Compute out-degree centrality.
predecessors
(n)Returns an iterator over predecessor nodes of n.
remove_edge
(u, v)Remove the edge between u and v.
remove_edges_from
(ebunch)Remove all edges specified in ebunch.
remove_node
(n)Remove node n.
remove_nodes_from
(nodes)Remove multiple nodes.
reverse
([copy])Returns the reverse of the graph.
shortest_path_list_kernel
(nodes, shortest_path)Collect the shortest paths that contain at least two nodes.
size
([weight])Returns the number of edges or total of all edge weights.
subgraph
(nodes)Returns a SubGraph view of the subgraph induced on nodes.
successors
(n)Returns an iterator over successor nodes of n.
to_directed
([as_view])Returns a directed representation of the graph.
to_directed_class
()Returns the class to use for empty directed copies.
to_undirected
([reciprocal, as_view])Returns an undirected representation of the digraph.
to_undirected_class
()Returns the class to use for empty undirected copies.
update
([edges, nodes])Update the graph using nodes/edges/graphs as input.
Attributes
adj
Graph adjacency object holding the neighbors of each node.
GeneralGraph.area
Betweenness centrality of the graph.
Closeness centrality of the graph.
degree
A DegreeView for the Graph as G.degree or G.degree().
Degree centrality of the graph.
description attribute for every node.
edges
An OutEdgeView of the DiGraph as G.edges or G.edges().
Efficiency of the graph.
GeneralGraph.father_condition
final_status attribute for switches.
Average global efficiency of the whole graph.
in_degree
An InDegreeView for (node, in_degree) or in_degree for single node.
in_edges
An InEdgeView of the Graph as G.in_edges or G.in_edges().
In-degree centrality of the graph.
init_status attribute for switches.
initial_service attribute for every node.
Local efficiency of the graph.
mark attribute for every node.
mark_status attribute for every node.
name
String identifier of the graph.
Nodal efficiency of the graph.
nodes
A NodeView of the Graph as G.nodes or G.nodes().
out_degree
An OutDegreeView for (node, out_degree)
out_edges
An OutEdgeView of the DiGraph as G.edges or G.edges().
Out-degree centrality of the graph.
GeneralGraph.perturbation_resistant
pred
Graph adjacency object holding the predecessors of each node.
Computed service.
Shortest existing paths between all node pairs.
Shortest path length.
list of graph sources.
GeneralGraph.status_area
succ
Graph adjacency object holding the successors of each node.
list of graph switches.
type attribute for every node.
list of graph users.
weight attribute for every edge.