easygraph.functions.graph_generator package
Submodules
easygraph.functions.graph_generator.RandomNetwork module
- easygraph.functions.graph_generator.RandomNetwork.WS_Random(n, k, p, FilePath=None)[source]
Returns a small-world graph.
- Parameters:
n (int) – The number of nodes
k (int) – Each node is joined with its k nearest neighbors in a ring topology.
p (float) – The probability of rewiring each edge
FilePath (string) – The file for storing the output graph G
- Returns:
G – a small-world graph
- Return type:
graph
Examples
Returns a small-world graph G
>>> WS_Random(100,10,0.3,"/users/fudanmsn/downloads/RandomNetwork.txt")
- easygraph.functions.graph_generator.RandomNetwork.erdos_renyi_M(n, edge, directed=False, FilePath=None)[source]
Given the number of nodes and the number of edges, return an Erdős-Rényi random graph, and store the graph in a document.
- Parameters:
n (int) – The number of nodes.
edge (int) – The number of edges.
directed (bool, optional (default=False)) – If True, this function returns a directed graph.
FilePath (string) – The file for storing the output graph G.
- Returns:
G – an Erdős-Rényi random graph.
- Return type:
graph
Examples
Returns an Erdős-Rényi random graph G.
>>> erdos_renyi_M(100,180,directed=False,FilePath="/users/fudanmsn/downloads/RandomNetwork.txt")
References
- easygraph.functions.graph_generator.RandomNetwork.erdos_renyi_P(n, p, directed=False, FilePath=None)[source]
Given the number of nodes and the probability of edge creation, return an Erdős-Rényi random graph, and store the graph in a document.
- Parameters:
n (int) – The number of nodes.
p (float) – Probability for edge creation.
directed (bool, optional (default=False)) – If True, this function returns a directed graph.
FilePath (string) – The file for storing the output graph G.
- Returns:
G – an Erdős-Rényi random graph.
- Return type:
graph
Examples
Returns an Erdős-Rényi random graph G
>>> erdos_renyi_P(100,0.5,directed=False,FilePath="/users/fudanmsn/downloads/RandomNetwork.txt")
References
[1] Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
[2] Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
- easygraph.functions.graph_generator.RandomNetwork.fast_erdos_renyi_P(n, p, directed=False, FilePath=None)[source]
Given the number of nodes and the probability of edge creation, return an Erdős-Rényi random graph, and store the graph in a document. Use this function for generating a huge scale graph.
- Parameters:
n (int) – The number of nodes.
p (float) – Probability for edge creation.
directed (bool, optional (default=False)) – If True, this function returns a directed graph.
FilePath (string) – The file for storing the output graph G.
- Returns:
G – an Erdős-Rényi random graph.
- Return type:
graph
Examples
Returns an Erdős-Rényi random graph G
>>> erdos_renyi_P(100,0.5,directed=False,FilePath="/users/fudanmsn/downloads/RandomNetwork.txt")
References
[1] Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
[2] Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
easygraph.functions.graph_generator.classic module
- easygraph.functions.graph_generator.classic.complete_graph(n, create_using=None)[source]
Return the complete graph K_n with n nodes.
A complete graph on n nodes means that all pairs of distinct nodes have an edge connecting them.
- Parameters:
n (int or iterable container of nodes) – If n is an integer, nodes are from range(n). If n is a container of nodes, those nodes appear in the graph.
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
Examples
>>> G = eg.complete_graph(9) >>> len(G) 9 >>> G.size() 36 >>> G = eg.complete_graph(range(11, 14)) >>> list(G.nodes()) [11, 12, 13] >>> G = eg.complete_graph(4, eg.DiGraph()) >>> G.is_directed() True