-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex_enumeration.jl
93 lines (74 loc) · 2.07 KB
/
vertex_enumeration.jl
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
using LRSLib
function HtoV(A, b)
"""
Change the H representation of a Polyhedron to
V representation.
Parameters
----------
A : Array{Int64,2}
The matrix of left-hand side of matrix inequality:
Ax <= b
b : Array{Int64,1}
The vector of right-hand side of matrix inequality.
Return
------
V : Polyhedra.SimpleVRepresentation{2,Rational{BigInt}}
The vertex matrix which is V representation of
Ax <= b
"""
linset = IntSet()
H = Polyhedra.SimpleHRepresentation(A, b, linset)
H = LRSMatrix(H)
V = LRSGeneratorMatrix(H)
V = Polyhedra.SimpleVRepresentation(V)
return V
end
function vertex_enumeration(A, B)
"""
Given payoff matrixs of two-player strategic form game,
extend the matrixs with nonnegativity constraint of mixed actions,
and do vertex_enumeration to find NEs.
Parameters
----------
A : Array{Int64,2}
The payoff matrix of Player0.
B : Array{Int64,2}
The payoff matrix of Player1.
Return
------
NE : Array{Polyhedra.SimpleVRepresentation{2,Rational{BigInt}}, 1}
The NEs found by vertex enumeration, which are represented by
vertexs.
"""
NE = []
n1 = size(A)[2]
n2 = size(B)[2]
b1 = ones(size(A)[1])
b2 = ones(size(B)[1])
A = vcat(A, -eye(Int64, n1))
b1 = vcat(b1, zeros(n1))
B = vcat(-eye(Int64, n2), B)
b2 = vcat(zeros(n2), b2)
Q = HtoV(A, b1)
P = HtoV(B, b2)
for i in 1:size(A)[1]
for j in 1:size(B)[1]
v1 = Q.V[i, :]
v2 = P.V[j, :]
label1 = *(A, v1) - b1
ind1 = label1 .!= 0
ind2 = label1 .== 0
label1[ind1] = 0
label1[ind2] = 1
label2 = *(B, v2) - b2
ind3 = label2 .!= 0
ind4 = label2 .== 0
label2[ind3] = 0
label2[ind4] = 1
if label1 + label2 == [1., 1., 1., 1., 1.]
push!(NE, (v1, v2))
end
end
end
return NE
end