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