-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathultimatum_v3.py
116 lines (101 loc) · 4.49 KB
/
ultimatum_v3.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
# from softmax import *
import matplotlib.pyplot as plt
from dynamic_trans_agent import DynamicTransAgent
import random
import copy
class ultimatum_v3(object):
def __init__(self,resource_val=1, proposer = DynamicTransAgent(), arbiter= DynamicTransAgent()):
self.resource_val = resource_val
self.proposer = proposer
self.arbiter = arbiter
propIdentity = {'arbiter':round(random.uniform(0,2),1)}
arbIdentity = {'proposer':round(random.uniform(0,2),1)}
random.seed = 32
self.proposer.identity = propIdentity
self.arbiter.identity = arbIdentity
# self.proposer.setIdentity(propIdentity)
# self.arbiter.setIdentity(arbIdentity)
def find_key(self, input_dict, value):
return {k for k, v in input_dict.items() if v == value}
def agent_decision(self):
split_factor = np.arange(0,1.01,0.01)
utility = {}
for i in split_factor:
my_split = i*self.resource_val
other_split = self.resource_val*(1-i)
utility[i] = self.proposer.basic_utility_computation(my_split, other_split, 'arbiter')
return utility
def proposer_decision(self):
split_factor = np.arange(0,1.05,0.05)
satis_score = {}
utility = {}
for i in split_factor:
my_split = i*self.resource_val
other_split = self.resource_val*(1-i)
utility[i] = self.proposer.utility_computation(my_split, other_split,'arbiter')
# satis_score[i] = self.proposer.satisfaction_score(my_split, other_split)
# print("stais_score ", satis_score)
# utility_vals = list(utility.values())
# maxUtility = max(utility_vals)
# print("utility ", utility)
# print("max ", maxUtility)
# split = list(self.find_key(utility, maxUtility))[0]
# print(self.proposer.get_attrs())
# decision, decisionUtil = self.proposer.decision(utility)
# return decision, decisionUtil
return utility
# return split
# return decision
def arbiter_decision(self, proposed_split):
my_split = proposed_split
other_split = self.resource_val - proposed_split
utility = self.arbiter.utility_computation(my_split, other_split, 'proposer')
minAccept, utilAccept = self.arbiter.minAccept('proposer')
rejectUtil = self.arbiter.utility_computation(0,0,'proposer')
if utility>=utilAccept:
decision = 1
finalUtil = utility
else:
# arbUtil = self.arbiter.utility_computation(0,0,'proposer')
# print("Losing Out ", recvUtil, arbUtil, recvUtil-arbUtil)
decision = 0
finalUtil = rejectUtil
return decision, finalUtil, utilAccept, minAccept
def agent_fair_score(self, split, agent_type = 'proposer'):
if agent_type=='proposer':
return self.proposer.fair_normalized(split)
else:
return self.arbiter.fair_normalized(split)
def find_accept(self, split_util):
utility = list(split_util.values())
# print(utility)
return max(utility)
# if max(utility) >= 0:
# return max(utility)
# else:
# y = 0
# x_key = utility.index(max(utility))
# for i in range(x_key,len(utility)):
# if utility[i+1] - utility[i] < 0.04:
# return utility[i]
def arbiter_mao(self):
split_util = {}
for split in np.arange(0,1.1,0.1):
split_util[split] = self.arbiter_decision(split)
splits = list(split_util.keys())
utility = list(split_util.values())
ylist = [j>0 for j in utility]
# decSplit, decUtil = self.arbiter.decision(split_util)
accept = self.find_accept(split_util)
accept_split = list(self.find_key(split_util, accept))[0]
return accept_split, accept
# return decSplit, decUtil
def game(self):
proposer_split, propUtil = self.proposer_decision()
# print(proposer_split)
arbiter_split = self.resource_val - proposer_split
recvUtil = copy.deepcopy(self.arbiter.utility_computation(arbiter_split, proposer_split, 'proposer'))
decision, finalUtil, utilAccept, minAccept = self.arbiter_decision(arbiter_split)
# print("min accept ", minimum_accept, " arbiter_split ", arbiter_split, " losing out", recvUtil-arbUtil)
return proposer_split, arbiter_split, decision