GenStar¶
-
GenStar
(GraphType, Nodes, IsDir=True)¶
Generates a graph with star topology. Node id 0 is in the center and then links to all other nodes.
Parameters:
- Nodes: int (input)
Number of nodes in the star graph, including the center node.
- IsDir: bool (input)
Indicates whether the edges should be directed or undirected. Defaults to directed.
Return value:
- graph
A Snap.py graph of the specified type.
The following example shows how to generate a star graph with five nodes using GenStar()
for classes TNGraph
, TUNGraph
, and TNEANet
:
import snap
Graph = snap.GenStar(snap.TNGraph, 5, True)
for EI in Graph.Edges():
print("edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId()))
UGraph = snap.GenStar(snap.TUNGraph, 5, True)
for EI in UGraph.Edges():
print("edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId()))
Network = snap.GenStar(snap.TNEANet, 5, True)
for EI in Network.Edges():
print("edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId()))