二维数组的约束随机化



我正在寻找问题的解决方案,即 我有一个二维约束。一个是

typedef struct {
rand int subcarriers[12];
} symbol_alloc_per_prb_t;
class stim_gen_c;
//Declaration of variables
rand int prb;   
rand symbol_alloc_per_prb_t symb_alloc_prbs[];
rand int channel;
constraint c_ch {channel inside {[0:127]};}
constraint c_prb {prb inside {[0:272]};} 

constraint c_symb_alloc {
symb_alloc_prbs.size() == prb + 1;
foreach (symb_alloc_prbs[i]) {
foreach (symb_alloc_prbs[i].subcarriers[j])
symb_alloc_prbs[i].subcarriers[j] inside {[0:channel]};
}
}
endclass
module rand_methods;
initial begin
stim_gen_c stim_gen;
stim_gen = new();

if(!stim_gen.randomize() with {
stim_gen.prb == 5;
stim_gen.channel == 5;
})
//repeat(10) begin
$display ("Symbol Allocation Table (subcarrier : channel ID)");
for (int i=0; i < stim_gen.symb_alloc_prbs.size(); i++) begin
$display("PRB %0d ", i,);
$write(" | ");
for (int j=0; j < 12; j++) begin
$write("%2d: %3d", j, stim_gen.symb_alloc_prbs[i].subcarriers[j]);
$write(" | ");
end
$write("n");
end
//end
end
endmodule

上面的代码生成如下输出:

Symbol Allocation Table (subcarrier : channel ID)
PRB 0  
|  0:   5 |  1:   4 |  2:   5 |  3:   1 |  4:   2 |  5:   5 |  6:   1 |  7:   1 |  8:   5 |  9:   2 | 10:   3 | 11:   3 | 
PRB 1  
|  0:   3 |  1:   5 |  2:   1 |  3:   5 |  4:   1 |  5:   3 |  6:   3 |  7:   0 |  8:   0 |  9:   4 | 10:   2 | 11:   3 | 
PRB 2  
|  0:   3 |  1:   4 |  2:   1 |  3:   3 |  4:   3 |  5:   1 |  6:   4 |  7:   4 |  8:   3 |  9:   3 | 10:   1 | 11:   1 | 
PRB 3  
|  0:   1 |  1:   4 |  2:   0 |  3:   5 |  4:   4 |  5:   5 |  6:   5 |  7:   3 |  8:   4 |  9:   2 | 10:   5 | 11:   5 | 
PRB 4  
|  0:   5 |  1:   5 |  2:   2 |  3:   4 |  4:   3 |  5:   5 |  6:   1 |  7:   2 |  8:   2 |  9:   2 | 10:   1 | 11:   0 | 
PRB 5  
|  0:   1 |  1:   1 |  2:   5 |  3:   0 |  4:   1 |  5:   1 |  6:   4 |  7:   3 |  8:   2 |  9:   5 | 10:   5 | 11:   4 |

目前,随机化正在工作,使得每个子载波获得不同的信道值。

现在,我希望随机化的工作方式是,一个子载波阵列只能有一个通道分配,如下所示。但在下面的示例中,通道号/ID 是一个连续的数字。PRB 0 可以有通道 ID 5,PRB 1 可以有通道 ID 2 或其他东西,这怎么可能是随机的。

Symbol Allocation Table (subcarrier : channel ID)
PRB 0  
|  0:   1 |  1:   1 |  2:   1 |  3:   1 |  4:   1 |  5:   1 |  6:   1 |  7:   1 |  8:   1 |  9:   1 | 10:   1 | 11:   1 | 
PRB 1  
|  0:   2 |  1:   2 |  2:   2 |  3:   2 |  4:   2 |  5:   2 |  6:   2 |  7:   2 |  8:   2 |  9:   2 | 10:   2 | 11:   2 | 
PRB 2  
|  0:   3 |  1:   3 |  2:   3 |  3:   3 |  4:   3 |  5:   3 |  6:   3 |  7:   3 |  8:   3 |  9:   3 | 10:   3 | 11:   3 | 
PRB 3  
|  0:   4 |  1:   4 |  2:   4 |  3:   4 |  4:   4 |  5:   4 |  6:   4 |  7:   4 |  8:   4 |  9:   4 | 10:   4 | 11:   4 | 
PRB 4  
|  0:   5 |  1:   5 |  2:   5 |  3:   5 |  4:   5 |  5:   5 |  6:   5 |  7:   5 |  8:   5 |  9:   5 | 10:   5 | 11:   5 | 
PRB 5  
|  0:   6 |  1:   6 |  2:   6 |  3:   6 |  4:   6 |  5:   6 |  6:   6 |  7:   6 |  8:   6 |  9:   6 | 10:   6 | 11:   6 |

谢谢

执行此操作的最佳方法是添加通道 ID 的帮助程序数组,您可以使用唯一值填充这些数组。

class stim_gen_c;
//Declaration of variables
rand int prb;
rand symbol_alloc_per_prb_t symb_alloc_prbs[];
rand int channel, channelIDs[];
constraint c_ch {channel inside {[0:127]};}
constraint c_prb {prb inside {[0:272]};} 

constraint c_symb_alloc {
symb_alloc_prbs.size() == prb + 1;
channelIDs.size() == prb + 1;
unique {channelIDs}; // not clear if this constraint is required
foreach (symb_alloc_prbs[i]) {
foreach (symb_alloc_prbs[i].subcarriers[j]) {
symb_alloc_prbs[i].subcarriers[j] inside {[0:channel]};
symb_alloc_prbs[i].subcarriers[j] == channelIDs[i];
}
}
}
endclass

最新更新