Structure
I have a structure like this:
- level 1 items represented by a capital letter (A, B, C, D,...)
- level 2 items represented by lower case letter (a, b, c, d,...)
- level 3 items repredented by numbers (1, 2, 3, 4,...)
these items are grouped into "combination" consisting of:
(level 1 item, level 2 item, level 3 item) always in this order.
e.g. (A, c, 5)
Let's say level 1 items are only 4: A, B, C, D
level 2 items are the first 10 letters : a, b, c, d, e, f, g, h, i, j
level 3 items are represented by natural numbers up to 30
Not all possible combinations are considered valid! The suitable combinations are grouped into a list:
(A, f, 3)
(A, f, 8)
(A, f, 10)
(A, j, 23)
(B, h, 1)
(D, d, 30)
(D, g, 18)
The combination list does not allow duplicates, so every combination is unique.
Process
- Randomly select 1 lvl 1 item from all the possibles
(A, B, C, D)
e.g. random selection gives:A - Retrieve all combinations that have
Aas lvl 1 item:
(A, a, 12)
(A, f, 3)
(A, f, 8)
(A, f, 10)
(A, j, 23)
- Now from lvl 2 items remained in these 5 combinations
(a, f, j), one item is randomly selected. Let's say selection givesf.
Remark: I need to avoid that numerosity of a single lvl 2 item influence the random selection. So in this case the random selection cannot be done simply picking one of the 5 combinations above because it is more likely to pickf(3 of 5) thanaorj(1 of 5 each).
Retrieve all combinations that havefas lvl 2 item:
(A, f, 3)
(A, f, 8)
(A, f, 10)
- From lvl 3 items remained in these 3 combinations
(3, 8, 10), one item is randomly selected. Let's say8. identify the unique combination:
(A, f, 8)
Moreover this process is repeated to pick a 2nd random combination. But in this case there is another limitation. The new combination cannot contain the same lvl 1 item. So it has the following form:
(everything but A, lvl 2 item, lvl 3 item) or
(not A, lvl 2 item, lvl 3 item)
All these operation are performed to pass the combination to another application as input.
Questions
- What do you think could be the most efficient way to implement such a process?
- Is it worth using a relational database? (I expect very complex query)
- Is it better to perform this type of operation using a programming language? e.g. pandas dataframe in Python)
PS: I'm not sure if this questions belongs in this section so please give me feedback on this.
A,_,_, combinations in one list, allB,_,_, in another, etc. Then you have to select a list at random, and an entry at random, followed by a random selection from one of the other lists. I don't see a role for a DBMS while computing (though you might have reasons to use one for more permanent storage). As for efficiency, I'm not sure that the lists are large enough to warrant anything more advanced than I have already suggested.