Skip to content

Commit

Permalink
logger
Browse files Browse the repository at this point in the history
  • Loading branch information
erelsgl committed Jun 9, 2024
1 parent ae91b11 commit 58b5b95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 9 additions & 1 deletion fairpyx/algorithms/iterated_maximum_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,22 @@ def iterated_maximum_matching_unadjusted(alloc:AllocationBuilder, **kwargs):
from fairpyx.adaptors import divide_random_instance, divide
from fairpyx.explanations import ConsoleExplanationLogger, FilesExplanationLogger, StringsExplanationLogger

console_explanation_logger = ConsoleExplanationLogger()
files_explanation_logger = FilesExplanationLogger({
i: f"logs/s{i+1}.log"
for i in range(2)
}, mode='w', language="he")
string_explanation_logger = StringsExplanationLogger(f"s{i+1}" for i in range(2))

instance = Instance(valuations=[[5,4,3,2],[2,3,4,5]], agent_capacities=2, item_capacities=1)
print(divide(iterated_maximum_matching, instance=instance, explanation_logger=ConsoleExplanationLogger()))
print(divide(iterated_maximum_matching, instance=instance, explanation_logger=files_explanation_logger))

sys.exit()

num_of_agents = 30
num_of_items = 10


console_explanation_logger = ConsoleExplanationLogger()
files_explanation_logger = FilesExplanationLogger({
f"s{i+1}": f"logs/s{i+1}.log"
Expand Down
20 changes: 15 additions & 5 deletions fairpyx/algorithms/picking_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ def picking_sequence(alloc: AllocationBuilder, agent_order:list):
logger.info("\nPicking-sequence with items %s , agents %s, and agent-order %s", alloc.remaining_item_capacities, alloc.remaining_agent_capacities, agent_order)
for agent in cycle(agent_order):
if alloc.isdone():
break
logger.info("No more items to allocate")
break
if not agent in alloc.remaining_agent_capacities:
logger.info("No more agents with capacities")
continue
potential_items_for_agent = set(alloc.remaining_items_for_agent(agent))
if len(potential_items_for_agent)==0:
logger.info("Agent %s cannot pick any more items: remaining=%s, bundle=%s", agent, alloc.remaining_item_capacities, alloc.bundles[agent])
alloc.remove_agent_from_loop(agent)
continue
best_item_for_agent = max(potential_items_for_agent, key=lambda item: alloc.effective_value(agent,item))
# logger.info("\nAgent %s picks item %s", agent, best_item_for_agent)
alloc.give(agent, best_item_for_agent, logger)


Expand Down Expand Up @@ -125,13 +128,20 @@ def bidirectional_round_robin(alloc: AllocationBuilder, agent_order:list=None):
### MAIN

if __name__ == "__main__":
import doctest, sys
print("\n",doctest.testmod(), "\n")
# import doctest
# print("\n",doctest.testmod(), "\n")

# sys.exit()

# logger.addHandler(logging.StreamHandler(sys.stdout))
# logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)

from fairpyx.adaptors import divide
agent_capacities = {"Alice": 2, "Bob": 3, "Chana": 2, "Dana": 3} # 10 seats required
course_capacities = {"c1": 2, "c2": 3, "c3": 4} # 9 seats available
valuations = {"Alice": {"c1": 10, "c2": 8, "c3": 6}, "Bob": {"c1": 10, "c2": 8, "c3": 6}, "Chana": {"c1": 6, "c2": 8, "c3": 10}, "Dana": {"c1": 6, "c2": 8, "c3": 10}}
instance = Instance(agent_capacities=agent_capacities, item_capacities=course_capacities, valuations=valuations)
divide(picking_sequence, instance=instance, agent_order=["Alice","Bob", "Chana", "Dana","Dana","Chana","Bob", "Alice"])

# from fairpyx.adaptors import divide_random_instance

Expand Down

0 comments on commit 58b5b95

Please sign in to comment.