| | |
| | | |
| | | |
| | | class Graph: |
| | | """ |
| | | represents an undirected and unweighted Graph |
| | | """ |
| | | def __init__(self): |
| | | self._adjacent: dict[int, set] = {} |
| | | self._vertex_attribute: dict[int, dict] = {} |
| | |
| | | u_neighbor.add(v) |
| | | pass |
| | | |
| | | def add_edges(self, u: int, adjacent:[int]): |
| | | def add_edges(self, u: int, adjacent: list[int]): |
| | | for v in adjacent: |
| | | self.add_edge(u, v) |
| | | pass |
| | |
| | | """ |
| | | if vertex not in self._adjacent: |
| | | raise ValueError(f"Graph does not include vertex {vertex}") |
| | | old_attributes = self._vertex_attribute.get(vertex) |
| | | old_attributes = self._vertex_attribute[vertex] |
| | | self._vertex_attribute[vertex] = old_attributes | properties |
| | | return self |
| | | pass |
| | |
| | | def adjacent_of(self, vertex: int): |
| | | if vertex not in self._adjacent: |
| | | raise ValueError(f"Graph does not include vertex {vertex}") |
| | | return sorted( self._adjacent.get(vertex) ) |
| | | return sorted( self._adjacent[vertex] ) |
| | | |
| | | def for_each_edges(self, action: Callable[[int, int], Any]): |
| | | """ |
| | |
| | | for end in self.adjacent_of(start): |
| | | (first, second) = (start, end) if (start >= end) else (end, start) |
| | | if first in visited_edges: |
| | | visited_adjacent = visited_edges.get(first) |
| | | #visited_adjacent = visited_edges.get(first) |
| | | visited_adjacent = visited_edges[first] |
| | | if second not in visited_adjacent: |
| | | visited_adjacent.add(second) |
| | | action(start, end) |
| | | else: |
| | | adjacent = set() |
| | | adjacent: set[int] = set() |
| | | visited_edges[first] = adjacent |
| | | adjacent.add(second) |
| | | action(start, end) |
| | | |
| | | def get_lecture_name(self, vertex: int): |
| | | pass |
| | | |
| | | def set_lecture_name(self, vertex: int, name: str): |
| | | pass |
| | | |
| | | def __repr__(self): |
| | | text = "" |