Commit eca82628 authored by Eddie Schoute's avatar Eddie Schoute
Browse files

Add command line options to select sorting

parent a7830143
......@@ -125,12 +125,25 @@ def main(NUM_PERMS_PER_LENGTH, LENGTH_FROM, LENGTH_TO):
# Now you can run `echo "0 1 3 2" | python main.py`
if __name__ == "__main__":
import argparse
import sys
for line in sys.stdin:
parser = argparse.ArgumentParser(description="Route a given permutation by using reversals and attempt to minimize time.")
parser.add_argument("permfile", help="File containing a list of permutations, one per line (default: stdin).",
type=argparse.FileType('r'), nargs='?', default=sys.stdin)
parser.add_argument("--sorting", help="Select binary sorting routine in generic divide and conquer (default: TBS)",
default="tbs", choices=["tbs", "atbs"])
args = parser.parse_args()
if args.sorting == "atbs":
sorting = adaptive_tb_sort
else:
sorting = tripartite_binary_sort
for line in args.permfile:
perm = [int(el) for el in line.split()]
# Check if is permutation
if set(range(len(perm))) != set(perm):
raise ValueError(f"Given permutation does not contain all elements in [0,{len(perm)-1}].")
router = routing.DCRoute(adaptive_tb_sort)
router = routing.DCRoute(sorting)
reversals = router.route(perm)
print(reversals) # TODO: Implement pretty print
\ No newline at end of file
......@@ -188,12 +188,3 @@ class ReversalCompresser:
return self.counter
def apply_revs(revs, perm):
"""
Applies reversals in list revs in order to permutation perm, in place
"""
for rev in revs:
reverse(perm, rev)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment