小型尺寸的长度
如果我这样定义了我的数组:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
长度函数实际上仅是为了获取元素数量。当您想要阵列的检索索引时,应该使用
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