diff options
author | Nao Pross <np@0hm.ch> | 2023-11-18 11:40:09 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2023-11-18 11:40:09 +0100 |
commit | 39a659320560f138820c0ecbcbeaf5762f32decd (patch) | |
tree | 120be837b3c0c999266c2cad7c18f49cf822392a | |
parent | Fix semicategory loading (diff) | |
download | act4e-alphubel-prod.tar.gz act4e-alphubel-prod.zip |
Pass TestCurrencyOptimizationalphubel-prod
-rw-r--r-- | Homeworks.md | 4 | ||||
-rw-r--r-- | src/act4e_solutions/currency_ex.py | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/Homeworks.md b/Homeworks.md index e208388..57320d4 100644 --- a/Homeworks.md +++ b/Homeworks.md @@ -52,6 +52,6 @@ $ make docker-check ## Exercises for Nov. 20 -- [ ] TestSemiCategoryRepresentation -- [ ] TestCurrencyOptimization +- [X] TestSemiCategoryRepresentation +- [X] TestCurrencyOptimization - [ ] TestFinitePosetMinMax diff --git a/src/act4e_solutions/currency_ex.py b/src/act4e_solutions/currency_ex.py index c0b6b1b..fbb9775 100644 --- a/src/act4e_solutions/currency_ex.py +++ b/src/act4e_solutions/currency_ex.py @@ -9,4 +9,22 @@ class SolCurrencyOptimization(I.CurrencyOptimization): amount: float, target: str, ) -> I.OptimalSolution: - pass + source, target = available.get_object(source), available.get_object(target) + + results = {} + for l in range(available.objects().size() + 1): + paths = available.hom(source, target, l) + for p in paths.elements(): + # Allow to go through exchanges only once + names = p.label.split(";") + if any([names.count(n) > 1 for n in names]): + continue + + rate, commission = p.mordata.rate, p.mordata.commission + res = amount * rate - commission + results[res] = p + + final = max(results.keys()) + path = results[final].label.split(";") + return I.OptimalSolution(path, final) + |