-
Notifications
You must be signed in to change notification settings - Fork 1
/
classicalStrategies.py
143 lines (124 loc) · 5.54 KB
/
classicalStrategies.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import numpy as np
def bestClassicalStrategy(game):
"""
Social welfare of the best classical strategy for a given game.
"""
try:
v0, v1 = game.v0.value, game.v1.value
except:
v0, v1 = game.v0, game.v1
if v1 == 0:
payoutRatio = np.infty
else:
payoutRatio = v0 / v1
assert(game.nbPlayers == 3 or game.nbPlayers == 5)
if game.nbPlayers == 5:
if not game.sym:
if payoutRatio <= 1 / 3:
socialWelfare = 1/30 * (8 * v0 + 17 * v1)
elif payoutRatio <= 1:
socialWelfare = 1/30 * (6 * v0 + 19 * v1)
else:
socialWelfare = 1/30 * 25 * v0
else:
if payoutRatio <= 1 / 3:
socialWelfare = 1 / 30 * (4 * v0 + 11 * v1)
elif payoutRatio <= 1:
socialWelfare = 1 / 30 * (5 * v0 + 20 * v1)
else:
socialWelfare = 1/30 * 25 * v0
else:
if payoutRatio <= 1:
socialWelfare = 1/12 * (7 * v1 + 2 * v0)
else:
socialWelfare = 1/12 * 9 * v0
return socialWelfare
def genRhoClassic(nbPlayers):
"""
Simple classical rho.
"""
n = 2**nbPlayers
rho = np.zeros((n, n))
rho[0][0] = 1
return rho
def classicalStratPOVM(game):
"""
Generate the POVMs corresponding to the best classical strategy for a given game.
"""
assert(game.nbPlayers == 5 or game.nbPlayers == 3)
try:
v0, v1 = game.v0.value, game.v1.value
except:
v0, v1 = game.v0, game.v1
payoutRatio = v0/v1
opDict = {}
if game.nbPlayers == 5:
if game.sym:
if payoutRatio <= 1/3:
#Not Not 1 1 1
#Two players Not
for playerId in range(2):
opDict[str(playerId) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "01"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "11"] = np.array([[0, 0], [0, 0]])
#Three players 1
for playerId in range(2, 5):
opDict[str(playerId) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "01"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "11"] = np.array([[0, 0], [0, 0]])
elif payoutRatio >= 1 / 3:
# Id Id 1 1 1
# Two players Id
for playerId in range(2):
opDict[str(playerId) + "00"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "10"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "11"] = np.array([[1, 0], [0, 1]])
# Three players 1
for playerId in range(2, 5):
opDict[str(playerId) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "11"] = np.array([[1, 0], [0, 1]])
else:
if payoutRatio <= 1 / 3:
print("v0/v1 = {} Not Not Not Not 1".format(payoutRatio))
# Not Not Not Not 1
for playerId in range(4):
opDict[str(playerId) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "01"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "11"] = np.array([[0, 0], [0, 0]])
opDict["4" + "00"] = np.array([[0, 0], [0, 0]])
opDict["4" + "10"] = np.array([[1, 0], [0, 1]])
opDict["4" + "01"] = np.array([[1, 0], [0, 1]])
opDict["4" + "11"] = np.array([[0, 0], [0, 0]])
elif payoutRatio >= 1 / 3:
print("v0/v1 = {} Id Id 1 1 1".format(payoutRatio))
# Id Id 1 1 1
# Two players Id
for playerId in range(2):
opDict[str(playerId) + "00"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "10"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "11"] = np.array([[1, 0], [0, 1]])
# Three players 1
for playerId in range(2, 5):
opDict[str(playerId) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "11"] = np.array([[1, 0], [0, 1]])
if game.nbPlayers == 3:
for playerId in range(2):
opDict[str(playerId) + "00"] = np.array([[1, 0], [0, 1]])
opDict[str(playerId) + "10"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(playerId) + "11"] = np.array([[1, 0], [0, 1]])
# Three players 1
opDict[str(2) + "00"] = np.array([[0, 0], [0, 0]])
opDict[str(2) + "10"] = np.array([[1, 0], [0, 1]])
opDict[str(2) + "01"] = np.array([[0, 0], [0, 0]])
opDict[str(2) + "11"] = np.array([[1, 0], [0, 1]])
return opDict