import SetFunctions data Node = A | B | C | D | E -- Graphdarstellung: Nachfolgerknotendarstellung succ :: Node -> Node succ A = B succ A = C succ B = A succ B = C succ B = D succ C = D succ C = E succ D = E succ E = C -- Weg zwischen zwei Knoten pathFromTo :: Node -> Node -> [Node] pathFromTo n1 n2 = extendPath n2 [n1] -- Erweitere einen Weg (umgekehrte Reihenfolge), -- bis wir ein Ziel erreicht haben. extendPath :: Node -> [Node] -> [Node] extendPath target path@(n:_) = if target==n then reverse path else extendPath target ((succ n) `consNoCycle` path) -- Constrained Constructor: Listenkonstruktor mit Fehlschlag, -- falls die Liste zyklisch wird. consNoCycle :: a -> [a] -> [a] consNoCycle x xs | all (x/=) xs = x : xs -- Kuerzester Pfad: berechne alle und suche kuerzesten shortestPath :: Node -> Node -> [Node] shortestPath n1 n2 = minValue shorter ((set2 pathFromTo) n1 n2) where shorter p1 p2 = length p1 < length p2