5.55. binary_tree

DESCRIPTIONLINKSGRAPH
Origin

Derived from πšπš›πšŽπšŽ.

Constraint

πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ(π™½πšƒπšπ™΄π™΄πš‚,π™½π™Ύπ™³π™΄πš‚)

Arguments
π™½πšƒπšπ™΄π™΄πš‚πšπšŸπšŠπš›
π™½π™Ύπ™³π™΄πš‚πšŒπš˜πš•πš•πšŽπšŒπšπš’πš˜πš—(πš’πš—πšπšŽπš‘-πš’πš—πš,𝚜𝚞𝚌𝚌-πšπšŸπšŠπš›)
Restrictions
π™½πšƒπšπ™΄π™΄πš‚β‰₯0
π™½πšƒπšπ™΄π™΄πš‚β‰€|π™½π™Ύπ™³π™΄πš‚|
πš›πšŽπššπšžπš’πš›πšŽπš(π™½π™Ύπ™³π™΄πš‚,[πš’πš—πšπšŽπš‘,𝚜𝚞𝚌𝚌])
π™½π™Ύπ™³π™΄πš‚.πš’πš—πšπšŽπš‘β‰₯1
π™½π™Ύπ™³π™΄πš‚.πš’πš—πšπšŽπš‘β‰€|π™½π™Ύπ™³π™΄πš‚|
πšπš’πšœπšπš’πš—πšŒπš(π™½π™Ύπ™³π™΄πš‚,πš’πš—πšπšŽπš‘)
π™½π™Ύπ™³π™΄πš‚.𝚜𝚞𝚌𝚌β‰₯1
π™½π™Ύπ™³π™΄πš‚.πšœπšžπšŒπšŒβ‰€|π™½π™Ύπ™³π™΄πš‚|
Purpose

Cover the digraph G described by the π™½π™Ύπ™³π™΄πš‚ collection with π™½πšƒπšπ™΄π™΄πš‚ binary trees in such a way that each vertex of G belongs to exactly one binary tree (i.e.,Β each vertex of G has at most two children). The edges of the binary trees are directed from their leaves to their respective root.

Example
2,πš’πš—πšπšŽπš‘-1𝚜𝚞𝚌𝚌-1,πš’πš—πšπšŽπš‘-2𝚜𝚞𝚌𝚌-3,πš’πš—πšπšŽπš‘-3𝚜𝚞𝚌𝚌-5,πš’πš—πšπšŽπš‘-4𝚜𝚞𝚌𝚌-7,πš’πš—πšπšŽπš‘-5𝚜𝚞𝚌𝚌-1,πš’πš—πšπšŽπš‘-6𝚜𝚞𝚌𝚌-1,πš’πš—πšπšŽπš‘-7𝚜𝚞𝚌𝚌-7,πš’πš—πšπšŽπš‘-8𝚜𝚞𝚌𝚌-5
8,πš’πš—πšπšŽπš‘-1𝚜𝚞𝚌𝚌-1,πš’πš—πšπšŽπš‘-2𝚜𝚞𝚌𝚌-2,πš’πš—πšπšŽπš‘-3𝚜𝚞𝚌𝚌-3,πš’πš—πšπšŽπš‘-4𝚜𝚞𝚌𝚌-4,πš’πš—πšπšŽπš‘-5𝚜𝚞𝚌𝚌-5,πš’πš—πšπšŽπš‘-6𝚜𝚞𝚌𝚌-6,πš’πš—πšπšŽπš‘-7𝚜𝚞𝚌𝚌-7,πš’πš—πšπšŽπš‘-8𝚜𝚞𝚌𝚌-8
7,πš’πš—πšπšŽπš‘-1𝚜𝚞𝚌𝚌-8,πš’πš—πšπšŽπš‘-2𝚜𝚞𝚌𝚌-2,πš’πš—πšπšŽπš‘-3𝚜𝚞𝚌𝚌-3,πš’πš—πšπšŽπš‘-4𝚜𝚞𝚌𝚌-4,πš’πš—πšπšŽπš‘-5𝚜𝚞𝚌𝚌-5,πš’πš—πšπšŽπš‘-6𝚜𝚞𝚌𝚌-6,πš’πš—πšπšŽπš‘-7𝚜𝚞𝚌𝚌-7,πš’πš—πšπšŽπš‘-8𝚜𝚞𝚌𝚌-8

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).
ctrs/binary_tree-1-tikz
All solutions

FigureΒ 5.55.2 gives all solutions to the following non ground instance of the πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ constraint: π™½πšƒπšπ™΄π™΄πš‚βˆˆ{1,4}, S 1 ∈[1,2], S 2 ∈[1,3], S 3 ∈[3,4], S 4 ∈[3,4], S 5 ∈[2,3], πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ(π™½πšƒπšπ™΄π™΄πš‚,〈1 S 1 ,2 S 2 ,3 S 3 ,4 S 4 ,5 S 5 βŒͺ).

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.
ctrs/binary_tree-2-tikz
Typical
π™½πšƒπšπ™΄π™΄πš‚>0
π™½πšƒπšπ™΄π™΄πš‚<|π™½π™Ύπ™³π™΄πš‚|
|π™½π™Ύπ™³π™΄πš‚|>2
Symmetry

Items of π™½π™Ύπ™³π™΄πš‚ are permutable.

Arg. properties

Functional dependency: π™½πšƒπšπ™΄π™΄πš‚ determined by π™½π™Ύπ™³π™΄πš‚.

Reformulation

The πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ constraint can be expressed in term of (1)Β a set of |π™½π™Ύπ™³π™΄πš‚| 2 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 |π™½π™Ύπ™³π™΄πš‚| 2 reified constraints and of |π™½π™Ύπ™³π™΄πš‚| inequalities constraints for enforcing the fact that each vertex has at most two children.

  1. For each vertex π™½π™Ύπ™³π™΄πš‚[i] (i∈[1,|π™½π™Ύπ™³π™΄πš‚|]) of the π™½π™Ύπ™³π™΄πš‚ collection we create a variable R i that takes its value within interval [1,|π™½π™Ύπ™³π™΄πš‚|]. This variable represents the rank of vertex π™½π™Ύπ™³π™΄πš‚[i] 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 π™½π™Ύπ™³π™΄πš‚[i],π™½π™Ύπ™³π™΄πš‚[j] (i,j∈[1,|π™½π™Ύπ™³π™΄πš‚|]) of the π™½π™Ύπ™³π™΄πš‚ collection we create a reified constraint of the form π™½π™Ύπ™³π™΄πš‚[i].𝚜𝚞𝚌𝚌=π™½π™Ύπ™³π™΄πš‚[j].πš’πš—πšπšŽπš‘βˆ§iβ‰ jβ‡’R i <R j . The purpose of this constraint is to express the fact that, if there is an arc from vertex π™½π™Ύπ™³π™΄πš‚[i] to another vertex π™½π™Ύπ™³π™΄πš‚[j], then R i should be strictly less than R j .

  2. For each vertex π™½π™Ύπ™³π™΄πš‚[i] (i∈[1,|π™½π™Ύπ™³π™΄πš‚|]) of the π™½π™Ύπ™³π™΄πš‚ collection we create a 0-1 variable B i and state the following reified constraint π™½π™Ύπ™³π™΄πš‚[i].𝚜𝚞𝚌𝚌=π™½π™Ύπ™³π™΄πš‚[i].πš’πš—πšπšŽπš‘β‡”B i in order to force variable B i to be set to value 1 if and only if there is a loop on vertex π™½π™Ύπ™³π™΄πš‚[i]. Finally we create a constraint π™½πšƒπšπ™΄π™΄πš‚=B 1 +B 2 +β‹―+B |π™½π™Ύπ™³π™΄πš‚| for stating the fact that the number of trees is equal to the number of loops of the graph.

  3. For each pair of vertices π™½π™Ύπ™³π™΄πš‚[i],π™½π™Ύπ™³π™΄πš‚[j] (i,j∈[1,|π™½π™Ύπ™³π™΄πš‚|]) of the π™½π™Ύπ™³π™΄πš‚ collection we create a 0-1 variable B ij and state the following reified constraint π™½π™Ύπ™³π™΄πš‚[i].𝚜𝚞𝚌𝚌=π™½π™Ύπ™³π™΄πš‚[j].πš’πš—πšπšŽπš‘βˆ§iβ‰ j⇔B ij . Variable B ij is set to value 1 if and only if there is an arc from π™½π™Ύπ™³π™΄πš‚[i] to π™½π™Ύπ™³π™΄πš‚[j]. Then for each vertex π™½π™Ύπ™³π™΄πš‚[j] (j∈[1,|π™½π™Ύπ™³π™΄πš‚|]) we create a constraint of the form B 1j +B 2j +β‹―+B |π™½π™Ύπ™³π™΄πš‚|j ≀2.

Counting
Length (n)2345678
Solutions3161211191144612090983510921

Number of solutions for πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ: domains 0..n

ctrs/binary_tree-3-tikz

ctrs/binary_tree-4-tikz

Length (n)2345678
Total3161211191144612090983510921
Parameter
value

129605406120837901345680
216484805850844201411200
3-112150210033390599760
4--1203606720135240
5---13073517640
6----1421344
7-----156
8------1

Solution count for πš‹πš’πš—πšŠπš›πš’_πšπš›πšŽπšŽ: domains 0..n

ctrs/binary_tree-5-tikz

ctrs/binary_tree-6-tikz

See also

generalisation: πšπš›πšŽπšŽΒ (at most two childrens replaced by no restriction on maximum number of childrens).

implied by: πš™πšŠπšπš‘.

implies: πšπš›πšŽπšŽ.

implies (items to collection): πšŠπšπš•πšŽπšŠπšœπš_πš—πšŸπšŽπšŒπšπš˜πš›.

specialisation: πš™πšŠπšπš‘Β (at most two childrens replaced by at most one child).

Keywords

constraint type: graph constraint, graph partitioning constraint.

final graph structure: connected component, tree, one_succ.

modelling: functional dependency.

Arc input(s)

π™½π™Ύπ™³π™΄πš‚

Arc generator
πΆπΏπΌπ‘„π‘ˆπΈβ†¦πšŒπš˜πš•πš•πšŽπšŒπšπš’πš˜πš—(πš—πš˜πšπšŽπšœ1,πš—πš˜πšπšŽπšœ2)

Arc arity
Arc constraint(s)
πš—πš˜πšπšŽπšœ1.𝚜𝚞𝚌𝚌=πš—πš˜πšπšŽπšœ2.πš’πš—πšπšŽπš‘
Graph property(ies)
β€’ πŒπ€π—_𝐍𝐒𝐂𝐂≀1
β€’ 𝐍𝐂𝐂=π™½πšƒπšπ™΄π™΄πš‚
β€’ πŒπ€π—_πˆπƒβ‰€2

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
ctrs/binary_treeActrs/binary_treeB
(a) (b)