Modeling a completely connected graph in Alloy

安稳与你 提交于 2019-12-23 20:13:18

问题


I'm trying to get my feet wet with Alloy (also relatively new-ish to formal logic as well), and I'm trying to start with a completely connected graph of nodes.

sig Node {
  adj : set Node
}

fact {
  adj = ~adj    -- symmetrical
  no iden & adj     -- no loops
  all n : Node | Node in n.*adj -- connected
}

pred ex { }
run ex for exactly 3 Node

As you can see from the image, Nodes 0 and 1 aren't connected. I thought that my fact was enough to make it completely connected...but perhaps I missed something.


回答1:


How about

adj = Node -> Node - iden

This basically says that adj contains all possible pairs of nodes, except identities (self-loops).

The reason why it is ok that Node1 and Node2 are not connected for your model is the last clause of your fact which constrains that for each node, all nodes are transitively reachable, but it seems to me that you want them to be immediately reachable. Alternatively to using my solution above, you can change

all n: Node | Node in n.*adj to all n: Node | (Node - n) in n.adj

to get the same effect.



来源:https://stackoverflow.com/questions/13614740/modeling-a-completely-connected-graph-in-alloy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!