// Happy Friday!
// Happy almost-long-weekend!
-- TWO ADDITIONS
-- (1) yes, this model will only admit trees
-- with an odd number of nodes. This is because
-- of how it's handling Leaf nodes!
-- (2) To get heights to vizualize nicely, go
-- into the Theme menu when viewing an instance,
-- then select height. Uncheck show-as-arc and
-- check show-as-attribute.
abstract sig Node {height: Int} -- ghost variable
sig Leaf extends Node {}
sig Data extends Node {left, right: Node}
run {} for exactly 5 Node
fact rooted {
some r: Node | all n: Node-r | {
n in r.^(left + right)
}
}
fact acyclic {
all n: Node | n not in n.^(left + right)
}
fact loneParent {
all n: Node | {
// n.right != n.left -- over-constraint
no n.right & n.left
// lone n.~(left+right)
lone (left+right).n
}
}
fact heights {
all l: Leaf | l.height = 1
all d: Data | {
d.height = add[1, max[d.left.height + d.right.height]]
}
}