MiniZinc MILP 约束,用于限制数组中最多 3 个连续的特定项
我有下一个 MiniZinc 代码
array [0..5] of var 0..1: a;
constraint sum(a) = 3;
output [show(a)]
我需要添加两个约束以确保最多有 3 个连续的 1。我认为添加 constraint sum(a) = 3;
有帮助,但是如何添加约束来确保我有 3 个连续的 1,例如 111000 或 011100?
I have the next MiniZinc code
array [0..5] of var 0..1: a;
constraint sum(a) = 3;
output [show(a)]
And I need to add two constraints to ensure that at most I have 3 contiguous 1's. I thought that adding constraint sum(a) = 3;
helps but how can I add a constraint to make sure I have 3-contiguous 1s for example 111000 or 011100?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种选择是限制第一个和最后一个
1
之间的距离:Another alternative is to constrain the distance between first and last
1
:这是一种将 4 个连续元素的每个块的总和限制为 3 的方法:
Here is one way by constraining the sum of each block of 4 consecutive elements to 3: