Specman: Error in on-the-fly generating of list of lists with all different values

╄→尐↘猪︶ㄣ 提交于 2019-12-11 13:46:55

问题


I try to generate on-the-fly list of list of uint (my_list_of_list) with all different values (I have a variable num_of_ms_in_each_g : list of uint, that keeps lengths of every list inside my_list_of_list):

  var my_list_of_list : list of list of uint;
  gen my_list_of_list keeping {
     for each (g) using index (g_idx) in it {
        g.size() == num_of_ms_in_each_g[g_idx];
        for each (m) using index (m_idx) in g {
           // Error in the next line:
           m not in it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1]; 
           m not in it[g_idx][0..max(0, m_idx-1)];
        };
  };

Explanation for the code algorithm: generate m (the value) that was not yet in any list of uint (g) before, and does not appear in current list for previous indexes.

I get compilation error:

  *** Error: 'm' is of type 'uint', while expecting type 'list of uint' or
'list of list of uint'.

Do you have any idea how to solve the compilation error? (it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1] is uint..) Or maybe another way to generate on-the-fly list of list of uint with all different values? Thank you for your help.


回答1:


I would reduce the complexity of this constraint by using a sort of a unified list that contains all the items, and then Break this list into the desired list of list ( as It is easier to generate a single unique list). Also, in general, it is best to keep all non-generative operations outside of the constraints since it could be done procedurally Afterwards which will improve the overall performance of generating such a field set.

I would do this using the following code:

   var unified_list:list of uint;
    var my_list_of_list : list of list of uint;
    gen unified_list keeping { 
        it.size()==num_of_ms_in_each_g.sum(it);
        it.all_different(it);
    };
    for each in num_of_ms_in_each_g {
        var temp_list:list of uint;
        for i from 0 to it-1 {
            temp_list.add(unified_list.pop0());
        };
        my_list_of_list.add(temp_list);
        };

thanks




回答2:


Actually, the expression it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1] is of type list of list of uint. The operator list[from..to] produces a sub list. In your code you apply it twice to it which first produces a sublist and then produces a sublist of the sublist.

The second such constraint in your code works, because it[g_idx] does not produce a sublist, but rather accesses a list item, which is of type list of uint and then produces a sublist.

To produce an all different list of list I would do something like:

var my_list_of_list : list of list of uint;
for each (sz) in num_of_ms_in_each_g {
    var l : list of uint;
    gen l keeping {
        it.size() == sz;
        it.all_different(it);
        //  not it.has(it in my_list_of_list.flatten());
        // for better performance
        for each (itm) in it {
            itm not in my_list_of_list.flatten();
        };
    };
    my_list_of_list.add(l);
};


来源:https://stackoverflow.com/questions/34741160/specman-error-in-on-the-fly-generating-of-list-of-lists-with-all-different-valu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!