import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
def draw_G(inputG, filename):
"""
inputG를 그려서 filename에 저장함.
"""
plt.figure()
nx.draw_networkx(inputG)
plt.savefig(filename)
#####
N = 5
G = nx.star_graph(N)
LG = nx.line_graph(G) # line graph of G
LLG = nx.line_graph(LG)
draw_G(G, "G.png")
draw_G(LG, "LG.png")
draw_G(LLG, "LLG.png")
print("==" * 20)
print("== G")
print(f"Node size: {len(G)}")
print(f"Edge size: {len(G.edges())}")
print(f"Degree Sum: {sum(map(lambda x: x[1], nx.degree(G)))}")
degree_sum = sum(map(lambda x: x[1], nx.degree(G)))
#print(degree_sum)
print("== LG")
print(f"Node size: {len(LG)}")
print(f"Edge size: {len(LG.edges())}")
print(f"Degree Sum: {sum(map(lambda x: x[1], nx.degree(LG)))}")
print("== LLG")
print(f"Node size: {len(LLG)}")
print(f"Edge size: {len(LLG.edges())}")
print(f"Degree Sum: {sum(map(lambda x: x[1], nx.degree(LLG)))}")
print("=="*20)
========================================
== G
Node size: 6
Edge size: 5
Degree Sum: 10
== LG
Node size: 5
Edge size: 10
Degree Sum: 20
== LLG
Node size: 10
Edge size: 30
Degree Sum: 60
========================================
댓글남기기