Skip to content

Commit

Permalink
Use actual path length instead of idealized
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Gåsemyr Magnus committed Apr 25, 2019
1 parent 2e0e503 commit a85cc19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion etw/etw.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ def etw(ns, nt, cost=None, max_shift=None):
def weighted_table(idx):
i, k = idx
i, k = i % ns, k % nt
w = max(max(i + 1, k + 1) / min(i + 1, k + 1), 1.0)

# Idealized:
# w = max(max(i + 1, k + 1) / min(i + 1, k + 1), 1.0)

# Actual:
w = max(max(i + 1, k + 1) / L[i][k], 1.0)

return T[i][k] * w

min_b = min(((i, -1) for i in range(max_shift, ns)), key=weighted_table)
Expand Down
20 changes: 17 additions & 3 deletions etw/tests/test_etw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
from .. import cli
from .. import etw


def test_main():
_ = cli.main([])
# TODO:
# def test_ns_ne_nt():
# s = [3, 2, 1, 2, 3, 4, 5, 6, 7]
# t = [1, 2, 3, 4, 4.2, 4, 4, 5, 5, 5]
# cost = lambda i, k: 1.0 + abs(s[i] - t[k])


def test_ns_eq_nt():
s = [3, 2, 1, 2, 3, 4, 5, 6, 6, 7]
t = [1, 2, 3, 4, 4.2, 4, 4, 5, 5, 5]

ref_path = ([2, 3, 4, 5, 5, 5, 5, 6, 6, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
path, _, _, _ = etw(len(s), len(t),
cost=lambda i, k: 1.0 + abs(s[i] - t[k]))

assert path == ref_path

0 comments on commit a85cc19

Please sign in to comment.