矩阵中方子矩阵的约束

问题描述 投票:0回答:1

我有一个 9x9 矩阵,如下 M[9][9] 下面的每个 A、B、C 等都是 3x3 的子方阵,因此总共是 9x9 矩阵。

                  A B C

           M  =   D E F

                  G H I

我需要为以下条件编写约束: 条件 1:上面任何给定的 3x3 子方阵 A、B 等都应具有唯一的最大值 例如

          1 1 1               5 6 6  

     A =  3 2 1          B =  6 9 6 

          3 6 8               6 6 6

Amax = 8,Bmax = 9。

条件2:Amax != Bmax

条件3:Amax != Dmax

对于一个子方阵有一个最大元素,如下。代码有效,但我不知道如何使其适用于所有子方阵,

         class max;  
         bit[4:0] sub_mat[3][3];
         rand bit[4:0] max;

           constraint c3 {
               sub_mat.sum(item1) with (item1.sum(item2) with (int'(item2==max))) ==1;
                   
                         foreach (mat[i,j]){
                            sub_mat[i][j] <= max;
                               }
                           }    
         endclass

请提供如何对更大矩阵 M 中的所有 A、B、C 等子矩阵进行操作的输入

matrix constraints system-verilog uvm
1个回答
0
投票

我不明白条件 2 和 3 的用途,因为它们已经包含在条件 1 中。

但是如果我正确理解你的问题,你想保证每个子矩阵都有一个唯一的最大值。 我想下一堂课会成功:

class MyClass;
  bit[4:0] matrix[9][9]; 
  rand bit[4:0] sub_mat[9][3][3];

    // Ensure unique maximum values in sub-matrices
    constraint unique_max_value {
      foreach (sub_mat[i]) {
        bit[4:0] max_val = sub_mat[i].max();
        foreach (sub_mat[j]) {
          if (i != j) {
            max_val != sub_mat[j].max();
          }
        }
      }
    }

     function void post_randomize();
          // Assign sub-matrices into the 9x9 matrix
          for (int i = 0; i < 9; i++) begin
                for (int j = 0; j < 9; j++) begin
                      matrix[i][j] = sub_mat[(i/3)*3+(j/3)][i%3][j%3];
                end
          end
     endfunction
endclass

注意:我没有检查它的编译或工作情况,而且自从我编写 UVM 以来已经有一段时间了,所以对它持保留态度。

© www.soinside.com 2019 - 2024. All rights reserved.