summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/act4e_solutions/posets_bounds.py10
-rw-r--r--src/act4e_solutions/posets_map.py13
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)