This repository was archived by the owner on Mar 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.hs
265 lines (191 loc) · 7.31 KB
/
Main.hs
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances, FunctionalDependencies #-}
-- | Solution concepts for two-player games
module Main where
import Data.Array
import Data.List(nub, elemIndex)
import TypeLevel.NaturalNumber
import Math.GameTheory.NormalForm
import Math.GameTheory.Common
import Math.GameTheory.Internal.NormalForm
main = undefined
-- | Shortcuts for 2 and 3 player games
rowPlayer = 1
colPlayer = 2
matPlayer = 3
yankPos :: (NaturalNumber n) => (Pos Int (SuccessorTo n)) -> Int -> Pos Int n
yankPos (Pos l n) i = Pos (snd (yank (i - 1) l)) (predecessorOf n)
emptyPos :: Pos a N0
emptyPos = Pos [] n0
appendPos :: (NaturalNumber n) => (Pos a n) -> a -> Pos a (SuccessorTo n)
appendPos g@(Pos l n) v = insertPos g (length l) v
--------------------
stackelberg1 :: Game N2
stackelberg1 = mkGame2 [[1 <\> 3, 3 <\> 1],
[0 <\> 0, 2 <\> 1]]
stackelberg2 :: Game N2
stackelberg2 = mkGame2 [[0 <\> 3, 3 <\> 2],
[1 <\> 0, 2 <\> 1]]
game22a :: Game N3
game22a = mkGame3 [ [ [1 <\> 1 <\> 0, 0 <\> 1 <\> 1],
[0 <\> 1 <\> 1, 1 <\> 0 <\> 1] ],
[ [0 <\> 1 <\> 1, 1 <\> 0 <\> 1],
[1 <\> 0 <\> 1, 1 <\> 1 <\> 0] ]
]
g2Game :: Game N2
g2Game = mkGame2 [ [1 <\> 1, 0 <\> 2, 2 <\> 0, 0 <\> 2],
[2 <\> 0, 1 <\> 1, 0 <\> 2, 2 <\> 0],
[0 <\> 2, 2 <\> 0, 1 <\> 1, 0 <\> 2],
[2 <\> 0, 0 <\> 2, 2 <\> 0, 1 <\> 1]
]
{-
A = {2,3,4,5,6}
2 3 4 5 6
2 0,0 -1,1 2,-2 -1,1 2,-2
3 1,-1 0,0 -1,1 -1,1 2,-2
4 -2,2 1,-1 0,0 -1,1 -1,1
5 1,-1 1,-1 1,-1 0,0 -1,1
6 -2,2 -2,2 1,-1 1,-1 0,0
-}
g25Game :: Game N2
g25Game = mkGame2 [[ 0 <\> 0 , (-1) <\> 1 , 2 <\> (-2), (-1) <\> 1 , 2 <\> (-2)],
[ 1 <\> (-1), 0 <\> 0 , (-1) <\> 1 , (-1) <\> 1 , 2 <\> (-2)],
[(-2) <\> 2 , 1 <\> (-1), 0 <\> 0 , (-1) <\> 1 , (-1) <\> 1 ],
[ 1 <\> (-1), 1 <\> (-1), 1 <\> (-1), 0 <\> 0 , (-1) <\> 1 ],
[(-2) <\> 2 , (-2) <\> 2 , 1 <\> (-1), 1 <\> (-1), 0 <\> 0 ]
]
g27TestGame :: Game N2
g27TestGame = mkGame2 [[0 <\> 0, (-1) <\> 1, 1 <\> (-1), (-1) <\> 1],
[1 <\> (-1), 0 <\> 0, (-1) <\> 1, 1 <\> (-1)],
[(-1) <\> 1, 1 <\> (-1), 0 <\> 0, (-1) <\> 1],
[1 <\> (-1), (-1) <\> 1, 1 <\> (-1), 0 <\> 0]]
g30Game :: Game N2
g30Game = mkGame2 [[4 <\> 2, 5 <\> 1],
[3 <\> 3, 1 <\> 2],
[5 <\> 1, 4 <\> 3]]
g30Game' :: Game N2
g30Game' = mkGame2 [[4 <\> 2, 5 <\> 1],
[5 <\> 1, 4 <\> 3]]
g31Game :: Game N3
g31Game = mkGame3 [ [ [1 <\> 1 <\> 0, 1 <\> -2 <\> -1],
[1 <\> 1 <\> 0, 1 <\> -2 <\> -1]],
[ [0 <\> -1 <\> -1, 0 <\> 0 <\> 1],
[0 <\> -1 <\> -1, 0 <\> 0 <\> 1]]]
prisonersDillema :: Game N2
prisonersDillema = mkGame2 [[2 <\> 2, 0 <\> 3],
[3 <\> 0, 1 <\> 1]]
{-
tstGame = mkGame [ [3 <\> 1, 0 <\> 0],
[0 <\> 3, 3 <\> 2],
[1 <\> 1, 1 <\> 2] ]
tstGame' = mkGame [ [3 <\> 1, 0 <\> 0],
[0 <\> 3, 3 <\> 2]]
tstGame'' = mkGame [ [3 <\> 1],
[0 <\> 3] ]
tstGame3 = mkGame [ [3 <\> 1, 0 <\> 0, 0 <\> 0],
[1 <\> 1, 1 <\> 2, 5 <\> 0],
[0 <\> 1, 4 <\> 0, 0 <\> 0] ]
iterDomTest = tstGame3
tstGame3' = mkGame [ [3 <\> 1, 0 <\> 0],
[1 <\> 1, 1 <\> 2],
[0 <\> 1, 4 <\> 0] ]
tstGame3'' = mkGame [ [3 <\> 1, 0 <\> 0],
[0 <\> 1, 4 <\> 0] ]
tstGame3''' = mkGame [ [3 <\> 1],
[0 <\> 1] ]
iterWeakDomTest = mkGame [ [2 <\> 1, 1 <\> 1, 0 <\> 0],
[1 <\> 1, 1 <\> 2, 0 <\> 1],
[0 <\> 0, 1 <\> 0, 1 <\> 1] ]
game18a = mkGame [ [2 <\> 2, 0 <\> 1],
[1 <\> 1, 3 <\> 3] ]
game18b a = mkGame [ [1 <\> 1, a <\> 0],
[0 <\> 0, 2 <\> 1] ]
main = print $ dominated tstGame RowPlayer 1
gGame = mkGame [ [(0,0),(3,1)]
, [(1,3),(0,0)]
]
-- main = print $ maxiMin gGame RowPlayer
g1Game = mkGame [ [1 <\> 1, 0 <\> 2, 2 <\> 0],
[2 <\> 0, 1 <\> 1, 0 <\> 2],
[0 <\> 2, 2 <\> 0, 1 <\> 1] ]
g2Game = mkGame [ [1 <\> 1, 0 <\> 2, 2 <\> 0, 0 <\> 2],
[2 <\> 0, 1 <\> 1, 0 <\> 2, 2 <\> 0],
[0 <\> 2, 2 <\> 0, 1 <\> 1, 0 <\> 2],
[2 <\> 0, 0 <\> 2, 2 <\> 0, 1 <\> 1]
]
g3Game = mkGame [ [1 <\> 1, 0 <\> 2, 2 <\> 0, 0 <\> 2],
[2 <\> 0, 1 <\> 1, 0 <\> 2, 0 <\> 2],
[0 <\> 2, 2 <\> 0, 1 <\> 1, 0 <\> 2],
[2 <\> 0, 2 <\> 0, 2 <\> 0, 1 <\> 1]
]
g4Game = mkGame [ [1 <\> 1, 2 <\> 0, 2 <\> 0, 0 <\> 2],
[0 <\> 2, 1 <\> 1, 0 <\> 2, 0 <\> 2],
[0 <\> 2, 2 <\> 0, 1 <\> 1, 0 <\> 2],
[2 <\> 0, 2 <\> 0, 2 <\> 0, 1 <\> 1]
]
g4Game' = mkGame [ [1 <\> 1, 2 <\> 0, 0 <\> 2],
[0 <\> 2, 1 <\> 1, 0 <\> 2],
[2 <\> 0, 2 <\> 0, 1 <\> 1]
]
g4Game'' = mkGame [ [1 <\> 1, 0 <\> 2],
[2 <\> 0, 1 <\> 1]
]
{-
maximize u with r*1+p*2+s*0+w*2>=u,r*0+p*1+s*2+w*0>=u,r*2+p*0+s*1+w*2>=u,r*0+p*2+s*0+w*1>=u,r+p+s+w=1,r>=0,p>=0,s>=0,w>=0
-}
-- main = print $ maxiMin g2Game ColPlayer
-- main = print $ expectedUtility g2Game RowPlayer ([0,1/3,1/3,1/3],[0,1/3,1/3,1/3])
prisoner = mkGame [ [1 <\> 1, 3 <\> 0]
, [0 <\> 3, 2 <\> 2]]
-- main = print $ expectedUtility prisoner RowPlayer ([1.0,0.0],[0.0,1.0])
-- main = print $ maxiMin prisoner RowPlayer
{-
-- variables are s_1_A, s_2_A, U_1
battleOfSexesProb = Maximize [0, 0, 1]
battleOfSexesConstr =
Dense [ [2, 0, -1] :=>: 0
, [0, 1, -1] :=>: 0
, [0, 1, 0] :=>: 0
, [1, 1, 0] :==: 1
]
solBattleSexes = simplex battleOfSexesProb battleOfSexesConstr []
-- main = print sol
{-
G-Homework:
s_1_A * 0 + s_1_B * 1 >= U_1
s_1_A * 3 + s_1_B * 0 >= U_1
-}
hwProb = Maximize [0, 0, 1]
hwConstr =
Dense [ [0, 1, -1] :=>: 0
, [3, 0, -1] :=>: 0
, [0, 1, 0] :=>: 0
, [1, 1, 0] :==: 1
]
solHw = simplex hwProb hwConstr []
main = print solHw
{-
Exp payoff for player 1:
s_1_A * s_2_A * 0 + s_1_A * s_2_B * 3 +
s_1_B * s_2_A * 1 + s_1_B * s_2_B * 0
= s_1_A * s_2_B * 3 + s_1_B * s_2_A * 1
similarly for player 2.
This is not a linear problem.
-}
hwProb2 = Maximize []
hw2Constr =
Dense [
{-
prob = Maximize [4, -3, 2]
{-
constr1 = Sparse [ [2#1, 1#2] :<: 10
, [1#2, 5#3] :<: 20
]
-}
constr2 = Dense [ [2,1,0] :<=: 10
, [0,1,5] :<=: 20
]
foo = simplex prob constr2 []
main = print foo
-}
-}
-}