Skip to content

Commit 2f38cc3

Browse files
committed
Add vertex enumeration.
1 parent 7ffab27 commit 2f38cc3

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/Games.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ include("pure_nash.jl")
5858
include("repeated_game.jl")
5959
include("random.jl")
6060
include("support_enumeration.jl")
61+
include("vertex_enumeration.jl")
6162

6263
export
6364
# Types
@@ -87,6 +88,9 @@ export
8788
random_game, covariance_game,
8889

8990
# Support Enumeration
90-
support_enumeration, support_enumeration_task
91+
support_enumeration, support_enumeration_task,
92+
93+
# Vertex Enumeration
94+
vertex_enumeration, vertex_enumeration_task
9195

9296
end # module

src/vertex_enumeration.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
function vertex_enumeration(g::NormalFormGame{2}; plib=getlibraryfor(2, Float64))
2+
3+
c = Channel(0)
4+
task = vertex_enumeration_task(c, g, plib)
5+
bind(c, task)
6+
schedule(task)
7+
NEs = Tuple{Vector{Real}, Vector{Real}}[NE for NE in c]
8+
9+
return NEs
10+
11+
end
12+
13+
function vertex_enumeration_task(c::Channel,
14+
g::NormalFormGame{2},
15+
plib)
16+
17+
task = Task(
18+
() -> _vertex_enumeration_producer(c, g, plib)
19+
)
20+
21+
return task
22+
23+
end
24+
25+
function _vertex_enumeration_producer(c::Channel,
26+
g::NormalFormGame{2},
27+
plib)
28+
29+
n, m = size(g.players[1].payoff_array)
30+
BRSv = [_BRS_vertices(g, opp_idx, plib) for opp_idx in 1:2]
31+
ZERO_LABELING = BitArray(vcat(zeros(m), ones(n)))
32+
COMPLETE_LABELING = trues(n+m)
33+
34+
for i in 1:size(BRSv[1][3])[1]
35+
v1 = BRSv[1][3][i, :]
36+
labeling1 = *(BRSv[1][1], v1) .≈ BRSv[1][2]
37+
38+
if labeling1 == ZERO_LABELING
39+
continue
40+
end
41+
42+
for j in 1:size(BRSv[2][3])[1]
43+
v2 = BRSv[2][3][j, :]
44+
labeling2 = *(BRSv[2][1], v2) .≈ BRSv[2][2]
45+
46+
if xor.(labeling1, labeling2) == COMPLETE_LABELING
47+
put!(c, (_get_mixed_action(v1),
48+
_get_mixed_action(v2)))
49+
end
50+
end
51+
end
52+
end
53+
54+
function _BRS_vertices(g::NormalFormGame, idx::Integer, plib)
55+
56+
opp_idx = idx % 2 + 1
57+
B = g.players[opp_idx].payoff_array
58+
n, m = size(B)
59+
60+
arr = [B, -eye(m)]
61+
D = vcat(arr[idx], arr[opp_idx])
62+
vec = [ones(Float64, n), zeros(Float64, m)]
63+
b = vcat(vec[idx], vec[opp_idx])
64+
65+
hrep = SimpleHRepresentation(D, b)
66+
p = polyhedron(hrep, plib)
67+
vertices = SimpleVRepresentation(p).V
68+
69+
return D, b, vertices
70+
end
71+
72+
function _get_mixed_action(a)
73+
return a ./ sum(a)
74+
end

0 commit comments

Comments
 (0)