Konversi Python ke Java
import networkx as nx
import matplotlib.pyplot as plt
FName="graph.txt"
GType=nx.Graph()
Graph = nx.read_edgelist(
FName,
create_using=GType,
node_type=int,
data=(('weight',float),)
)
# Find the total number of degree for each node
for g in Graph.nodes():
print("Node: ", g, " has total #degree: ",Graph.degree(x))
# Find the weight for each node
for t,y in Graph.edges():
print ("Weight of Edge ("+str(t)+","+str(y)+")", Graph.get_edge_data(t,y))
#degree centrality
degreecentrality=nx.degree_centrality(Graph)
print("\nDegree centrality of each node: ",degreecentrality)
#Closeness Centrality
closenesscentrality = nx.closeness_centrality(Graph)
print("\nCloseness centrality of each node: ",closenesscentrality)
#Betweenness Centrality
betweennesscentrality=nx.betweenness_centrality(Graph)
print("\nBetweenness centrality of each node: ",betweennesscentrality)
yasaswini reddy