this repo has no description
1include "subgraph.mzn";
2
3predicate fzn_dreachable(int: N, int: E, array[int] of int: from, array[int] of int: to,
4 var int: r, array[int] of var bool: ns, array[int] of var bool: es) =
5 let {
6 set of int: NODE = 1..N;
7 array[NODE] of var 0..N-1: dist; /* distance from root */
8 array[NODE] of var 0..N: parent; /* parent */
9 } in
10 ns[r] /\ % the root must be chosen
11 dist[r] = 0 /\ % root is at distance 0
12 forall(n in NODE) % nonselected nodes have parent 0
13 (not ns[n] -> parent[n] = 0) /\
14 forall(n in NODE) % nonselected nodes have distance 0
15 (not ns[n] -> dist[n] = 0) /\
16 forall(n in NODE) % each in node except root must have a parent
17 (ns[n] -> (n = r \/ parent[n] > 0)) /\
18 forall(n in NODE) % each in node with a parent must be in and also its parent
19 (parent[n] > 0 -> (ns[n] /\ ns[parent[n]])) /\
20 forall(n in NODE) % each except with a parent is one more than its parent
21 (parent[n] > 0 -> dist[n] = dist[parent[n]] + 1) /\
22 forall(n in NODE) % each node with a parent must have that edge in
23 (parent[n] > 0 -> exists(e in 1..E)(es[e] /\ from[e] = parent[n] /\ to[e] = n)) /\
24 subgraph(N,E,from,to,ns,es);
25
26%-----------------------------------------------------------------------------%