diff --git a/fairpyx/algorithms/iterated_maximum_matching.py b/fairpyx/algorithms/iterated_maximum_matching.py index 739e8e9..7783a99 100644 --- a/fairpyx/algorithms/iterated_maximum_matching.py +++ b/fairpyx/algorithms/iterated_maximum_matching.py @@ -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" diff --git a/fairpyx/algorithms/picking_sequence.py b/fairpyx/algorithms/picking_sequence.py index b930d32..81bc788 100644 --- a/fairpyx/algorithms/picking_sequence.py +++ b/fairpyx/algorithms/picking_sequence.py @@ -31,8 +31,10 @@ 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: @@ -40,6 +42,7 @@ def picking_sequence(alloc: AllocationBuilder, agent_order:list): 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) @@ -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