From a8c5c3a4ebe77a372a991c0fa8a557292fc5ea8e Mon Sep 17 00:00:00 2001 From: hbui <hong-phuc.bui@htwsaar.de> Date: Fri, 19 Jul 2024 01:31:57 +0200 Subject: [PATCH] add RiemannSum Implementierung --- stundenplan/src/pygraph/graphdemo.py | 40 ++++++++++++++++++++++++---------------- 1 files changed, 24 insertions(+), 16 deletions(-) diff --git a/stundenplan/src/pygraph/graphdemo.py b/stundenplan/src/pygraph/graphdemo.py index 202e779..28bf931 100644 --- a/stundenplan/src/pygraph/graphdemo.py +++ b/stundenplan/src/pygraph/graphdemo.py @@ -1,23 +1,23 @@ class Graph: def __init__(self): - self.adjacent: dict[int, set] = {} - self.vertex_attribute: dict[int, dict] = {} + self._adjacent: dict[int, set] = {} + self._vertex_attribute: dict[int, dict] = {} def add_vertex(self, vertex): - if vertex not in self.adjacent: + if vertex not in self._adjacent: if not isinstance(vertex, int): raise TypeError(f"Argument {vertex} is not a valid vertex") - self.adjacent[vertex] = set() + self._adjacent[vertex] = set() pass def add_edge(self, u, v): self.add_vertex(u) self.add_vertex(v) - v_neighbor = self.adjacent[v] + v_neighbor = self._adjacent[v] if u not in v_neighbor: v_neighbor.add(u) - u_neighbor = self.adjacent[u] + u_neighbor = self._adjacent[u] if v not in u_neighbor: u_neighbor.add(v) pass @@ -34,31 +34,31 @@ :param properties: :return: self """ - if vertex not in self.adjacent: + if vertex not in self._adjacent: raise ValueError(f"Graph does not include vertex {vertex}") - old_attributes = self.vertex_attribute[vertex] - self.vertex_attribute[vertex] = old_attributes | properties + old_attributes = self._vertex_attribute[vertex] + self._vertex_attribute[vertex] = old_attributes | properties return self pass def get_attribute(self, vertex): - if vertex in self.adjacent: - return self.vertex_attribute[vertex] + if vertex in self._adjacent: + return self._vertex_attribute[vertex] else: raise ValueError(f"Graph does not include vertex {vertex}") pass def vertices(self): - return self.adjacent.keys() + return self._adjacent.keys() def for_each_vertices(self, action): for v in self.vertices(): action(v) def adjacent_of(self, vertex): - if vertex not in self.adjacent: + if vertex not in self._adjacent: raise ValueError(f"Graph does not include vertex {vertex}") - return self.adjacent.get(vertex) + return self._adjacent.get(vertex) def for_each_edges(self, action): visited_edges: dict[int, set] = {} @@ -76,13 +76,21 @@ adjacent.add(second) action(start, end) + def get_lecture_name(self, vertex): + pass + + def set_lecture_name(self, vertex, name): + pass + def __repr__(self): text = "" - sorted_key = sorted(self.adjacent.keys()) + sorted_key = sorted(self._adjacent.keys()) last_key = sorted_key.pop() - def adjacent_fn(vertex): return "[" + ", ".join( [str(v) for v in self.adjacent[vertex]] ) + "]" + def adjacent_fn(vertex): return "[" + ", ".join([str(v) for v in self._adjacent[vertex]]) + "]" for key in sorted_key: text += f"{key} → {adjacent_fn(key)}\n" text += f"{last_key} → {adjacent_fn(last_key)}" return text + def to_dot(self) -> str: + pass -- Gitblit v1.10.0-SNAPSHOT