The thing that really slowed my code down was detecting multiple, equal-length LCS within the same pairing. Eg. In this dataset:
>string1
AAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTT
>string2
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
my program detects and reports both the As at the beginning and the Ts at the end:
P:\test>484593-4 duptest.dat
000:001 L[017] (0 0)'AAAAAAAAAAAAAAAAA' (47 47)'TTTTTTTTTTTTTTTTT'
1 trial of duptest.dat ( 1.210ms total), 1.210ms/trial
Where your program will only report the first of the two equal LCSs:
P:\test>gf -MIN=16 duptest.gf
Completed in 0.000209
Best match: >string1 - >string2. 17 characters starting at 0 and 0.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAA
Also, if the equal LCSs appear in different relative positions within the pairing, which is reported depends upon which appears first within the first string of the pairing:
P:\test>type duptest.gf
>string1
TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA
>string2
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
P:\test>gf -MIN=16 duptest.gf
Completed in 0.00021
Best match: >string1 - >string2. 17 characters starting at 0 and 47.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA
TTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
...............................................TTTTTTTTTTTTTTTTT
P:\test>type duptest.gf
>string1
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
>string2
TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA
P:\test>gf -MIN=16 duptest.gf
Completed in 0.000209
Best match: >string1 - >string2. 17 characters starting at 0 and 47.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAA
TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA
...............................................AAAAAAAAAAAAAAAAA
I cannot see how you could adapt your code to handle that without loosing it's performance?
This may be just a bug-report rather than a fundemental problem, but I modified the above dataset by deleting one of the As from the start of each line and adding two T's (keeping the length to 64) at the end, making the Ts the LCS for the pair.
Ignoring the reporting anomolies, your code still detects the As as the LCS unless I drop the minimum length right down to 2?
P:\test>gf -MIN=16 duptest.gf
Completed in 0.000207
Best match: >string1 - >string2. 17 characters starting at 0 and 0.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAC
AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAG
P:\test>gf -MIN=8 duptest.gf
Completed in 0.000296
Best match: >string1 - >string2. 17 characters starting at 0 and 0.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAC
AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAG
P:\test>gf -MIN=4 duptest.gf
Completed in 0.000611
Best match: >string1 - >string2. 17 characters starting at 0 and 0.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAC
AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAG
P:\test>gf -MIN=2 duptest.gf
Completed in 0.000909
Best match: >string1 - >string2. 19 characters starting at 44 and 44.
123456789 123456789 123456789 123456789 123456789 123456789 123456789
AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT
............................................CCTTTTTTTTTTTTTTTTT
AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT
............................................GGTTTTTTTTTTTTTTTTT
Indeed, as it stands, your code always favours a shorter match in the first string over a longer match in the second unless the minimum match is set to a value less than or equal to the difference between the matches.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
|