-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPooling.py
More file actions
133 lines (123 loc) · 6.29 KB
/
Pooling.py
File metadata and controls
133 lines (123 loc) · 6.29 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import numpy as np
def pooling(Mj, theta, transmit_util, receive_util):
PBE = []
if Mj == 1:
p = theta
Util_receiver_for_A1 = p * receive_util[1][Mj][1] + (1-p) * receive_util[2][Mj][1]
Util_receiver_for_A2 = p * receive_util[1][Mj][2] + (1-p) * receive_util[2][Mj][2]
Aj = 1 if Util_receiver_for_A1 > Util_receiver_for_A2 else 2
if transmit_util[1][1][Aj] >= transmit_util[1][2][1] and transmit_util[2][1][Aj] >= transmit_util[2][2][1]:
temp = (receive_util[1][2][1] + receive_util[2][2][2] - receive_util[2][2][1] - receive_util[1][2][2])
q = (receive_util[2][2][2] - receive_util[2][2][1]) / temp
F1_empty = 0
q_min = -1
q_max = -1
if temp > 0 and q > 1:
F1_empty = 1
elif temp > 0 and q <= 1:
q_min = max(q, 0)
q_max = 1
elif temp < 0 and q < 0:
F1_empty = 1
elif temp < 0 and q >= 0:
q_min = 0
q_max = min(q, 1)
elif temp == 0 and receive_util[2][2][1] >= receive_util[2][2][2]:
q_min = 0
q_max = 1
elif temp == 0 and receive_util[2][2][1] < receive_util[2][2][2]:
F1_empty = 1
if not F1_empty:
EU_R = theta * receive_util[1][1][Aj] + (1 - theta) * receive_util[2][1][Aj]
EU_S = theta * transmit_util[1][1][Aj] + (1 - theta) * transmit_util[2][1][Aj]
S1 = ('M{}, M{}'.format(Mj, Mj))
S2 = ('A{}, A{}'.format(Aj, 1))
PBE.append({'type':1, 'S1':S1, 'S2':S2, 'q_range':(q_min, q_max), 'p_range':(p, p), 'EU_S':EU_S, 'EU_R':EU_R})
if transmit_util[1][1][Aj] >= transmit_util[1][2][2] and transmit_util[2][1][Aj] >= transmit_util[2][2][2]:
temp = (receive_util[1][2][1] + receive_util[2][2][2] - receive_util[2][2][1] - receive_util[1][2][2])
q = (receive_util[2][2][2] - receive_util[2][2][1]) / temp
F2_empty = 0
q_min = -1
q_max = -1
if temp > 0 and q < 0:
F2_empty = 1
elif temp > 0 and q >= 0:
q_min = 0
q_max = min(q ,1)
elif temp < 0 and q > 1:
F2_empty = 1
elif temp < 0 and q <= 1:
q_min = max(q, 0)
q_max = 1
elif temp == 0 and receive_util[2][2][1] <= receive_util[2][2][2]:
q_min = 0
q_max = 1
elif temp == 0 and receive_util[2][2][1] > receive_util[2][2][2]:
F2_empty = 1
if not F2_empty:
EU_R = theta * receive_util[1][1][Aj] + (1 - theta) * receive_util[2][1][Aj]
EU_S = theta * transmit_util[1][1][Aj] + (1 - theta) * transmit_util[2][1][Aj]
S1 = ('M{}, M{}'.format(Mj, Mj))
S2 = ('A{}, A{}'.format(Aj, 2))
PBE.append({'type':1, 'S1':S1, 'S2':S2, 'q_range':(q_min, q_max), 'p_range':(p, p), 'EU_S':EU_S, 'EU_R':EU_R})
return PBE
elif Mj == 2:
q = theta
Util_receiver_for_A1 = q * receive_util[1][Mj][1] + (1-q) * receive_util[2][Mj][1]
Util_receiver_for_A2 = q * receive_util[1][Mj][2] + (1-q) * receive_util[2][Mj][2]
Aj = 1 if Util_receiver_for_A1 > Util_receiver_for_A2 else 2
if transmit_util[1][2][Aj] >= transmit_util[1][1][1] and transmit_util[2][2][Aj] >= transmit_util[2][1][1]:
temp = (receive_util[1][1][1] + receive_util[2][1][2] - receive_util[2][1][1] - receive_util[1][1][2])
p = (receive_util[2][1][2] - receive_util[2][1][1]) / temp
F1_empty = 0
p_min = -1
p_max = -1
if temp > 0 and p > 1:
F1_empty = 1
elif temp > 0 and p <= 1:
p_min = max(p, 0)
p_max = 1
elif temp < 0 and p < 0:
F1_empty = 1
elif temp < 0 and p >= 0:
p_min = 0
p_max = min(p, 1)
elif temp == 0 and receive_util[2][1][1] >= receive_util[2][1][2]:
p_min = 0
p_max = 1
elif temp == 0 and receive_util[2][1][1] < receive_util[2][1][2]:
F1_empty = 1
if not F1_empty:
EU_R = theta * receive_util[1][2][Aj] + (1 - theta) * receive_util[2][2][Aj]
EU_S = theta * transmit_util[1][2][Aj] + (1 - theta) * transmit_util[2][2][Aj]
S1 = ('M{}, M{}'.format(Mj, Mj))
S2 = ('A{}, A{}'.format(1, Aj))
PBE.append({'type':2, 'S1':S1, 'S2':S2, 'q_range':(q, q), 'p_range':(p_min, p_max), 'EU_S':EU_S, 'EU_R':EU_R})
if transmit_util[1][2][Aj] >= transmit_util[1][1][2] and transmit_util[2][2][Aj] >= transmit_util[2][1][2]:
temp = (receive_util[1][1][1] + receive_util[2][1][2] - receive_util[2][1][1] - receive_util[1][1][2])
p = (receive_util[2][1][2] - receive_util[2][1][1]) / temp
F2_empty = 0
p_min = -1
p_max = -1
if temp > 0 and p < 0:
F2_empty = 1
elif temp > 0 and p >= 0:
p_min = 0
p_max = min(p ,1)
elif temp < 0 and p > 1:
F2_empty = 1
elif temp < 0 and p <= 1:
p_min = max(p, 0)
p_max = 1
elif temp == 0 and receive_util[2][1][1] <= receive_util[2][1][2]:
p_min = 0
p_max = 1
elif temp == 0 and receive_util[2][1][1] > receive_util[2][1][2]:
F2_empty = 1
if not F2_empty:
EU_R = theta * receive_util[1][2][Aj] + (1 - theta) * receive_util[2][2][Aj]
EU_S = theta * transmit_util[1][2][Aj] + (1 - theta) * transmit_util[2][2][Aj]
S1 = ('M{}, M{}'.format(Mj, Mj))
S2 = ('A{}, A{}'.format(2, Aj))
PBE.append({'type':2, 'S1':S1, 'S2':S2, 'q_range':(q, q), 'p_range':(p_min, p_max), 'EU_S':EU_S, 'EU_R':EU_R})
return PBE