GECODE 矩阵中的成对不同列
GECODE Pairwise Distinct Columns In A Matrix
本文关键字:GECODE 更新时间:2023-10-16
我正在研究一个GECODE求解器来实现矩阵生成问题。我已经弄清楚了我需要的所有约束,除了一个:
Given a Matrix[M, N], all column vectors must be pairwise distinct.
这是我想写的代码:
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if( i != j )
{
notsame(*this, m.col(i), m.col(j));
}
}
}
但是我不知道如何使用提供的原始约束来表达这一点。我知道distinct()
存在,但是我不知道如何对矩阵中的列进行操作,而不是对列矩阵本身中的元素进行操作。表达这种对矩阵的约束的最佳方式是什么?
我想出了一个似乎有效的实现。
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if( i != j )
{
// Every column should not be equal to any other column
// Check each column pairwise element
BoolVarArgs equalities;
for(int r = 0; r < M; r++)
{
equalities << expr(*this, m(i, r) == m(j, r));
}
rel(*this, BOT_AND, equalities, 0);
}
}
}