Skip to content

Commit

Permalink
remove dicttools dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
erelsgl committed Oct 18, 2023
1 parent 365a900 commit fd9a1cc
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fairpyx/algorithms/almost_egalitarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def almost_egalitarian_allocation(alloc: AllocationBuilder, surplus_donation:boo
>>> from fairpyx.adaptors import divide
>>> from dicttools import stringify
>>> from fairpyx.utils.test_utils import stringify
>>> instance = Instance(valuations={"avi": {"x":5, "y":4, "z":3, "w":2}, "beni": {"x":2, "y":3, "z":4, "w":5}}, agent_capacities=1, item_capacities=1)
>>> stringify(divide(almost_egalitarian_allocation, instance=instance))
Expand Down
2 changes: 1 addition & 1 deletion fairpyx/algorithms/iterated_maximum_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def iterated_maximum_matching(alloc:AllocationBuilder, adjust_utilities:bool=Fal
:param alloc: an allocation builder, which tracks the allocation and the remaining capacity for items and agents. of the fair course allocation problem.
:param adjust_utilities: if True, the utilities of agents, who did not get their max-value item in the current iteration, will be adjusted to give them a higher chance in the next iteration.
>>> from dicttools import stringify
>>> from fairpyx.utils.test_utils import stringify
>>> from fairpyx.adaptors import divide
>>> instance = Instance(valuations={"avi": {"x":5, "y":4, "z":3, "w":2}, "beni": {"x":2, "y":3, "z":4, "w":5}}, agent_capacities=1, item_capacities=1)
Expand Down
2 changes: 1 addition & 1 deletion fairpyx/algorithms/utilitarian_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def utilitarian_matching(alloc: AllocationBuilder):
"""
Finds an allocation maximizing the sum of utilities for the given instance, using max-weight many-to-many matching.
>>> from dicttools import stringify
>>> from fairpyx.utils.test_utils import stringify
>>> from fairpyx.adaptors import divide
>>> instance = Instance(valuations={"avi": {"x":5, "y":4, "z":3, "w":2}, "beni": {"x":2, "y":3, "z":4, "w":5}}, agent_capacities=1, item_capacities=1)
Expand Down
2 changes: 1 addition & 1 deletion fairpyx/utils/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def many_to_many_matching(item_capacities: dict[any,int], agent_capacities:dict[
"""
Computes a many-to-many matching of items to agents.
>>> from dicttools import stringify
>>> from fairpyx.utils.test_utils import stringify
>>> valuations = {"a":{"x":11, "y":22}, "b":{"x":33,"y":55}}
>>> stringify(many_to_many_matching(item_capacities={"x":2, "y":2}, agent_capacities={"a":1, "b":1}, valuations=valuations))
Expand Down
24 changes: 24 additions & 0 deletions fairpyx/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Copied from dicttools library: https://github.com/trzemecki/dicttools/blob/39c19d9a5ecc965a58eed3eab18ac3e5e342fca2/dicttools/functions.py#L379C18-L379C18
"""

def stringify(d):
"""
Returns a canonical string representation of the given dict,
by sorting its items recursively.
This is especially useful in doctests::
>>> stringify({"a":1,"b":2,"c":{"d":3,"e":4}})
'{a:1, b:2, c:{d:3, e:4}}'
"""
d2 = {}

for k, v in d.items():
d2[k] = stringify(v) if isinstance(v, dict) else v

return "{" + ", ".join(["{}:{}".format(k, v) for k, v in sorted(d2.items())]) + "}"


if __name__ == "__main__":
import doctest, sys
print("\n",doctest.testmod(), "\n")
2 changes: 1 addition & 1 deletion fairpyx/zalternatives/yekta_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def yekta_day(alloc: AllocationBuilder):
"""
:param alloc: an allocation builder, which tracks the allocation and the remaining capacity for items and agents. of the fair course allocation problem.
>>> from dicttools import stringify
>>> from fairpyx.utils.test_utils import stringify
>>> from fairpy.courses.adaptors import divide
>>> instance = Instance(valuations={"avi": {"x":5, "y":4, "z":3, "w":2}, "beni": {"x":2, "y":3, "z":4, "w":5}}, agent_capacities=1, item_capacities=1)
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ cvxpy_base>=1.1.17
# prtpy>=0.7.0
# more_itertools
# scs
dicttools @ git+https://github.com/trzemecki/dicttools.git

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
# Publish to test PyPI:
# twine upload --repository testpypi dist/*

# Publish to real PyPI:
# Publish to real PyPI (make sure you set the environment variables TWINE_USERNAME and TWINE_PASSWORD):
# twine upload --repository pypi dist/*

0 comments on commit fd9a1cc

Please sign in to comment.