diff options
author | Nao Pross <np@0hm.ch> | 2023-11-05 11:36:00 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2023-11-05 11:36:00 +0100 |
commit | d4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86 (patch) | |
tree | 395ab4e139f28dd67b549fa318d09173fe901300 /src/act4e_solutions | |
parent | Fix (new) bug in MyFiniteSetProduct to pass TestFiniteMapRepresentation (diff) | |
download | act4e-d4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86.tar.gz act4e-d4f2e37c5b0a6541c2b253ac46b6f2c56c0eef86.zip |
Pass TestFiniteMonotoneMapProperties
Diffstat (limited to 'src/act4e_solutions')
-rw-r--r-- | src/act4e_solutions/posets_bounds.py | 10 | ||||
-rw-r--r-- | src/act4e_solutions/posets_map.py | 13 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/act4e_solutions/posets_bounds.py b/src/act4e_solutions/posets_bounds.py index c1c6310..05f818f 100644 --- a/src/act4e_solutions/posets_bounds.py +++ b/src/act4e_solutions/posets_bounds.py @@ -2,6 +2,8 @@ from typing import Any, List, Optional, overload, TypeVar from itertools import product from functools import cmp_to_key +from .posets_representation import MyFinitePoset + import act4e_interfaces as I E = TypeVar("E") @@ -17,7 +19,13 @@ class SolFinitePosetMeasurement(I.FinitePosetMeasurement): class SolFinitePosetConstructionOpposite(I.FinitePosetConstructionOpposite): def opposite(self, p: I.FinitePoset[X]) -> I.FinitePoset[X]: - raise NotImplementedError() # implement here + e = p.carrier().elements() + values = [] + for a, b in product(e, e): + if p.holds(a, b): + # then the opposite holds(b, a) + values.append((b, a)) + return MyFinitePoset(p.carrier(), values) class SolFinitePosetSubsetProperties(I.FinitePosetSubsetProperties): diff --git a/src/act4e_solutions/posets_map.py b/src/act4e_solutions/posets_map.py index a91d4d8..8d28c62 100644 --- a/src/act4e_solutions/posets_map.py +++ b/src/act4e_solutions/posets_map.py @@ -1,5 +1,8 @@ from typing import TypeVar +from itertools import product +from .posets_bounds import SolFinitePosetConstructionOpposite + import act4e_interfaces as I A = TypeVar("A") @@ -9,7 +12,13 @@ X = TypeVar("X") class SolFiniteMonotoneMapProperties(I.FiniteMonotoneMapProperties): def is_monotone(self, p1: I.FinitePoset[A], p2: I.FinitePoset[B], m: I.FiniteMap[A, B]) -> bool: - raise NotImplementedError() + A = p1.carrier().elements() + for x, y in product(A, A): + if p1.holds(x, y): + if not p2.holds(m(x), m(y)): + return False + return True def is_antitone(self, p1: I.FinitePoset[A], p2: I.FinitePoset[B], m: I.FiniteMap[A, B]) -> bool: - raise NotImplementedError() + opp = SolFinitePosetConstructionOpposite() + return self.is_monotone(opp.opposite(p1), p2, m) |