finding sequences from small length sequences
I want to generate a space by using some events in a specific format. Let
me explain the problem on a small example.
Assume that I have the events a,b,c,d,e,f. I will have 3-length sequences
as an input consisting of these events. From these sequences I want to
generate 6-length (number of events) sequences and there will be no
repeated elements in the sequence, i.e. every event will be used exactly
once. 6-length sequences need to satisfy some rules.(explained on example)
Example:
Input:
list1:['a','b','c']
list2:['c','d','e']
list3:['b','c','d']
list4:['a','c','g']
list5:['f','g','e']
List1 describes that, b and c will come after a, and c will come after b
in the 6-length sequence, i.e, when the order changes sequence also
changes. In the same manner List2 describes that d and e will come after
c, and e will come after d. All of the lists will be taken and rules are
recorded. After all rules extracted from these sequences, I need to
generate 6-length sequence that obeys rules. As an example;
Lets say in our case(for simplicity) inputs are List1,List2 and List3
Input:
list1:['a','b','c']
list2:['c','d','e']
list3:['b','c','d']
Then some results for these lists are;
['a','b','c','d','e']: it obeys all of the rules from extracted these 3
lists, like b and c comes after a, d and e comes after c, c and d comes
after b. Ýmportant note from here, if c needs to come after a, they do not
need to be adjacent in the output sequence(6-length)
It is not guaranteed that 6-length sequence will always exist. Firstly, it
needs to be checked that there is at least one such sequence. If not,
algorithm should return false. As an example; lets assume our inputs are
Lis1, Lis2, Lis3, Lis4 and Lis5.
Input:
list1:['a','b','c']
list2:['c','d','e']
list3:['b','c','d']
list4:['a','c','g']
list5:['e','g','b']
a => b => c => g => b it is not possible since b can not come after itself.
I need an algorithm to generate these sequences in Python. I do not have
any code for now, because so far I could not think any efficient
algorithm. It needs to be very efficient in finding longer length
sequences, too.
If the question is not clear, please let me now.
Thanks
No comments:
Post a Comment