1
- function vertex_enumeration (g:: NormalFormGame{2} ; plib= getlibraryfor (2 , Float64))
1
+ import Polyhedra: hyperplane
2
+
3
+ function vertex_enumeration (g:: NormalFormGame{2} ;
4
+ plib= getlibraryfor (2 , Float64))
2
5
3
6
c = Channel (0 )
4
7
task = vertex_enumeration_task (c, g, plib)
@@ -22,53 +25,73 @@ function vertex_enumeration_task(c::Channel,
22
25
23
26
end
24
27
25
- function _vertex_enumeration_producer (c:: Channel ,
26
- g:: NormalFormGame{2} ,
27
- plib)
28
+ function _vertex_enumeration_producer {T} (c:: Channel ,
29
+ g:: NormalFormGame{2, T } ,
30
+ plib)
28
31
29
32
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
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 ]
34
+ # create Representation for player 1
35
+ H1, V1, H2, V2 = construction_BRP (g, plib)
36
+
37
+ ZERO_LABELING_BITS = (1 << (n+ m)) - (1 << m)
38
+ COMPLETE_LABELING_BITS = 1 << (n+ m) - 1
37
39
38
- if labeling1 == ZERO_LABELING
40
+ for v1 in vreps (V1)
41
+ labelings_bits1 = labelings_bits (v1, H1)
42
+ if labelings_bits1 == ZERO_LABELING_BITS
39
43
continue
40
44
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
45
+ for v2 in vreps (V2)
46
+ labelings_bits2 = labelings_bits (v2, H2)
47
+ if xor (labelings_bits1, labelings_bits2) == COMPLETE_LABELING_BITS
47
48
put! (c, (_get_mixed_action (v1),
48
49
_get_mixed_action (v2)))
49
50
end
50
51
end
51
52
end
52
- end
53
53
54
- function _BRS_vertices (g :: NormalFormGame , idx :: Integer , plib)
54
+ end
55
55
56
- opp_idx = idx % 2 + 1
57
- B = g. players[opp_idx]. payoff_array
58
- n, m = size (B)
56
+ function construction_BRP {T} (g:: NormalFormGame{2, T} , plib)
59
57
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])
58
+ n, m = size (g. players[1 ]. payoff_array)
64
59
65
- hrep = SimpleHRepresentation (D, b)
66
- p = polyhedron (hrep, plib)
67
- vertices = SimpleVRepresentation (p). V
60
+ # create Representation for player 1
61
+ C = Matrix {T} (n+ m, n)
62
+ C[1 : m, :] = g. players[2 ]. payoff_array
63
+ C[m+ 1 : end , :] = - eye (T, n)
64
+ b1 = Vector {T} (n+ m)
65
+ b1[1 : m] = one (T)
66
+ b1[m+ 1 : end ] = zero (T)
67
+ H1 = SimpleHRepresentation (C, b1)
68
+ p1 = polyhedron (H1, plib)
69
+ V1 = SimpleVRepresentation (p1)
70
+
71
+ # create Representation for player 2
72
+ D = Matrix {T} (n+ m, m)
73
+ D[1 : m, :] = - eye (T, m)
74
+ D[m+ 1 : end , :] = g. players[1 ]. payoff_array
75
+ b2 = Vector {T} (n+ m)
76
+ b2[1 : m] = zero (T)
77
+ b2[m+ 1 : end ] = one (T)
78
+ H2 = SimpleHRepresentation (D, b2)
79
+ p2 = polyhedron (H2, plib)
80
+ V2 = SimpleVRepresentation (p2)
81
+
82
+ return H1, V1, H2, V2
83
+ end
68
84
69
- return D, b, vertices
85
+ function labelings_bits (v:: VRepElement , p:: HRep )
86
+ b = 0
87
+ for (i, h) in enumerate (hreps (p))
88
+ if v in hyperplane (h)
89
+ b += 1 << (i- 1 )
90
+ end
91
+ end
92
+ return b
70
93
end
71
94
72
- function _get_mixed_action (a)
95
+ function _get_mixed_action (a:: Vector )
73
96
return a ./ sum (a)
74
97
end
0 commit comments