Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
erelsgl committed Apr 14, 2024
1 parent ae6e3bc commit bd4c731
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
24 changes: 12 additions & 12 deletions examples/courses.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ print(divide(fairpyx.algorithms.almost_egalitarian_with_donation, instance=rando
```

```
{'s1': ['c1', 'c3'], 's2': ['c1', 'c2'], 's3': ['c1', 'c2'], 's4':
['c1', 'c3'], 's5': ['c1', 'c2'], 's6': ['c2'], 's7': ['c2'], 's8':
['c3'], 's9': ['c3'], 's10': ['c3']}
{'s1': ['c3'], 's2': ['c2'], 's3': ['c2'], 's4': ['c3'], 's5': ['c2'],
's6': ['c1', 'c2'], 's7': ['c1', 'c2'], 's8': ['c1', 'c3'], 's9':
['c1', 'c3'], 's10': ['c1', 'c3']}
{'s1': ['c1', 'c2', 'c3'], 's2': ['c1', 'c2', 'c3'], 's3': ['c1',
'c2', 'c3'], 's4': ['c2', 'c3'], 's5': ['c2', 'c3'], 's6': ['c1'],
's7': ['c1'], 's8': [], 's9': [], 's10': []}
{'s1': ['c3'], 's2': ['c1', 'c2'], 's3': ['c1'], 's4': ['c3'], 's5':
['c3'], 's6': ['c1', 'c2'], 's7': ['c2', 'c3'], 's8': ['c2'], 's9':
['c1', 'c3'], 's10': ['c1', 'c2']}
{'s1': ['c2', 'c3'], 's2': ['c2', 'c3'], 's3': ['c1', 'c3'], 's4':
['c1', 'c3'], 's5': ['c1', 'c2'], 's6': ['c1', 'c3'], 's7': ['c1',
'c2'], 's8': ['c1', 'c2'], 's9': ['c1', 'c3'], 's10': ['c3']}
{'s1': ['c2'], 's2': ['c1', 'c2'], 's3': ['c1', 'c3'], 's4': ['c1',
'c3'], 's5': ['c1', 'c2'], 's6': ['c1', 'c3'], 's7': ['c2', 'c3'],
's8': ['c2', 'c3'], 's9': ['c1', 'c3'], 's10': ['c1', 'c3']}
{'s1': ['c2', 'c3'], 's2': ['c2', 'c3'], 's3': ['c2', 'c3'], 's4':
['c1', 'c2', 'c3'], 's5': ['c1', 'c2', 'c3'], 's6': ['c1', 'c3'],
's7': ['c1', 'c3'], 's8': ['c1'], 's9': ['c1'], 's10': ['c1']}
{'s1': ['c2'], 's2': ['c3'], 's3': ['c1', 'c3'], 's4': ['c1', 'c3'],
's5': ['c1', 'c2'], 's6': ['c1', 'c2', 'c3'], 's7': ['c1', 'c2'],
's8': ['c1', 'c3'], 's9': ['c1', 'c3'], 's10': ['c2', 'c3']}
```


Expand Down
30 changes: 13 additions & 17 deletions examples/input_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ print(allocation)
```

```
[[33 29 31 68 28 55 87 85 51 9 62 29]
[47 57 24 82 9 53 49 4 35 94 25 39]
[ 9 98 13 23 21 52 1 14 33 50 60 70]
[29 52 68 85 20 98 85 75 93 38 36 19]
[72 23 23 34 36 71 29 13 38 2 69 91]]
{0: [6, 7], 1: [3, 9], 2: [1, 10], 3: [2, 8], 4: [0, 4, 5, 11]}
[[11 51 26 40 92 22 25 9 26 44 52 98]
[58 55 4 57 48 3 24 24 51 84 97 2]
[ 6 5 31 66 74 95 11 21 81 28 98 28]
[ 9 50 8 9 37 24 42 22 90 15 36 11]
[43 73 76 60 30 20 4 11 1 54 68 86]]
{0: [4], 1: [0, 7, 9], 2: [5, 10], 3: [6, 8], 4: [1, 2, 3, 11]}
```


Expand All @@ -89,8 +89,7 @@ print(allocation)
```

```
No leafs - removing edge (2, 11) with minimum weight 0.17
{0: [6, 7], 1: [3, 9], 2: [1, 10], 3: [5, 8], 4: [0, 11]}
{0: [4, 11], 1: [0, 9], 2: [5, 10], 3: [6, 8], 4: [1, 2]}
```


Expand All @@ -104,8 +103,7 @@ print(allocation)
```

```
No leafs - removing edge (0, 6) with minimum weight 0.15
{0: [7], 1: [3, 9], 2: [1, 5, 10], 3: [6, 8], 4: [11]}
{0: [3], 1: [0, 9], 2: [4, 5, 10], 3: [1, 8], 4: [11]}
```


Expand All @@ -119,8 +117,7 @@ print(allocation)
```

```
No leafs - removing edge (2, 11) with minimum weight 0.17
{0: [6, 7], 1: [3, 9], 2: [1, 10], 3: [5, 8], 4: [0, 11]}
{0: [4, 11], 1: [0, 9], 2: [5, 10], 3: [6, 8], 4: [1, 2]}
```


Expand All @@ -134,9 +131,8 @@ print(allocation)
```

```
No leafs - removing edge (0, 10) with minimum weight 0.05
{0: [3, 6, 7, 8], 1: [0, 1, 3, 9], 2: [1, 9, 10, 11], 3: [5, 6, 7, 8],
4: [0, 5, 10, 11]}
{0: [1, 4, 9, 11], 1: [0, 3, 9, 10], 2: [4, 5, 8, 10], 3: [1, 5, 6,
8], 4: [0, 2, 3, 11]}
```


Expand All @@ -150,8 +146,8 @@ print(allocation)
```

```
{0: [3, 6, 7], 1: [1, 3, 9], 2: [1, 9, 10, 11], 3: [2, 5, 7, 8], 4:
[0, 4, 5, 11]}
{0: [1, 4, 11], 1: [0, 3, 7, 9], 2: [3, 5, 10], 3: [5, 6, 7, 8], 4:
[1, 2, 9, 11]}
```


Expand Down
4 changes: 2 additions & 2 deletions fairpyx/algorithms/almost_egalitarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def remove_agent_from_graph(agent):
edge_with_min_weight = min(fractional_allocation_graph.edges(), key=lambda edge:fractional_allocation_graph.weight(edge[0],edge[1]))
agent_min_weight,item_min_weight = edge_with_min_weight
min_weight = fractional_allocation_graph.weight(agent_min_weight,item_min_weight)
logger.warning("No leafs - removing edge %s with minimum weight %g", edge_with_min_weight, min_weight)
explanation_logger.info("There are no leaf nodes, but the edge %s has minimum weight %g, so it is removed.", edge_with_min_weight, min_weight, agents=agent_min_weight)
# logger.warning("No leafs - removing edge %s with minimum weight %g", edge_with_min_weight, min_weight)
explanation_logger.warning("There are no leaf nodes, but the edge %s has minimum weight %g, so it is removed.", edge_with_min_weight, min_weight, agents=agent_min_weight)
remove_edge_from_graph(agent_min_weight,item_min_weight)

iterated_maximum_matching(alloc) # Avoid waste
Expand Down
19 changes: 19 additions & 0 deletions fairpyx/explanations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class ExplanationLogger:
def __init__(self, language='en'):
self.language=language

def warning(self, message:str, *args, agents=None):
pass

def info(self, message:str, *args, agents=None):
pass

Expand Down Expand Up @@ -117,6 +120,12 @@ def info(self, message:str, *args, agents=None):
else: # to one agent
self.logger.info(str(agents)+": "+message.strip(), *args)

def warning(self, message:str, *args, agents=None):
if agents is None or not is_individual_agent(agents): # to all agents
self.logger.warning(message, *args)
else: # to one agent
self.logger.warning(str(agents)+": "+message.strip(), *args)


class ConsoleExplanationLogger(SingleExplanationLogger):
"""
Expand Down Expand Up @@ -160,6 +169,16 @@ def info(self, message:str, *args, agents=None):
for agent in agents:
self.map_agent_to_logger[agent].info(message, *args)

def warning(self, message:str, *args, agents=None):
if agents is None:
for agent,logger in self.map_agent_to_logger.items():
logger.warning(message, *args)
elif is_individual_agent(agents):
self.map_agent_to_logger[agents].warning(message, *args)
else:
for agent in agents:
self.map_agent_to_logger[agent].warning(message, *args)



class FilesExplanationLogger(ExplanationLoggerPerAgent):
Expand Down

0 comments on commit bd4c731

Please sign in to comment.