diff options
author | Nao Pross <np@0hm.ch> | 2023-10-17 19:54:42 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2023-10-17 19:54:42 +0200 |
commit | 8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53 (patch) | |
tree | 3ca4791823bdb7fd0a6bd8cfdf24ab21acc1283b /src | |
parent | Fix bug to pass TestFiniteMapRepresentation (diff) | |
download | act4e-8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53.tar.gz act4e-8f22cfbcd8c61e3e7ec78628b52a579c4f1dff53.zip |
Pass TestFiniteRelationOperations
Diffstat (limited to 'src')
-rw-r--r-- | src/act4e_solutions/relations.py | 14 |
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): |