Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naor #8

Merged
merged 63 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
74cec41
add my function and test file
elorisraeli May 21, 2024
b633fcb
resolve all comments
elorisraeli May 22, 2024
af985c2
fix CR
elorisraeli May 25, 2024
f95e567
implement functions + reformed utility func
elorisraeli Jun 4, 2024
39de631
fix PR errors
elorisraeli Jun 9, 2024
448a361
fix PR error log
elorisraeli Jun 9, 2024
9705ab1
tests
erelsgl Jun 10, 2024
2206075
fix algorithm and clean test file + edit allocations.py
elorisraeli Jun 13, 2024
619632f
update algorithm
elorisraeli Jun 13, 2024
fa89c6a
fix test bug
elorisraeli Jun 13, 2024
816dabd
Clean up comments and imports
elorisraeli Jun 13, 2024
9d64664
examples
erelsgl Jun 13, 2024
059f838
fix CR - pareto and ilp
elorisraeli Jun 14, 2024
7160be8
fix CR - remove i,j
elorisraeli Jun 15, 2024
0846105
fix CR - Naor
elorisraeli Jun 20, 2024
37f2e3d
clean unused - Naor
elorisraeli Jun 20, 2024
bd89fce
clean unused - Naor
elorisraeli Jun 20, 2024
4461a39
return to first - Naor
elorisraeli Jun 20, 2024
b9a3bb3
before Naor changes
elorisraeli Jun 20, 2024
06d6c31
Merge remote-tracking branch 'origin/main'
elorisraeli Jun 20, 2024
673677e
with Naor changes
elorisraeli Jun 20, 2024
7099d48
Merge branch 'ariel-research:main' into main
elorisraeli Jun 21, 2024
7619bce
bug
erelsgl Jun 23, 2024
b814f95
naor improve and add funcs
Naorl98 Jun 24, 2024
1f18412
naor improve and add funcs
Naorl98 Jun 24, 2024
4c3cb02
instance
erelsgl Jun 25, 2024
1fa97b4
Merge branch 'main' of github.com:elorisraeli/fairpyx
erelsgl Jun 25, 2024
e4b3015
log
erelsgl Jun 25, 2024
65169e4
delta logg
Naorl98 Jun 25, 2024
944ac24
Merge remote-tracking branch 'origin/main'
Naorl98 Jun 25, 2024
715a64c
print iteration
Naorl98 Jun 25, 2024
9ac453d
delta
erelsgl Jun 25, 2024
0460d46
Merge branch 'main' of github.com:elorisraeli/fairpyx
erelsgl Jun 25, 2024
b46d99e
value matrix
erelsgl Jun 25, 2024
2d7fc9a
plot and compare - naor
Naorl98 Jun 26, 2024
753d8e5
Elor improve
elorisraeli Jun 26, 2024
1139c3b
add eefpy and compare
Naorl98 Jun 27, 2024
fe6a2b0
Elor improve
elorisraeli Jun 27, 2024
95b17ed
add explain how to run
elorisraeli Jun 27, 2024
48f36b3
eef
dvir-pashut Jul 4, 2024
7b0a4d4
compare with all
dvir-pashut Jul 4, 2024
0a7d318
compare with all
dvir-pashut Jul 4, 2024
4b70666
DELETE agent capacities
dvir-pashut Jul 4, 2024
c72639f
DELETE agent capacities in second improved
dvir-pashut Jul 5, 2024
32a8b32
DELETE agent capacities in second improved
dvir-pashut Jul 5, 2024
dcca258
update configurations for cython improve
elorisraeli Jul 5, 2024
975b7e6
small change to push
elorisraeli Jul 5, 2024
5e23fe8
push new changes
elorisraeli Jul 5, 2024
4075113
Merge branch 'main' into main
elorisraeli Jul 5, 2024
2db184b
log
erelsgl Jul 9, 2024
777dcd1
Merge branch 'main' of github.com:elorisraeli/fairpyx
erelsgl Jul 9, 2024
ef8d57b
DELETE agent capacities in second improved
Naorl98 Jul 13, 2024
e869bd7
DELETE agent capacities in second improved
Naorl98 Jul 13, 2024
a499e99
Merge remote-tracking branch 'origin/main'
Naorl98 Jul 13, 2024
8b0db7e
Merge remote-tracking branch 'origin/main'
elorisraeli Jul 13, 2024
94f3b42
remove cython
elorisraeli Jul 16, 2024
c87f6ed
fix MR conflicts
elorisraeli Jul 22, 2024
2837eb9
fix results
elorisraeli Jul 22, 2024
49a4edf
fix results improved
elorisraeli Jul 22, 2024
5c9d6a0
update plots
elorisraeli Jul 22, 2024
78b902e
allow multiple copies
erelsgl Jul 22, 2024
cd3e365
fix last PR notes
elorisraeli Jul 26, 2024
4fa503c
reverse commit for PR
elorisraeli Jul 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 224 additions & 0 deletions experiments/compare_high_multiplicity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
"""
Compare the performance of a high_multiplicity_fair_allocation

Programmer: Naor Ladani & Elor Israeli
Since: 2024-06
"""
import experiments_csv
from pandas import read_csv
import matplotlib.pyplot as plt
from fairpyx import divide, AgentBundleValueMatrix, Instance
import fairpyx.algorithms.high_multiplicity_fair_allocation as high
import fairpyx.algorithms.improved_high_multiplicity as imp
from typing import *
import numpy as np
from eefpy import Objective, EnvyNotion
from eefpy import solve as solve

