是否有更好的树木合金模型?

时间:2017-01-17 22:09:41

标签: alloy

我创建了一个树模型。见下文。有更好的型号吗? “更好”我的意思是更简单。

sig Node {
    tree: set Node
}

one sig root extends Node {}

fact {
    // No node above root (no node maps to root)
    no tree.root
    // Can reach all nodes from root                
    all n: Node - root | n in root.^tree
    // No node maps to itself (irreflexive) 
    no iden & tree
    // No cycles                    
    no n: Node | Node in n.^tree
    // All nodes are distinct (injective)           
    tree.~tree in iden
}

1 个答案:

答案 0 :(得分:1)

这有什么不简单的?您可以简化约束:

sig Node {
    tree: set Node
}

one sig root extends Node {}

pred CostelloTree {
    // No node above root (no node maps to root)
    no tree.root
    // Can reach all nodes from root                
    all n: Node - root | n in root.^tree
    // No node maps to itself (irreflexive) 
    no iden & tree
    // No cycles                    
    no n: Node | Node in n.^tree
    // All nodes are distinct (injective)           
    tree.~tree in iden
}

pred DJTree {
    Node in root.*tree // all reachable
    no iden & ^tree // no cycles
    tree in Node lone -> Node // at most one parent
    }

check {CostelloTree iff DJTree}