-
Notifications
You must be signed in to change notification settings - Fork 8
/
simulations.py
72 lines (62 loc) · 2.11 KB
/
simulations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 13 22:43:45 2016
@author: nicolas
"""
from problem import Problem
import mipsolving
import protocols
from fairness_measures import fairnessDashboard
import numpy as np
def simulationOpt(sample_size,int_agents,int_resources,culture):
'''
@sample_size: number of xps for each parameter configuration
@int_agents: list of values to be considered
@int_resources: list of values to be considered
'''
envies = np.zeros((len(int_agents),len(int_resources)))
ef_ratios = np.zeros((len(int_agents),len(int_resources)))
for idx_agent,n in enumerate(int_agents):
for idx_res,m in enumerate(int_resources):
total_envy = 0
nb_ef = 0
for xp in range(sample_size):
p = Problem(n,m,culture,centralized=True)
# collecting statistics
envy = mipsolving.envyminimizingLP(p)
total_envy += envy
if envy==0:
nb_ef += 1
mean_envy = total_envy/sample_size
ef_ratio = nb_ef / sample_size
envies[idx_agent][idx_res] = mean_envy
ef_ratios[idx_agent][idx_res]=ef_ratio
return envies,ef_ratios
def simulationPickingSequences(sample_size,n,m,sequence,culture,verbose=False):
'''
for a given sequence, runs several simulations
@sample_size: number of xps for each parameter configuration
@n: nb of agents
@m: nb of resources
'''
d = fairnessDashboard()
for xp in range(sample_size):
p = Problem(n,m,culture,centralized=True)
protocols.pickingSequence(p,sequence,verbose)
if verbose:
print(p)
print (p.printAllocation())
d.update(p)
print(d)
return
def simulationLipton(sample_size,n,m,culture,verbose=False):
d = fairnessDashboard()
for xp in range(sample_size):
p = Problem(n,m,culture,centralized=True)
protocols.lipton(p,verbose)
if verbose:
print(p)
print (p.printAllocation()) # print the final allocation
d.update(p)
print(d)
return