Hong-Phuc Bui
2024-09-27 8a9933e4decb3b6a57b47b6409474bd476920c24
stundenplan/src/pygraph/graphdemo.py
@@ -2,6 +2,9 @@
class Graph:
    """
    represents an undirected and unweighted Graph
    """
    def __init__(self):
        self._adjacent: dict[int, set] = {}
        self._vertex_attribute: dict[int, dict] = {}
@@ -25,7 +28,7 @@
            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
@@ -44,7 +47,7 @@
        """
        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
@@ -75,7 +78,7 @@
    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]):
        """
@@ -87,21 +90,18 @@
            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 = ""