valos_halozat_hf/app.py

28 lines
956 B
Python
Raw Normal View History

2020-10-02 00:18:14 +02:00
#!/usr/bin/env python3
import igraph as ig
2020-10-02 01:31:45 +02:00
def read_graph(graph_file: str = 'valos_halozat_other_dataset.txt') -> dict:
2020-10-02 00:18:14 +02:00
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):
2020-10-02 01:15:18 +02:00
line = f.readline().split('\t')
2020-10-02 00:18:14 +02:00
result_graph.add_edge(int(line[0]), int(line[1]))
2020-10-02 01:34:58 +02:00
return {"graph": result_graph, "edges": edges, "vertices": vertices}
2020-10-02 00:39:25 +02:00
2020-10-02 01:31:45 +02:00
def calclulate_values(graph_data: dict):
2020-10-02 01:39:46 +02:00
print(f"Atmero: {graph_data['graph'].diameter()}")
print(f"Klaszterek: {graph_data['graph'].clusters()}")
print(f"Klaszterek szama: {len(graph_data['graph'].clusters())}")
2020-10-02 01:34:58 +02:00
print(f"Atlagos ut hossz: {graph_data['graph'].average_path_length()}")
2020-10-02 00:52:11 +02:00
print(f"Atlagos fokszam: {(graph_data['edges'] * 2) / graph_data['vertices']}")
2020-10-02 00:18:14 +02:00
if __name__ == "__main__":
2020-10-02 00:52:11 +02:00
data = read_graph()
calclulate_values(data)