-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphInterface.py
More file actions
83 lines (69 loc) · 2.87 KB
/
Copy pathGraphInterface.py
File metadata and controls
83 lines (69 loc) · 2.87 KB
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
class GraphInterface:
"""This abstract class represents an interface of a graph."""
def v_size(self) -> int:
"""
Returns the number of vertices in this graph
@return: The number of vertices in this graph
"""
raise NotImplementedError
def e_size(self) -> int:
"""
Returns the number of edges in this graph
@return: The number of edges in this graph
"""
raise NotImplementedError
def get_all_v(self) -> dict:
"""return a dictionary of all the nodes in the Graph, each node is represented using a pair
(node_id, node_data)
"""
def all_in_edges_of_node(self, id1: int) -> dict:
"""return a dictionary of all the nodes connected to (into) node_id ,
each node is represented using a pair (other_node_id, weight)
"""
def all_out_edges_of_node(self, id1: int) -> dict:
"""return a dictionary of all the nodes connected from node_id , each node is represented using a pair
(other_node_id, weight)
"""
def get_mc(self) -> int:
"""
Returns the current version of this graph,
on every change in the graph state - the MC should be increased
@return: The current version of this graph.
"""
raise NotImplementedError
def add_edge(self, id1: int, id2: int, weight: float) -> bool:
"""
Adds an edge to the graph.
@param id1: The start node of the edge
@param id2: The end node of the edge
@param weight: The weight of the edge
@return: True if the edge was added successfully, False o.w.
Note: If the edge already exists or one of the nodes dose not exists the functions will do nothing
"""
raise NotImplementedError
def add_node(self, node_id: int, pos: tuple = None) -> bool:
"""
Adds a node to the graph.
@param node_id: The node ID
@param pos: The position of the node
@return: True if the node was added successfully, False o.w.
Note: if the node id already exists the node will not be added
"""
raise NotImplementedError
def remove_node(self, node_id: int) -> bool:
"""
Removes a node from the graph.
@param node_id: The node ID
@return: True if the node was removed successfully, False o.w.
Note: if the node id does not exists the function will do nothing
"""
raise NotImplementedError
def remove_edge(self, node_id1: int, node_id2: int) -> bool:
"""
Removes an edge from the graph.
@param node_id1: The start node of the edge
@param node_id2: The end node of the edge
@return: True if the edge was removed successfully, False o.w.
Note: If such an edge does not exists the function will do nothing
"""
raise NotImplementedError