簡體   English   中英

矩陣中的GECODE成對區分列

[英]GECODE Pairwise Distinct Columns In A Matrix

我正在研究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);
        }
      }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM