是否可以在Alloy中模拟随机故障?
例如,我目前有一个连接图,它将各个时间步的数据传递给它的邻居。我想要做的是弄清楚允许模型随机杀死链接的一些方法,并且这样做仍然设法实现其目标(确保所有节点都将其数据状态设置为On)。
open util/ordering[Time]
enum Datum{Off, On} // A simple representation of the state of each node
sig Time{state:Node->one Datum} // at each time we have a network state
abstract sig Node{
neighbours:set Node
}
fact {
neighbours = ~neighbours -- symmetric
no iden & neighbours -- no loops
all n : Node | Node in n.*neighbours -- connected
-- all n : Node | (Node - n) in n.neighbours -- comp. connected
}
fact start{// At the start exactly one node has the datum
one n:Node|first.state[n]=On
}
fact simple_change{ // in one time step all neighbours of On nodes become on
all t:Time-last |
let t_on = t.state.On |
next[t].state.On = t_on+t_on.neighbours
}
run {} for 5 Time, 10 Node
我尝试在不确定性中模拟交易的软件。基本上,节点之间的链接可能会失败,并且软件会沿另一条路径重新路由。我想在Alloy中尝试做的是设置一些链接到' die'在某些时间步(最好随机)。在最重要的事实上,我有能力使图形完全连接,因此可能的是,如果链接死亡,另一个可能会收到松弛(因为simple_change将Datum的状态切换为On所有连接的邻居)。
修改
所以,我按照建议做了,并遇到了以下错误:
我很困惑,因为我认为邻居和节点仍然存在?
这是我更新的代码:
open util/ordering[Time]
open util/relation
enum Datum{Off, On} // A simple representation of the state of each node
sig Time{
neighbours : Node->Node,
state:Node->one Datum // at each time we have a network state
}{
symmetric[neighbours, Node]
}
abstract sig Node{
neighbours:set Node
}
fact {
neighbours = ~neighbours -- symmetric
no iden & neighbours -- no loops
-- all n : Node | (Node - n) in n.neighbours -- comp. connected
all n : Node | Node in n.*neighbours -- connected
}
// At the start exactly one node has the datum
fact start{
one n:Node|first.state[n]=On
}
// in one time step all neighbours of On nodes become on
fact simple_change{
all t:Time-last |
let t_on = t.state.On |
next[t].state.On = t_on+t_on.neighbours
all t:Time-last | next[t].neighbours in t.neighbours
all t:Time-last | lone t.neighbours - next[t].neighbours
}
run {} for 10 Time, 3 Node
答案 0 :(得分:3)
将邻居的定义移动到时间:
sig Time {neighbours : Node->Node, ....}
您需要重新表达相对于每个时间点的邻居对称性等事实。通过在时间签名的不变部分中执行此操作最容易实现:
sig Time {
neighbours : Node->Node,
...
}{
symmetric[neighbours, Node],
....
}
(我建议使用open util/relation
加载有用的定义,例如symmetric
。)
然后,通过添加诸如
之类的事实,时间步simple_change
会变得复杂
next[t].neighbours in t.neighbours
可以丢掉任意多个弧线。
如果您想限制每个步骤中丢弃的弧数,您可以添加更多事实,例如
lone t.neighbours - next[t].neighbours
将处理限制在最多一个弧线。