Skip to content

Commit

Permalink
Using HRepIterator and hyperplane to check binding inequalities.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizejin committed Dec 14, 2017
1 parent 2f38cc3 commit 8ee9e73
Showing 1 changed file with 54 additions and 31 deletions.
85 changes: 54 additions & 31 deletions src/vertex_enumeration.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function vertex_enumeration(g::NormalFormGame{2}; plib=getlibraryfor(2, Float64))
import Polyhedra: hyperplane

function vertex_enumeration(g::NormalFormGame{2};
plib=getlibraryfor(2, Float64))

c = Channel(0)
task = vertex_enumeration_task(c, g, plib)
Expand All @@ -22,53 +25,73 @@ function vertex_enumeration_task(c::Channel,

end

function _vertex_enumeration_producer(c::Channel,
g::NormalFormGame{2},
plib)
function _vertex_enumeration_producer{T}(c::Channel,
g::NormalFormGame{2, T},
plib)

n, m = size(g.players[1].payoff_array)
BRSv = [_BRS_vertices(g, opp_idx, plib) for opp_idx in 1:2]
ZERO_LABELING = BitArray(vcat(zeros(m), ones(n)))
COMPLETE_LABELING = trues(n+m)

for i in 1:size(BRSv[1][3])[1]
v1 = BRSv[1][3][i, :]
labeling1 = *(BRSv[1][1], v1) .≈ BRSv[1][2]
# create Representation for player 1
H1, V1, H2, V2 = construction_BRP(g, plib)

ZERO_LABELING_BITS = (1 << (n+m)) - (1 << m)
COMPLETE_LABELING_BITS = 1 << (n+m) - 1

if labeling1 == ZERO_LABELING
for v1 in vreps(V1)
labelings_bits1 = labelings_bits(v1, H1)
if labelings_bits1 == ZERO_LABELING_BITS
continue
end

for j in 1:size(BRSv[2][3])[1]
v2 = BRSv[2][3][j, :]
labeling2 = *(BRSv[2][1], v2) .≈ BRSv[2][2]

if xor.(labeling1, labeling2) == COMPLETE_LABELING
for v2 in vreps(V2)
labelings_bits2 = labelings_bits(v2, H2)
if xor(labelings_bits1, labelings_bits2) == COMPLETE_LABELING_BITS
put!(c, (_get_mixed_action(v1),
_get_mixed_action(v2)))
end
end
end
end

function _BRS_vertices(g::NormalFormGame, idx::Integer, plib)
end

opp_idx = idx % 2 + 1
B = g.players[opp_idx].payoff_array
n, m = size(B)
function construction_BRP{T}(g::NormalFormGame{2, T}, plib)

arr = [B, -eye(m)]
D = vcat(arr[idx], arr[opp_idx])
vec = [ones(Float64, n), zeros(Float64, m)]
b = vcat(vec[idx], vec[opp_idx])
n, m = size(g.players[1].payoff_array)

hrep = SimpleHRepresentation(D, b)
p = polyhedron(hrep, plib)
vertices = SimpleVRepresentation(p).V
# create Representation for player 1
C = Matrix{T}(n+m, n)
C[1:m, :] = g.players[2].payoff_array
C[m+1:end, :] = -eye(T, n)
b1 = Vector{T}(n+m)
b1[1:m] = one(T)
b1[m+1:end] = zero(T)
H1 = SimpleHRepresentation(C, b1)
p1 = polyhedron(H1, plib)
V1 = SimpleVRepresentation(p1)

# create Representation for player 2
D = Matrix{T}(n+m, m)
D[1:m, :] = -eye(T, m)
D[m+1:end, :] = g.players[1].payoff_array
b2 = Vector{T}(n+m)
b2[1:m] = zero(T)
b2[m+1:end] = one(T)
H2 = SimpleHRepresentation(D, b2)
p2 = polyhedron(H2, plib)
V2 = SimpleVRepresentation(p2)

return H1, V1, H2, V2
end

return D, b, vertices
function labelings_bits(v::VRepElement, p::HRep)
b = 0
for (i, h) in enumerate(hreps(p))
if v in hyperplane(h)
b += 1 << (i-1)
end
end
return b
end

function _get_mixed_action(a)
function _get_mixed_action(a::Vector)
return a ./ sum(a)
end

0 comments on commit 8ee9e73

Please sign in to comment.