max_value = 1000
normalized_sum_of_values = 100
TIME_LIMIT = 60

algorithms_plot = [
"high_multiplicity_fair_allocation",
"solve",
"improved_high_multiplicity_fair_allocation",
]
# Define the specific algorithm you want to check
algorithms = [
high.high_multiplicity_fair_allocation,
solve,
imp.improved_high_multiplicity_fair_allocation,
]


######### EXPERIMENT WITH UNIFORMLY-RANDOM DATA ##########


def evaluate_algorithm_on_instance(algorithm, instance):

if algorithm is solve:
agent_valuations = [[int(instance.agent_item_value(agent, item)) for item in instance.items] for agent in
instance.agents]
print(f' agent valuations: {agent_valuations}')
items = [instance.item_capacity(item) for item in instance.items]

alloc = solve(num_agents=instance.num_of_agents
, num_types=instance.num_of_items
, agent_utils=agent_valuations,
items=items,
envy=EnvyNotion.EF, obj=Objective.NONE)
allocation = {}
for i, agent in enumerate(instance.agents):
allocation[agent] = []
for j, item in enumerate(instance.items):
if alloc == []:
allocation[agent] = []
else:
for sum in range(alloc[i][j]):
allocation[agent].append(item)

else:
allocation = divide(algorithm, instance)
matrix = AgentBundleValueMatrix(instance, allocation)
matrix.use_normalized_values()
return {
"utilitarian_value": matrix.utilitarian_value(),
"egalitarian_value": matrix.egalitarian_value(),

}


def course_allocation_with_random_instance_uniform(
num_of_agents: int, num_of_items: int,
value_noise_ratio: float,
algorithm: Callable,
random_seed: int):
agent_capacity_bounds = [1000, 1000]
item_capacity_bounds = [2, 10]
np.random.seed(random_seed)
instance = Instance.random_uniform(
num_of_agents=num_of_agents, num_of_items=num_of_items,
normalized_sum_of_values=normalized_sum_of_values,
agent_capacity_bounds=agent_capacity_bounds,
item_capacity_bounds=item_capacity_bounds,
item_base_value_bounds=[1, max_value],
item_subjective_ratio_bounds=[1 - value_noise_ratio, 1 + value_noise_ratio]
)
return evaluate_algorithm_on_instance(algorithm, instance)


def run_uniform_experiment():
# Run on uniformly-random data:
experiment = experiments_csv.Experiment("results/", "high_multi.csv", backup_folder="results/backup/")
input_ranges = {
"num_of_agents": [2, 3, 4, 5],
"num_of_items": [2, 3, 5, 6],
"value_noise_ratio": [0, 0.2, 0.5, 0.8, 1],
"algorithm": algorithms,
"random_seed": range(2),
}
experiment.run_with_time_limit(course_allocation_with_random_instance_uniform, input_ranges, time_limit=TIME_LIMIT)


######### EXPERIMENT WITH DATA SAMPLED FROM naor input DATA ##########


import json

filename = "data/naor_input.json"
with open(filename, "r", encoding="utf-8") as file:
naor_input = json.load(file)


def course_allocation_with_random_instance_sample(
max_total_agent_capacity: int,
algorithm: Callable,
random_seed: int, ):
np.random.seed(random_seed)

(agent_capacities, item_capacities, valuations) = \
(naor_input["agent_capacities"], naor_input["item_capacities"], naor_input["valuations"])
instance = Instance.random_sample(
max_num_of_agents=max_total_agent_capacity,
max_total_agent_capacity=max_total_agent_capacity,
prototype_agent_conflicts=[],
prototype_agent_capacities=agent_capacities,
prototype_valuations=valuations,
item_capacities=item_capacities,
item_conflicts=[])

return evaluate_algorithm_on_instance(algorithm, instance)


def run_naor_experiment():
# Run on Ariel sample data:z
experiment = experiments_csv.Experiment("results/", "course_allocation_naor.csv", backup_folder="results/backup/")
input_ranges = {
"max_total_agent_capacity": [12], # in reality: 1115
"algorithm": algorithms,
"random_seed": range(2),
}
experiment.run_with_time_limit(course_allocation_with_random_instance_sample, input_ranges, time_limit=TIME_LIMIT)


