簡體   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