5.55. binary_tree
DESCRIPTION | LINKS | GRAPH |
- Origin
- Constraint
- Arguments
- Restrictions
- Purpose
Cover the digraph described by the collection with binary trees in such a way that each vertex of belongs to exactly one binary tree (i.e.,Β each vertex of has at most two children). The edges of the binary trees are directed from their leaves to their respective root.
- Example
-
The first constraint holds since its second argument corresponds to the 2 (i.e.,Β the first argument of the first constraint) binary trees depicted by FigureΒ 5.55.1.
Figure 5.55.1. The two binary trees corresponding to the first example of the Example slot; each vertex contains the information where is the index of its father in the tree (by convention the father of the root is the root itself).
- All solutions
FigureΒ 5.55.2 gives all solutions to the following non ground instance of the constraint: , , , , , , .
Figure 5.55.2. All solutions corresponding to the non ground example of the constraint of the All solutions slot; the attribute is displayed as indices of the attribute and all vertices of a same tree are coloured by the same colour.
- Typical
- Symmetry
Items of are permutable.
- Arg. properties
Functional dependency: determined by .
- Reformulation
The constraint can be expressed in term of (1)Β a set of reified constraints for avoiding circuit between more than one node and of (2)Β reified constraints and of one sum constraint for counting the trees and of (3)Β a set of reified constraints and of inequalities constraints for enforcing the fact that each vertex has at most two children.
For each vertex of the collection we create a variable that takes its value within interval . This variable represents the rank of vertex within a solution. It is used to prevent the creation of circuit involving more than one vertex as explained now. For each pair of vertices of the collection we create a reified constraint of the form . The purpose of this constraint is to express the fact that, if there is an arc from vertex to another vertex , then should be strictly less than .
For each vertex of the collection we create a 0-1 variable and state the following reified constraint in order to force variable to be set to value 1 if and only if there is a loop on vertex . Finally we create a constraint for stating the fact that the number of trees is equal to the number of loops of the graph.
For each pair of vertices of the collection we create a 0-1 variable and state the following reified constraint . Variable is set to value 1 if and only if there is an arc from to . Then for each vertex we create a constraint of the form .
- Counting
-
Length () 2 3 4 5 6 7 8 Solutions 3 16 121 1191 14461 209098 3510921 Number of solutions for : domains
Length () 2 3 4 5 6 7 8 Total 3 16 121 1191 14461 209098 3510921 Parameter value 1 2 9 60 540 6120 83790 1345680 2 1 6 48 480 5850 84420 1411200 3 - 1 12 150 2100 33390 599760 4 - - 1 20 360 6720 135240 5 - - - 1 30 735 17640 6 - - - - 1 42 1344 7 - - - - - 1 56 8 - - - - - - 1 Solution count for : domains
- See also
generalisation: Β (at most two childrens replaced by no restriction on maximum number of childrens).
implies: .
implies (items to collection): .
specialisation: Β (at most two childrens replaced by at most one child).
- Keywords
constraint type: graph constraint, graph partitioning constraint.
- Arc input(s)
- Arc generator
-
- Arc arity
- Arc constraint(s)
- Graph property(ies)
-
- Graph class
-
- Graph model
We use the same graph constraint as for the constraint, except that we add the graph property 2, which constraints the maximum in-degree of the final graph to not exceed 2. does not consider loops: This is why we do not have any problem with the root of each tree.
PartsΒ (A) andΒ (B) of FigureΒ 5.55.3 respectively show the initial and final graph associated with the first example of the Example slot. Since we use the graph property, we display the two connected components of the final graph. Each of them corresponds to a binary tree. Since we use the graph property, we also show with a double circle a vertex that has a maximum number of predecessors.
The constraint holds since all strongly connected components of the final graph have no more than one vertex, since 2 and since 2.
Figure 5.55.3. Initial and final graph of the constraint
(a) (b)