-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfas_graph.py
100 lines (76 loc) · 2.52 KB
/
fas_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from abc import ABC, abstractmethod
from typing import Iterator, Self
Node = int
Edge = tuple[Node, Node]
class FASGraph(ABC):
@abstractmethod
def get_node_labels(self) -> list[str]:
raise NotImplementedError
@abstractmethod
def get_nodes(self) -> list[Node]:
raise NotImplementedError
@abstractmethod
def get_num_nodes(self) -> int:
raise NotImplementedError
@abstractmethod
def get_num_edges(self) -> int:
raise NotImplementedError
@abstractmethod
def get_out_degree(self, node: Node) -> int:
raise NotImplementedError
@abstractmethod
def get_in_degree(self, node: Node) -> int:
raise NotImplementedError
@abstractmethod
def iter_out_neighbors(self, node: Node) -> Iterator[Node]:
raise NotImplementedError
@abstractmethod
def iter_in_neighbors(self, node: Node) -> Iterator[Node]:
raise NotImplementedError
@abstractmethod
def iter_components(self) -> Iterator[Self]:
raise NotImplementedError
@abstractmethod
def remove_runs(self) -> dict[Edge, Edge]:
raise NotImplementedError
@abstractmethod
def remove_2cycles(self) -> list[Edge]:
raise NotImplementedError
@abstractmethod
def remove_self_loops(self) -> list[Edge]:
raise NotImplementedError
@abstractmethod
def is_acyclic(self):
raise NotImplementedError
@abstractmethod
def get_edge_weight(self, source: Node, target: Node) -> int:
raise NotImplementedError
@abstractmethod
def edge_between_components(self, source: Node, target: Node) -> bool:
raise NotImplementedError
@abstractmethod
def add_edges(self, edges: list[Edge]):
raise NotImplementedError
@abstractmethod
def add_edge(self, source: Node, target: Node):
raise NotImplementedError
@abstractmethod
def remove_edge(self, source: Node, target: Node):
raise NotImplementedError
@abstractmethod
def remove_edges(self, edges: list[Edge]):
raise NotImplementedError
@classmethod
@abstractmethod
def load_from_edge_list(cls, filename: str) -> tuple[Self, dict[str, Node]]:
raise NotImplementedError
@classmethod
@abstractmethod
def load_from_dot(cls, filename: str) -> tuple[Self, dict[str, Node]]:
raise NotImplementedError
@classmethod
@abstractmethod
def load_from_adjacency_list(
cls, filename: str
) -> tuple[Self, dict[str, Node]]:
raise NotImplementedError