Skip to content

Commit 2560bc8

Browse files
committed
Add Graphs!SimplePath.
[Feature]
1 parent 87fdc6a commit 2560bc8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/Graphs.tla

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
------------------------------- MODULE Graphs -------------------------------
22
LOCAL INSTANCE Naturals
33
LOCAL INSTANCE Sequences
4+
LOCAL INSTANCE SequencesExt
45

56
IsDirectedGraph(G) ==
67
/\ G = [node |-> G.node, edge |-> G.edge]
@@ -26,6 +27,13 @@ Path(G) == {p \in Seq(G.node) :
2627
/\ p # << >>
2728
/\ \A i \in 1..(Len(p)-1) : <<p[i], p[i+1]>> \in G.edge}
2829

30+
SimplePath(G) ==
31+
\* A simple path is a path with no repeated nodes.
32+
{p \in SeqOf(G.node, Cardinality(G.node)) :
33+
/\ p # << >>
34+
/\ Cardinality({ p[i] : i \in DOMAIN p}) = Len(p)
35+
/\ \A i \in 1..(Len(p)-1) : <<p[i], p[i+1]>> \in G.edge}
36+
2937
AreConnectedIn(m, n, G) ==
3038
\E p \in Path(G) : (p[1] = m) /\ (p[Len(p)] = n)
3139

0 commit comments

Comments
 (0)