2022-03-30 18:00:11 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
import os;
|
|
|
|
import sys;
|
|
|
|
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'));
|
|
|
|
sys.path.insert(0, os.getcwd());
|
|
|
|
|
2022-04-18 19:04:42 +02:00
|
|
|
from src.core.log import *;
|
2022-04-07 16:41:33 +02:00
|
|
|
from src.graphs.graph import *;
|
|
|
|
from src.graphs.tarjan import *;
|
|
|
|
|
2022-03-30 18:00:11 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBAL CONSTANTS/VARIABLES
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# MAIN METHOD
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
def enter():
|
2022-04-07 16:41:33 +02:00
|
|
|
## Beispiel aus Seminarblatt 1
|
2022-04-18 19:04:42 +02:00
|
|
|
nodes = [1,2,3,4,5,6,7,8];
|
|
|
|
edges = [
|
|
|
|
(1,2),
|
|
|
|
(1,3),
|
|
|
|
(2,4),
|
|
|
|
(2,5),
|
|
|
|
(3,5),
|
|
|
|
(3,6),
|
|
|
|
(3,8),
|
|
|
|
(4,5),
|
|
|
|
(4,7),
|
|
|
|
(5,1),
|
|
|
|
(5,8),
|
|
|
|
(6,8),
|
|
|
|
(7,8),
|
|
|
|
(8,6),
|
|
|
|
];
|
|
|
|
G = Graph(nodes=nodes, edges=edges);
|
|
|
|
components = tarjan_algorithm(G, debug=True);
|
2022-04-07 16:41:33 +02:00
|
|
|
for component in components:
|
2022-04-18 19:04:42 +02:00
|
|
|
log_debug(component);
|
2022-03-30 18:00:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# EXECUTION
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
enter();
|