def create_plot_naor_experiment():
csv_file = 'results/course_allocation_naor.csv'
data = read_csv(csv_file)

print(data.head())
algorithms_for_plot = data['algorithm'].unique()

fig, axes = plt.subplots(1, 3, figsize=(21, 6))

for algorithm_p in algorithms_for_plot:
df_algo = data[data['algorithm'] == algorithm_p]
axes[0].plot(df_algo['utilitarian_value'], marker='o', linestyle='-', label=algorithm_p)
axes[1].plot(df_algo['egalitarian_value'], marker='o', linestyle='-', label=algorithm_p)
axes[2].plot(df_algo['runtime'], marker='o', linestyle='-', label=algorithm_p)

axes[0].set_title('Utilitarian Value Comparison')
axes[0].set_xlabel('')
axes[0].set_ylabel('Utilitarian Value')
axes[0].legend()

axes[1].set_title('Egalitarian Value Comparison')
axes[1].set_xlabel('')
axes[1].set_ylabel('Egalitarian Value')
axes[1].legend()

axes[2].set_title('runtime Comparison')
axes[2].set_xlabel('')
axes[2].set_ylabel('runtime')
axes[2].legend()

plt.tight_layout()
plt.savefig('results/naor_and_elor_plot.png')


def create_plot_uniform():
csv_file = 'results/high_multi.csv'
data = read_csv(csv_file)

print(data.head())
algorithms_for_plot = data['algorithm'].unique()

fig, axes = plt.subplots(1, 3, figsize=(21, 6))

for algorithm_p in algorithms_for_plot:
df_algo = data[data['algorithm'] == algorithm_p]
axes[0].plot(df_algo['utilitarian_value'], marker='o', linestyle='-', label=algorithm_p)
axes[1].plot(df_algo['egalitarian_value'], marker='o', linestyle='-', label=algorithm_p)
axes[2].plot(df_algo['runtime'], marker='o', linestyle='-', label=algorithm_p)

axes[0].set_title('Utilitarian Value Comparison')
axes[0].set_xlabel('')
axes[0].set_ylabel('Utilitarian Value')
axes[0].legend()

axes[1].set_title('Egalitarian Value Comparison')
axes[1].set_xlabel('')
axes[1].set_ylabel('Egalitarian Value')
axes[1].legend()

axes[2].set_title('runtime Comparison')
axes[2].set_xlabel('')
axes[2].set_ylabel('runtime')
axes[2].legend()

plt.tight_layout()

plt.savefig('results/high_multiplicity_uniforn_plot.png')


######### MAIN PROGRAM ##########


if __name__ == "__main__":
import logging

experiments_csv.logger.setLevel(logging.DEBUG)
# run_naor_experiment()
# create_plot_naor_experiment()
# run_uniform_experiment()
create_plot_uniform()
10 changes: 10 additions & 0 deletions experiments/data/naor_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"agent_capacities": {"s1": 23, "s2": 23, "s3": 23, "s4": 23},
"item_capacities": {"c1": 5, "c2": 6, "c3": 2, "c4": 3, "c5": 5, "c6": 2},
"valuations": {
"s1": {"c1": 152, "c2": 86, "c3": 262, "c4": 68, "c5": 263, "c6": 169},
"s2": {"c1": 124, "c2": 70, "c3": 98, "c4": 244, "c5": 329, "c6": 135},
"s3": {"c1": 170, "c2": 235, "c3": 295, "c4": 91, "c5": 91, "c6": 118},
"s4": {"c1": 158, "c2": 56, "c3": 134, "c4": 255, "c5": 192, "c6": 205}
}
}
20 changes: 20 additions & 0 deletions experiments/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
numpy>=1.21.3,<2.0.0
scipy>=1.6.1
networkz~=1.0.6
cvxpy_base>=1.1.17
prtpy
# cmake
# matplotlib
# repackage
# pytest
# cvxpy_leximin>=0.4.4
# prtpy>=0.7.0
# more_itertools
# scs
experiments_csv
cvxpy~=1.5.1
setuptools~=67.4.0
matplotlib~=3.9.0
pandas~=2.2.2
pytest~=8.2.2
eefpy~=0.1.5
7 changes: 7 additions & 0 deletions experiments/results/course_allocation_naor.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
max_total_agent_capacity,algorithm,random_seed,utilitarian_value,egalitarian_value,runtime
12,high_multiplicity_fair_allocation,0,103.02000000000001,92.30000000000001,29.27266180400011
12,high_multiplicity_fair_allocation,1,0.0,0,968.108752568
12,solve,0,104.24000000000001,94.0,1.5066105169998991
12,solve,1,0.0,0,178.2857671109996
12,improved_high_multiplicity_fair_allocation,0,103.02000000000001,92.30000000000001,27.41918799999985
12,improved_high_multiplicity_fair_allocation,1,0.0,0,922.6537668400006
Loading
Loading