小型尺寸的长度

发布于 2025-02-06 04:22:04 字数 261 浏览 1 评论 0原文

如果我这样定义了我的数组:

array[_, 1..2] of J: A;

j在哪里是枚举,我可以使用什么函数来获取A的第一维度的长度? 长度函数返回14(并指出它不适用于多个维度)。在测试中,我像这样进行了硬编码,但它并不总是13:

constraint forall(row in 1..13)(S[A[row, 2]] >= C[A[row, 1]]);

If I define my array like this:

array[_, 1..2] of J: A;

where J is a enum, what function can I use to get the length of the first dimension of A? The length function returns 14 (and states that it doesn't work for multiple dimensions). I had it hard-coded like so in my testing, but it won't always be 13:

constraint forall(row in 1..13)(S[A[row, 2]] >= C[A[row, 1]]);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2025-02-13 04:22:04

长度函数实际上仅是为了获取元素数量。当您想要阵列的检索索引时,应该使用index_set函数。这将返回实际的索引集,您可以迭代:i在index_set(a)中

用于多维阵列中,每个数组的每个索引集都有特定的功能。例如,要从二维数组(如您的代码片段中)获取第一个索引,您可以使用函数index_set_sof2

The length function is really only meant for getting the number of elements. When you want the retrieve indexes of an array, you should instead use the index_set function. This returns the actual index set, which you can iterate over: i in index_set(A)

For multidimensional arrays there are specific functions for each index set of the array. For example, to get the first index set from a two-dimensional array (as in your code fragment) you can use the function index_set_1of2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文