From e1f7097bc3d3a177c2b2fa00ba615132d3e52907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nina=20Chl=C3=B3e=20Kassandra=20Rei=C3=9F?= Date: Sat, 18 Jul 2026 21:34:45 +0200 Subject: [PATCH] Warshall algorithm reference --- adj2con.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 adj2con.py diff --git a/adj2con.py b/adj2con.py new file mode 100644 index 0000000..56af1d7 --- /dev/null +++ b/adj2con.py @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +""" +File: adj2con.py +Author: Nina Chloe Kassandra Reiß +Created on: Sa 18. Jul 11:30:03 CEST 2026 +Description: Turn adjacency matrices into boolean connectivity matrix +""" +adjacency = [[1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0]] + + +def warshall(adj): + n = len(adj) + + # Kopie erzeugen + R = [row[:] for row in adj] + + # Jeder Knoten ist von sich selbst erreichbar + for i in range(n): + R[i][i] = 1 + + for k in range(n): + for i in range(n): + for j in range(n): + R[i][j] = R[i][j] or (R[i][k] and R[k][j]) + + return R + + +print(warshall(adjacency))