this repo has no description
1include "subgraph.mzn";
2
3predicate fzn_dtree(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 set of int: EDGE = index_set(es);
7 array[index_set(ns)] of var 0..length(ns)-1: dist; /* distance from root */
8 array[index_set(ns)] of var index_set(ns): parent; /* parent */
9 } in
10 ns[r] /\ % the root must be chosen
11 dist[r] = 0 /\ % root is at distance 0
12 parent[r] = r /\ % root is its own parent
13 forall(n in index_set(ns)) % nonselected nodes have parent 0
14 (not ns[n] -> parent[n] = n) /\
15 forall(n in index_set(ns)) % nonselected nodes have distance 0
16 (not ns[n] -> dist[n] = 0) /\
17 forall(n in index_set(ns)) % each in node except root must have a parent
18 (ns[n] -> (n = r \/ parent[n] != n)) /\
19 forall(n in index_set(ns)) % each in node with a parent must be in and also its parent
20 (parent[n] != n -> (ns[n] /\ ns[parent[n]])) /\
21 forall(n in index_set(ns)) % each except with a parent is one more than its parent
22 (parent[n] != n -> dist[n] = dist[parent[n]] + 1) /\
23 forall(n in index_set(ns)) % each node with a parent must have that edge in
24 (parent[n] != n -> exists(e in EDGE where to[e] = n)(es[e] /\ from[e] = parent[n])) /\
25 forall(e in EDGE) % each edge must be part of the parent relation
26 (es[e] -> parent[to[e]] = from[e]) /\
27 sum(e in EDGE)(es[e]) = sum(n in index_set(ns))(ns[n]) - 1 /\ % redundant relationship of trees
28 subgraph(from,to,ns,es);
29
30%-----------------------------------------------------------------------------%