0

I have a list of lists, i would like to generate a new list which isn't in the old lists, how can i do this automatically?

DB : list of list of uint;
generate_new_data() is {
    for i from 1 to 10 {
        var new_list : list of uint;

        gen new_list keeping {
           it.size() == n;
           it not in DB;
        };

        DB.add( new_list );
    };
};

The new list can be a permutation of an old one, i care to have different values in the list items, it can be one or all different (i want this to be random)

Kamil.Khoury
  • 210
  • 2
  • 9
  • Hi, a similar question was asked here: http://stackoverflow.com/questions/34741160/specman-error-in-on-the-fly-generating-of-list-of-lists-with-all-different-valu/34763920#34763920 please take a look and see if this is what you meant. – yuvalg Feb 24 '16 at 07:13
  • It doesn't help, i want to generate a new list which i didn't generate before. example: list #1 - {1, 2, 3}, list #2 - {1, 2, 4} ... – Kamil.Khoury Feb 24 '16 at 08:20

1 Answers1

0

Consider the following, if two lists are not equal then there is at least one location where the values are different. Therefore,

l1 is different than l2  if and only if there exists a 'diff_at' such that l1[diff_at]!=l2[diff_at]

Using this approach the entire DB can be generated in a single CFS:

struct db_wrapper_s {
    DB : list of list of uint;
    diff_at : list of list of uint;

    keep DB.size() == diff_at.size();

    keep for each in diff_at {
        it.size() == index;
        for each in it {
            it < read_only(DB[index].size());
        };
    };

    keep for each (diff_i) using index (i) in diff_at {
        for each (diff_i_j) using index (j) in diff_i {
            DB[i][diff_i_j] != DB[j][diff_i_j];
        };
    };
};

generate_new_data() is {
    var genDB : db_wrapper_s;
    var db_sz : uint = 10;
    var l_sz : uint = 5;
    gen genDB keeping {
        it.DB.size() == read_only(db_sz);
        for each in it.DB {
            it.size() == read_only(l_sz);
        };
    };
    print genDB.DB;
};

The problem with the above is it will proabaly suffer from long solving time if the amount of lists in DB and the list size are large.

Since Specman 14.2 the random generator supports generative list index:

keep foo()[gen_var] == ... ;

(The feature is disabled in 14.2/15.1 and need to turned on by "config gen -use_generative_list_index=TRUE").

Using this feature you can build the DB list by list:

struct new_list_wrapper_s {
    new_list : list of uint;
    diff_at : list of uint;
};

!DB : list of list of uint;
generate_new_data() is {
    var n : uint = 5;
    for i from 1 to 10 {
        var new_list_wrapper : new_list_wrapper_s;
        gen new_list_wrapper keeping {
            it.diff_at.size() == read_only(DB.size());
            it.new_list.size() == read_only(n);
            for each (diff_loc) in it.diff_at {
                diff_loc < read_only(n);
                it.new_list[diff_loc] != read_only(DB[index])[diff_loc];
            };
        };
        DB.add( new_list_wrapper.new_list );
    };
    print DB;
};
Amit M.
  • 208
  • 1
  • 3