繁体   English   中英

合金中有多件套吗?

[英]Are there multisets in Alloy?

有没有办法在Alloy中使用bag(multisets)来建模系统? 而且,如果没有明确的“袋”概念,是否有任何可行的解决方法?

谢谢。

E的多集[aka bag]用函数E->一个自然的,或E->孤独的(自然零)表示(取决于口味如何处理缺席)。

open util/natural
sig E {}
sig A { m : E -> one Natural }
sig B { n : E -> lone (Natural-Zero) }

fun bagunion[m, n : univ -> lone Natural]: univ -> lone Natural
{ e : (m+n).univ, x : Natural |      e in m.univ-n.univ implies x=e.m
                                else e in n.univ-m.univ implies x=e.n
                                else x=add[e.m, e.n]                  }

可能有更整洁的方式进行袋装合并。

感谢您的所有帮助,但最终我通过以下方式做到了:

首先,我将袋子限制为仅包含非零多重性的元素

module bags

open util/natural
open util/relation

sig Element{}

sig Bag{
    elements: Element -> one Natural
}{
    all e: Element.elements | e != Zero
}

并这样编码并集/差异/交集:

fun BagUnion[b1, b2 : Element -> one Natural]: Element -> one Natural{
    let e = (dom[b1] + dom[b2]) | e -> add[e.b1, e.b2]  
}

fun BagDifference[b1, b2 : Element -> one Natural]: Element -> one Natural{
    let e = dom[b1] | e -> max[Zero + sub[e.b1, e.b2]] 
}

fun BagIntersection[b1, b2 : Element -> one Natural]: Element -> one Natural{
    let e = (dom[b1] & dom[b2]) | e -> min[e.b1 + e.b2] 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM