Umstellen der Auswertungslogik

This commit is contained in:
Oliver Hofmann
2026-03-31 11:30:26 +02:00
parent c48b5c7e59
commit 1dfdff9391
25 changed files with 49 additions and 558 deletions
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from bubble_sorting import bubble_sort_stepwise
@@ -1,6 +1,6 @@
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from utils.algo_range import irange
from utils.algo_range import Range
def bubble_sort_stepwise(z: Array, ctx: AlgoContext):
@@ -11,8 +11,8 @@ def bubble_sort_stepwise(z: Array, ctx: AlgoContext):
Wird von bubble_game.py für die Visualisierung verwendet.
"""
n = len(z)
for i in irange(n - 1):
for j in irange(n - 1, i, -1):
for i in Range(n - 1):
for j in Range(n - 1, i, -1):
if z[j - 1] > z[j]:
z.swap(j - 1, j)
yield z
@@ -27,7 +27,7 @@ def bubble_sort2_stepwise(z: Array, ctx: AlgoContext):
n = len(z)
while True:
swapped = False
for i in irange(n - 1):
for i in Range(n - 1):
if z[i] > z[i + 1]:
z.swap(i, i + 1)
swapped = True
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from insert_sorting import insert_sort_stepwise
@@ -1,7 +1,7 @@
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from utils.algo_int import Int
from utils.algo_range import irange
from utils.algo_range import Range
def insert_sort_stepwise(z: Array, ctx: AlgoContext):
@@ -13,7 +13,7 @@ def insert_sort_stepwise(z: Array, ctx: AlgoContext):
n = len(z)
elem = Int(0, ctx) # Zwischenregister für das einzufügende Element
for i in irange(n):
for i in Range(n):
elem.set(z[i]) # 1 read + 1 write
j = Int(int(i), ctx)
while j > 0 and z[j - 1] > elem:
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from select_sorting import select_sort_stepwise
@@ -1,7 +1,7 @@
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from utils.algo_int import Int
from utils.algo_range import irange
from utils.algo_range import Range
def select_sort_stepwise(z: Array, ctx: AlgoContext):
@@ -13,9 +13,9 @@ def select_sort_stepwise(z: Array, ctx: AlgoContext):
n = len(z)
cur_min = Int(0, ctx) # Index des aktuellen Minimums
for i in irange(n):
for i in Range(n):
cur_min.set(Int(int(i), ctx))
for j in irange(int(i) + 1, n):
for j in Range(int(i) + 1, n):
if z[j] < z[cur_min]:
cur_min.set(Int(int(j), ctx))
z.swap(int(i), int(cur_min))
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from heap_sorting import heap_sort_stepwise
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from quick_sorting import quick_sort_stepwise
@@ -1,6 +1,6 @@
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from utils.algo_range import irange
from utils.algo_range import Range
def count_sort(a: Array, b: Array, k: int, ctx: AlgoContext):
@@ -14,15 +14,15 @@ def count_sort(a: Array, b: Array, k: int, ctx: AlgoContext):
c = Array([0] * (k + 1), ctx) # Zählarray
# Häufigkeiten zählen
for j in irange(len(a)):
for j in Range(len(a)):
c[a[j]] = c[a[j]] + 1
# Kumulierte Summen bilden
for i in irange(1, k + 1):
for i in Range(1, k + 1):
c[i] = c[i] + c[i - 1]
# Stabil in b einsortieren (rückwärts für Stabilität)
for j in irange(len(a) - 1, -1, -1):
for j in Range(len(a) - 1, -1, -1):
b[c[a[j]] - 1] = a[j]
c[a[j]] = c[a[j]] - 1
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from avl_tree import AVLTree
+2 -2
View File
@@ -1,6 +1,6 @@
from vorlesung.L05_binaere_baeume.bin_tree_node import BinaryTreeNode
from utils.algo_context import AlgoContext
from utils.project_dir import get_path
from utils.algo_path import path
from datetime import datetime
import graphviz
@@ -148,7 +148,7 @@ class BinaryTree:
self.tree_structure_traversal(define_node)
_rec(self.root)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
dot.render(get_path(f"{self.graph_filename()}_{timestamp}.gv"))
dot.render(path(f"{self.graph_filename()}_{timestamp}.gv"))
if __name__ == "__main__":
@@ -1,6 +1,6 @@
import random
import pygame
from utils.game import Game
from utils.algo_game import Game
from utils.algo_context import AlgoContext
from bin_tree import BinaryTree
+1 -1
View File
@@ -2,7 +2,7 @@ from collections.abc import Callable
from utils.algo_context import AlgoContext
from utils.algo_array import Array
from utils.algo_int import Int
from utils.algo_range import irange
from utils.algo_range import Range
UNUSED_MARK = "UNUSED"
-45
View File
@@ -1,45 +0,0 @@
from vorlesung.L08_graphen.graph import Graph, AdjacencyMatrixGraph
from utils.project_dir import get_path
graph = AdjacencyMatrixGraph()
start = ""
end = ""
def read_file(filename: str = "data/aoc2212.txt"):
"""Read a file and return the content as a string."""
def adjust_char(char):
"""Adjust character for comparison."""
if char == 'S':
return 'a'
elif char == 'E':
return 'z'
return char
global start, end
with open(get_path(filename), "r") as file:
quest = file.read().strip().splitlines()
for row, line in enumerate(quest):
for col, char in enumerate(line):
label = f"{row},{col}"
graph.insert_vertex(label)
if char == "S":
start = label
if char == "E":
end = label
for row, line in enumerate(quest):
for col, char in enumerate(line):
for neighbor in [(row - 1, col), (row, col - 1), (row + 1, col), (row, col + 1)]:
if 0 <= neighbor[0] < len(quest) and 0 <= neighbor[1] < len(line):
if ord(adjust_char(quest[neighbor[0]][neighbor[1]])) <= ord(adjust_char(char)) + 1:
label1 = f"{row},{col}"
label2 = f"{neighbor[0]},{neighbor[1]}"
graph.connect(label1, label2)
# Lösung des Adventskalenders 2022, Tag 12
read_file("data/aoc2212test.txt")
graph.graph()
distance_map, predecessor_map = graph.bfs(start)
print(distance_map[graph.get_vertex(end)])
print(graph.path(end, predecessor_map))
+3 -3
View File
@@ -5,8 +5,8 @@ import graphviz
import math
import heapq
from datetime import datetime
from utils.project_dir import get_path
from utils.priority_queue import PriorityQueue
from utils.algo_path import path
from utils.algo_priority_queue import PriorityQueue
from vorlesung.L09_mst.disjoint import DisjointValue
@@ -155,7 +155,7 @@ class Graph:
dot.edge(str(id(self.get_vertex(edge[0]))), str(id(self.get_vertex(edge[1]))), label=str(edge[2]))
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{filename}_{timestamp}.gv"
filename = get_path(filename)
filename = path(filename)
dot.render(filename)
def dijkstra(self, start_name: str) -> tuple[dict[Vertex, float], dict[Vertex, Vertex | None]]: