A set of files for solving the problem listed here: http://stackoverflow.com/questions/22222994/optimal-merging-of-triplets
./merge_triplets.py < triplets
will merge triplets listed in the filetriplets
with lookahead 3 and output the size of the resulting set../merge_triplets.py -v < triplets
will output information on every step of the algorithm, visualizing recursion../merge_triplets.py 0 < triplets
will use zero lookahead, a.k.a. the blind algorithm as discussed on StackOverflow../merge_triplets.py 1 < triplets
will use the simple heuristic, a.k.a Level 1: Greedy../merge_triplets.py 2 < triplets
also for any argument larger than 1, this will use the recursive lookahead algorithm a.k.a. Level 2: Very greedy
./random_triplets.py n
will generaten
triplets on stdout, with maximum element value about base-3 logarithm ofn
./random_triplets.py | ./merge_triplets.py
is a convinient way of combining the two scripts
./find_diff.sh n l1 l2
will repeatedly generate sets ofn
triplets, and compare the results of merges with lookaheadsl1
andl2
to find differences. When a difference is found, the script prints details of the event as well as the triplets that caused it and exits. Default values forn
,l1
andl2
are10
,2
and3
respectively.
./stat_diff.sh n l1 l2
will do the same thing as./find_diff.sh n l1 l2
except that instead of exiting, it will keep track of differences and continue running with new datasets. Sending an interrupt (Ctrl-C) will cause the script to print the statistics so far and exit. The script will leave behindlast_better[12]_triplets
files (so long the corresponding datasets have been found) so that they can be analyzed after the script has finished.
- These files are examples of triplets which cause different results for different lookaheads, as found by the
find_diff.sh
script.