1
- import Polyhedra: hyperplane
2
-
3
1
function vertex_enumeration (g:: NormalFormGame{2} ;
4
2
plib= SimplePolyhedraLibrary {Float64} ())
5
3
@@ -25,25 +23,36 @@ function vertex_enumeration_task(c::Channel,
25
23
26
24
end
27
25
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)
31
29
32
30
n, m = size (g. players[1 ]. payoff_array)
33
31
34
32
# 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
36
45
37
46
ZERO_LABELING_BITS = (1 << (n+ m)) - (1 << m)
38
47
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] )
42
51
if labelings_bits1 == ZERO_LABELING_BITS
43
52
continue
44
53
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] )
47
56
if xor (labelings_bits1, labelings_bits2) == COMPLETE_LABELING_BITS
48
57
put! (c, (_get_mixed_action (v1),
49
58
_get_mixed_action (v2)))
@@ -53,7 +62,7 @@ function _vertex_enumeration_producer{T}(c::Channel,
53
62
54
63
end
55
64
56
- function construction_BRP {T} (g:: NormalFormGame{2, T} , plib)
65
+ function construction_BRP (g:: NormalFormGame{2, T} , plib)
57
66
58
67
n, m = size (g. players[1 ]. payoff_array)
59
68
@@ -66,7 +75,6 @@ function construction_BRP{T}(g::NormalFormGame{2, T}, plib)
66
75
b1[m+ 1 : end ] = zero (T)
67
76
H1 = hrep (C, b1)
68
77
p1 = polyhedron (H1, plib)
69
- V1 = vrep (p1)
70
78
71
79
# create Representation for player 2
72
80
D = Matrix {T} (n+ m, m)
@@ -77,22 +85,18 @@ function construction_BRP{T}(g::NormalFormGame{2, T}, plib)
77
85
b2[m+ 1 : end ] = one (T)
78
86
H2 = hrep (D, b2)
79
87
p2 = polyhedron (H2, plib)
80
- V2 = vrep (p2)
81
88
82
- return H1, V1, H2, V2
89
+ return p1, p2
83
90
end
84
91
85
- function labelings_bits (v :: VRepElement , p :: HRep )
92
+ function labelings_bits (inchalfindices :: Vector{T} ) where T <: Integer
86
93
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 )
91
96
end
92
97
return b
93
98
end
94
99
95
- function _get_mixed_action (a:: Vector )
100
+ function _get_mixed_action (a:: Vector{T} )
96
101
return a ./ sum (a)
97
102
end
98
-
0 commit comments