0
votes

I am looking for some solution of a problem i.e. I have a two dimensional constraint. One is

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

The above code produces the output like:

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 |

At the moment, the randomization is working such that each subcarrier gets a different value of channel.

Now I want the randomization work in such a way that one subcarrier array can have only one channel allocation as shown below. But in the below example the channel number/ID is a running number. How can this be randomize that PRB 0 can have channel ID 5 and PRB 1 can have channel ID 2 or something.

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 |

Thanks

1
It would really help to show the declarations of all variables. Even better is a complete minimal example. We have no idea how a channel fits into any code you have shown.dave_59
I have updated the question by adding the variables. Basically channel is just a number between 0:127 and I want that the subcarrier[] array should only get one channel.Bilal Bashir
You still have not shown all the declarations. What is symb_alloc_prbs? And what are you printing?dave_59
Please show all rand declarations.Karan Shah
The code has been updated and can be reproduced @dave_59Bilal Bashir

1 Answers

0
votes

The best way to do this is adding a helper array of channelIDs that you can fill with unique values.

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