summaryrefslogtreecommitdiffstats
path: root/src/act4e_solutions
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2023-10-17 19:54:42 +0200
committerNao Pross <np@0hm.ch>2023-10-17 19:54:42 +0200
commit8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53 (patch)
tree3ca4791823bdb7fd0a6bd8cfdf24ab21acc1283b /src/act4e_solutions
parentFix bug to pass TestFiniteMapRepresentation (diff)
downloadact4e-8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53.tar.gz
act4e-8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53.zip
Pass TestFiniteRelationOperations
Diffstat (limited to 'src/act4e_solutions')
-rw-r--r--src/act4e_solutions/relations.py14
1 files changed, 12 insertions, 2 deletions
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):