Skip to content

Commit fd1f096

Browse files
committed
Modifications.
1 parent 8c84d43 commit fd1f096

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/vertex_enumeration.jl

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Polyhedra: hyperplane
2-
31
function vertex_enumeration(g::NormalFormGame{2};
42
plib=SimplePolyhedraLibrary{Float64}())
53

@@ -25,25 +23,36 @@ function vertex_enumeration_task(c::Channel,
2523

2624
end
2725

28-
function _vertex_enumeration_producer{T}(c::Channel,
29-
g::NormalFormGame{2, T},
30-
plib)
26+
function _vertex_enumeration_producer(c::Channel,
27+
g::NormalFormGame{2, T},
28+
plib)
3129

3230
n, m = size(g.players[1].payoff_array)
3331

3432
# create Representation for player 1
35-
H1, V1, H2, V2 = construction_BRP(g, plib)
33+
p1, p2 = construction_BRP(g, plib)
34+
V1 = points(p1)
35+
simplex1 = []
36+
for pidx in eachindex(points(p1))
37+
push!(simplex1, [idx.value for idx in incidenthalfspaceindices(p1, pidx)])
38+
end
39+
40+
V2 = points(p2)
41+
simplex2 = []
42+
for pidx in eachindex(points(p2))
43+
push!(simplex2, [idx.value for idx in incidenthalfspaceindices(p2, pidx)])
44+
end
3645

3746
ZERO_LABELING_BITS = (1 << (n+m)) - (1 << m)
3847
COMPLETE_LABELING_BITS = 1 << (n+m) - 1
39-
40-
for v1 in points(V1)
41-
labelings_bits1 = labelings_bits(v1, H1)
48+
49+
for (i, v1) in enumerate(V1)
50+
labelings_bits1 = labelings_bits(simplex1[i])
4251
if labelings_bits1 == ZERO_LABELING_BITS
4352
continue
4453
end
45-
for v2 in points(V2)
46-
labelings_bits2 = labelings_bits(v2, H2)
54+
for (j, v2) in enumerate(V2)
55+
labelings_bits2 = labelings_bits(simplex2[j])
4756
if xor(labelings_bits1, labelings_bits2) == COMPLETE_LABELING_BITS
4857
put!(c, (_get_mixed_action(v1),
4958
_get_mixed_action(v2)))
@@ -53,7 +62,7 @@ function _vertex_enumeration_producer{T}(c::Channel,
5362

5463
end
5564

56-
function construction_BRP{T}(g::NormalFormGame{2, T}, plib)
65+
function construction_BRP(g::NormalFormGame{2, T}, plib)
5766

5867
n, m = size(g.players[1].payoff_array)
5968

@@ -66,7 +75,6 @@ function construction_BRP{T}(g::NormalFormGame{2, T}, plib)
6675
b1[m+1:end] = zero(T)
6776
H1 = hrep(C, b1)
6877
p1 = polyhedron(H1, plib)
69-
V1 = vrep(p1)
7078

7179
# create Representation for player 2
7280
D = Matrix{T}(n+m, m)
@@ -77,22 +85,18 @@ function construction_BRP{T}(g::NormalFormGame{2, T}, plib)
7785
b2[m+1:end] = one(T)
7886
H2 = hrep(D, b2)
7987
p2 = polyhedron(H2, plib)
80-
V2 = vrep(p2)
8188

82-
return H1, V1, H2, V2
89+
return p1, p2
8390
end
8491

85-
function labelings_bits(v::VRepElement, p::HRep)
92+
function labelings_bits(inchalfindices::Vector{T}) where T <: Integer
8693
b = 0
87-
for (i, h) in enumerate(halfspaces(p))
88-
if v in hyperplane(h)
89-
b += 1 << (i-1)
90-
end
94+
for i in inchalfindices
95+
b += 1 << (i-1)
9196
end
9297
return b
9398
end
9499

95-
function _get_mixed_action(a::Vector)
100+
function _get_mixed_action(a::Vector{T})
96101
return a ./ sum(a)
97102
end
98-

0 commit comments

Comments
 (0)