testing - 合金阵列模型
问题描述
我刚开始学习合金模型语言,并试图在合金中编写自己的数组模型。但是,我无法从关系中提取索引。这是我的标志和事实:
sig Element {}
one sig Array {
// Map index to element
IdxEle: Int -> Element,
// Length of the array.
length: Int
}
fact Index {
all r : IdxEle | r.Int >= 0 and r.Int < length
}
我得到的错误是
This must be an integer expression.
Instead, it has the following possible type(s):
{none->none}
我查看了参考指南,但找不到提取关系的 idx 字段的方法。有人可以帮帮我吗?谢谢
解决方案
首先,r
在您的模型中是 type Array->Int->Element
,因此(Array->Int->Element).Int
无法计算,因为元组中的最后一列是 Element 类型,而不是您似乎期望的 Int 类型。(加入合金时,左侧最后一列必须与右侧第一列相同类型。)
其次,有更简单、更灵活、更易读的方式来表达你想要的:
sig Element {}
let range[start,end] = { i : Int | i >= start and i < end }
one sig Array { index : Int -> Element } {
index.Element = range[ 0, len[this] ]
}
fun len[ array : Array ] : Int { # array.index }
第三...有一个内置类型为您调用seq
。它拥有您想要的一切以及更多。
推荐阅读
- javascript - 当从 yAxis 出现 plotband 和 plotline 时,如何仅在 highchart 中为 plotband 设置特定宽度
- spring - 弹簧执行器端点似乎被调用了两次
- javascript - 如何在javascript中添加preventDefault?
- python - 从 django app hpsted 在 aws 上运行 unix shell 命令并使用 apache2 Web 服务器
- python - FiPy 中一维扩散方程的默认边界条件实现
- python - 无法从网页中提取带有熊猫的嵌套表体
- r - R:gganimate 与 geom_density
- machine-learning - 持续的训练损失和验证损失
- sql - Postgres 喜欢全文搜索
- css - vuetify:不显示 v-img 中的标签