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") X = TypeVar("X") class SolFinitePosetMeasurement(I.FinitePosetMeasurement): def height(self, fp: I.FinitePoset[Any]) -> int: raise NotImplementedError() def width(self, fp: I.FinitePoset[Any]) -> int: raise NotImplementedError() class SolFinitePosetConstructionOpposite(I.FinitePosetConstructionOpposite): def opposite(self, p: I.FinitePoset[X]) -> I.FinitePoset[X]: 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): def is_chain(self, fp: I.FinitePoset[X], s: List[X]) -> bool: try: def cmp(a, b): return fp._cmp(a, b) s_sorted = sorted(s, key=cmp_to_key(cmp)) except RuntimeError as e: return False return True def is_antichain(self, fp: I.FinitePoset[X], s: List[X]) -> bool: # Comparison with itself should be ignored, since there is always a # relation to itself by antisymmetry not_the_same = lambda pair: not fp.carrier().equal(pair[0], pair[1]) # Check that no elements are comparable for a, b in filter(not_the_same, product(s, s)): assert fp.carrier().contains(a) and fp.carrier().contains(b) if fp.holds(a, b): return False return True class SolFinitePosetSubsetProperties2(I.FinitePosetSubsetProperties2): def is_lower_set(self, fp: I.FinitePoset[X], s: List[X]) -> bool: raise NotImplementedError() def is_upper_set(self, fp: I.FinitePoset[X], s: List[X]) -> bool: raise NotImplementedError() class SolFinitePosetClosures(I.FinitePosetClosures): def upper_closure(self, fp: I.FinitePoset[X], s: List[X]) -> List[X]: raise NotImplementedError() def lower_closure(self, fp: I.FinitePoset[X], s: List[X]) -> List[X]: raise NotImplementedError() class SolFinitePosetInfSup(I.FinitePosetInfSup): def lower_bounds(self, fp: I.FinitePoset[E], s: List[E]) -> List[E]: raise NotImplementedError() def upper_bounds(self, fp: I.FinitePoset[E], s: List[E]) -> List[E]: raise NotImplementedError() def infimum(self, fp: I.FinitePoset[E], s: List[E]) -> Optional[E]: raise NotImplementedError() def supremum(self, fp: I.FinitePoset[E], s: List[E]) -> Optional[E]: raise NotImplementedError() class SolFinitePosetMinMax(I.FinitePosetMinMax): def minimal(self, fp: I.FinitePoset[E], S: List[E]) -> List[E]: raise NotImplementedError() def maximal(self, fp: I.FinitePoset[E], S: List[E]) -> List[E]: raise NotImplementedError()