summaryrefslogtreecommitdiffstats
path: root/src/act4e_solutions
diff options
context:
space:
mode:
Diffstat (limited to 'src/act4e_solutions')
-rw-r--r--src/act4e_solutions/maps_representation.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/act4e_solutions/maps_representation.py b/src/act4e_solutions/maps_representation.py
index ad9cdf5..330b3fd 100644
--- a/src/act4e_solutions/maps_representation.py
+++ b/src/act4e_solutions/maps_representation.py
@@ -30,7 +30,7 @@ class MyFiniteMap(I.FiniteMap[A, B]):
# print("dst: ", self._target.elements())
# print("val: ", self._values)
# print("inp: ", a)
- # assert a in self._source.elements()
+ assert a in self._source.elements()
rv = None
for v in self._values:
@@ -38,11 +38,10 @@ class MyFiniteMap(I.FiniteMap[A, B]):
# print(f"{v[0]} equals {a}")
rv = v[1]
- # assert self._target.contains(rv)
+ assert self._target.contains(rv)
# print("ret: ", rv)
# print("the type of rv is", type(rv))
# print()
- # assert type(rv) != bool
return rv
@@ -51,30 +50,35 @@ class SolFiniteMapRepresentation(I.FiniteMapRepresentation):
def load(self, h: I.IOHelper, s: I.FiniteMap_desc) -> I.FiniteMap[A, B]:
fsr = SolFiniteSetRepresentation()
+ if not "values" in s.keys():
+ raise I.InvalidFormat()
+
+ if len(s["values"]) == 0:
+ raise I.InvalidFormat()
+
A = fsr.load(h, s["source"])
B = fsr.load(h, s["target"])
values = []
- # Check that the values are are in the domain and codomain
for v in s["values"]:
a, b = A.load(h, v[0]), B.load(h, v[1])
- values.append([a, b])
if not A.contains(a):
print(f"{v[0]} is not in A: {A.elements()}")
raise I.InvalidFormat()
- if not v[1] in B.elements():
+ if not B.contains(b):
print(f"{v[1]} is not in B: {B.elements()}")
raise I.InvalidFormat()
+ values.append([a, b])
+
# Check that the domain values are unique
- # FIXME: fix this part
- domvals = []
- for d in map(lambda v: v[0], values):
- if d in domvals:
+ domain = []
+ for a, _ in values:
+ if a in domain:
raise I.InvalidFormat()
- domvals.append(d)
+ domain.append(a)
return MyFiniteMap(A, B, values)
@@ -87,10 +91,10 @@ class SolFiniteMapRepresentation(I.FiniteMapRepresentation):
"values": []
}
- # for a in m.source().elements():
- # b = m(a)
- # d["values"].append([
- # m.source().save(h, a),
- # m.target().save(h, b)])
+ for a in m.source().elements():
+ b = m(a)
+ d["values"].append([
+ m.source().save(h, a),
+ m.target().save(h, b)])
return d