Commit 5b292738 authored by Eddie Schoute's avatar Eddie Schoute
Browse files

Rename SBR to reversal.py.

Fix tests
parent a48471b6
import math
from . import SBR
from . import reversal
def GDC_ATBS(perm):
......@@ -9,7 +9,7 @@ def GDC_ATBS(perm):
the cost of sorting the permutation.
"""
revs = sequential_permutation_sort_parallelized(perm, 0, len(perm) - 1)
return SBR.compress_reversals(revs, len(perm)) / 3
return reversal.compress_reversals(revs, len(perm)) / 3
def beginning_index_of_weight(w, v, i):
......@@ -105,7 +105,7 @@ def fill_4_parallel(w, v, A, i, j, b):
elif j == i + 1 and b == (i + 1) % 2:
leftind = beginning_index_of_weight(w, v, i)
rightind = end_index_of_weight(w, v, j)
r = SBR.Reversal(leftind, rightind)
r = reversal.Reversal(leftind, rightind)
A[i][j][b] = [w[i] + w[j] + 1, [r]]
elif j > i + 1 and b == i % 2:
A[i][j][b] = A[i + 1][j][b]
......@@ -130,7 +130,7 @@ def fill_6_parallel(w, v, A, i, j, b):
minval = val
leftind = beginning_index_of_weight(w, v, t + 1) - (v[t - ((t - i) % 2)] - v[i] + w[i])
rightind = end_index_of_weight(w, v, k - 1) + (v[j] - v[k + ((j - k) % 2)] + w[k + ((j - k) % 2)])
r = SBR.Reversal(leftind, rightind)
r = reversal.Reversal(leftind, rightind)
minrevs = A[i][t][b][1] + A[t + 1][k - 1][1 - b][1] + A[k][j][b][1] + [r]
A[i][j][b] = [minval, minrevs]
......@@ -145,8 +145,8 @@ def sequential_permutation_sort_parallelized(perm, i, j):
return []
b = perm_to_01(perm, i, j)
revs = binary_sort_parallel(b[i:j + 1])
offsetrevs = [SBR.Reversal(i + r.beg, i + r.end) for r in revs]
offsetrevs = [reversal.Reversal(i + r.beg, i + r.end) for r in revs]
m = (i + j) // 2
SBR.apply_revs(offsetrevs, perm)
reversal.apply_revs(offsetrevs, perm)
return offsetrevs + sequential_permutation_sort_parallelized(perm, i, m) + \
sequential_permutation_sort_parallelized(perm, m + 1, j)
\ No newline at end of file
from . import SBR, tripartite_binary_sort
from . import reversal, tripartite_binary_sort
def GDC_TBS(perm):
"""
......@@ -6,7 +6,7 @@ def GDC_TBS(perm):
(GenericDivideConquer_TripartiteBinarySort)
"""
revlist = routing_divideconquer_tbs(perm, 0, len(perm) - 1)
cost = SBR.compress_reversals(revlist, len(perm)) / 3
cost = reversal.compress_reversals(revlist, len(perm)) / 3
return cost
def perm_to_01(L, i, j):
......@@ -35,5 +35,5 @@ def routing_divideconquer_tbs(L, i=None, j=None):
T = perm_to_01(L, i, j)
revs = tripartite_binary_sort.tripartite_binary_sort(T, i, j)
m = (i + j) // 2
SBR.apply_revs(revs, L)
reversal.apply_revs(revs, L)
return revs + routing_divideconquer_tbs(L, i, m) + routing_divideconquer_tbs(L, m + 1, j)
......@@ -4,7 +4,7 @@ along with a couple testing/analysis functions
"""
import math
from . import SBR
from . import reversal
def tripartite_binary_sort(T, i, j):
"""
......@@ -21,8 +21,8 @@ def tripartite_binary_sort(T, i, j):
revlist += tripartite_binary_sort(T, part2 + 1, j)
oneind, zerind = zero_one_indices(T, i, j)
if oneind < zerind:
rev = SBR.Reversal(oneind, zerind)
SBR.reverse(T, rev)
rev = reversal.Reversal(oneind, zerind)
reversal.reverse(T, rev)
revlist.append(rev)
return revlist
......
......@@ -2,7 +2,7 @@ import random
from reversal_sort import routing
from unittest import TestCase
class TestRourting(TestCase):
class TestRouting(TestCase):
def test_perm_sort(self):
"""
......
import random
from reversal_sort import TripartiteBinarySort
from reversal_sort import tripartite_binary_sort
from unittest import TestCase
class TestTBS(TestCase):
......@@ -12,7 +12,5 @@ class TestTBS(TestCase):
l = [0]*random.randint(100,200) + [1]*random.randint(100,200)
random.shuffle(l)
before = l.copy()
#print(before)
TripartiteBinarySort.tripartite_binary_sort(l, 0 , len(l)-1)
#print(l, '\n')
tripartite_binary_sort.tripartite_binary_sort(l, 0 , len(l)-1)
self.assertEqual(sorted(before), l)
\ No newline at end of file
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