//cSelected[i]=1 ==> ∀ j∈{1,…,i-1} xCategory[i]!= xCategory[j]
cSelected[i]=0, otherwise
这就是我想要做的
int[] x = new int[]{0, 1, 0, 0, 1, 0};
int[] xCategory = new int[]{3, 1, 2, 2, 3, 0};
int[] xCategorySize = new int[]{0, 100, 200, 300};
IntVar[] cSelected = model.intVarArray("d", 6, 0, 1);
// 3. Post constraints
// i want to add and post this constraint:
//cSelected [i]=1 ==> ∀ j∈{1,…,i-1} xCategory[i]!= xCategory[j]
//cSelected [i]=0, otherwise
for (int i=0; i<x.length;i++)
sum += (1-x[i]) * cSelected[i].getValue() * xCategorySize[xCategory[i]];
答案 0 :(得分:0)
您需要为每个测试xCategory[i]!= xCategory[j]
验证约束,并将验证结果放入BoolVar
中包含的BoolVar[][] cMatrix
中。然后,在该矩阵中发布每个向量or
的{{1}}约束,并将其保存在BoolVar[]
(这也是cSelected
,而不是BoolVarArray
)中:
IntVarArray