valos_halozat_hf/app.py
Torma Kristóf 2df91678aa
Some checks failed
continuous-integration/drone/push Build is failing
change some stuff
2020-10-02 00:52:11 +02:00

28 lines
946 B
Python

#!/usr/bin/env python3
import igraph as ig
def read_graph(graph_file: str = 'valos_halozat_formatted.txt') -> map:
with open(graph_file) as f:
vertices = int(f.readline())
edges = int(f.readline())
result_graph: ig.Graph = ig.Graph(vertices)
for _ in range(edges):
line = f.readline().split(' ')
result_graph.add_edge(int(line[0]), int(line[1]))
return {"graph": result_graph, "edges:": edges, "vertices": vertices}
def calclulate_values(graph_data: map):
print(f"Klaszterezettseg: {graph_data['graph'].clusters()}")
print(f"Atlagos fokszam: {(graph_data['edges'] * 2) / graph_data['vertices']}")
print(f"Komponensek: {graph_data['graph'].components}")
print(f"Atmero: {graph_data['graph'].diameter()}")
print(f"Atlagos ut hossz: {graph_data['graph'].average_path_length()}")
if __name__ == "__main__":
data = read_graph()
calclulate_values(data)