From 8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 17 Oct 2023 19:54:42 +0200 Subject: Pass TestFiniteRelationOperations --- src/act4e_solutions/relations.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/act4e_solutions/relations.py b/src/act4e_solutions/relations.py index c538d4d..4fba1f1 100644 --- a/src/act4e_solutions/relations.py +++ b/src/act4e_solutions/relations.py @@ -60,10 +60,20 @@ class SolFiniteRelationProperties(I.FiniteRelationProperties): class SolFiniteRelationOperations(I.FiniteRelationOperations): def transpose(self, fr: I.FiniteRelation[A, B]) -> I.FiniteRelation[B, A]: - raise NotImplementedError() + # reverses the arrows in the relation + values = [] + for a in fr.source().elements(): + for b in fr.target().elements(): + if fr.holds(a, b): + values.append([b, a]) + return MyFiniteRelation(fr.target(), fr.source(), values) def as_relation(self, f: I.FiniteMap[A, B]) -> I.FiniteRelation[A, B]: - raise NotImplementedError() + values = [] + for a in f.source().elements(): + values.append([a, f(a)]) + + return MyFiniteRelation(f.source(), f.target(), values) class SolFiniteEndorelationProperties(I.FiniteEndorelationProperties): -- cgit v1.2.1