@@ -890,7 +890,7 @@ def __len__(self):
890
890
"""
891
891
return len (self .utilities )
892
892
893
- def _repr_ (self ):
893
+ def _repr_ (self ) -> str :
894
894
r"""
895
895
Return the strategy_profiles of the game.
896
896
@@ -909,7 +909,7 @@ def _repr_(self):
909
909
base_str = "Normal Form Game with the following utilities: {}"
910
910
return base_str .format (pformat (self .utilities ))
911
911
912
- def _latex_ (self ):
912
+ def _latex_ (self ) -> str :
913
913
r"""
914
914
Return the LaTeX code representing the ``NormalFormGame``.
915
915
@@ -1194,7 +1194,7 @@ def is_constant_sum(self):
1194
1194
return False
1195
1195
m1 , m2 = self .payoff_matrices ()
1196
1196
c = m1 + m2
1197
- t = c [0 ,0 ]
1197
+ t = c [0 , 0 ]
1198
1198
1199
1199
for row in c :
1200
1200
for i in row :
@@ -2021,7 +2021,7 @@ def _solve_enumeration(self, maximization=True):
2021
2021
powerset (range (player .num_strategies ))]
2022
2022
for player in self .players ]
2023
2023
2024
- potential_support_pairs = [ pair for pair in product (* potential_supports ) if len (pair [0 ]) == len (pair [1 ])]
2024
+ potential_support_pairs = ( pair for pair in product (* potential_supports ) if len (pair [0 ]) == len (pair [1 ]))
2025
2025
2026
2026
equilibria = []
2027
2027
for pair in potential_support_pairs :
@@ -2230,7 +2230,7 @@ def _is_NE(self, a, b, p1_support, p2_support, M1, M2):
2230
2230
p2_payoffs = [sum (v * col [j ] for j , v in enumerate (a ))
2231
2231
for col in M2 .columns ()]
2232
2232
2233
- #if p1_payoffs.index(max(p1_payoffs)) not in p1_support:
2233
+ # if p1_payoffs.index(max(p1_payoffs)) not in p1_support:
2234
2234
if not any (i in p1_support for i , x in enumerate (p1_payoffs )
2235
2235
if x == max (p1_payoffs )):
2236
2236
return False
@@ -2240,89 +2240,6 @@ def _is_NE(self, a, b, p1_support, p2_support, M1, M2):
2240
2240
2241
2241
return True
2242
2242
2243
- def _Hrepresentation (self , m1 , m2 ):
2244
- r"""
2245
- Create the H-representation strings required to use ``lrsnash``.
2246
-
2247
- Since lrslib 6.1, this format is referred to as "legacy format".
2248
-
2249
- This method is deprecated.
2250
-
2251
- EXAMPLES::
2252
-
2253
- sage: A = matrix([[1, 2], [3, 4]])
2254
- sage: B = matrix([[3, 3], [1, 4]])
2255
- sage: C = NormalFormGame([A, B])
2256
- sage: print(C._Hrepresentation(A, B)[0])
2257
- doctest:warning...
2258
- DeprecationWarning: NormalFormGame._Hrepresentation is deprecated as it
2259
- creates the legacy input format. Use NormalFormGame._lrs_nash_format instead
2260
- See https://github.com/sagemath/sage/issues/27745 for details.
2261
- H-representation
2262
- linearity 1 5
2263
- begin
2264
- 5 4 rational
2265
- 0 1 0 0
2266
- 0 0 1 0
2267
- 0 -3 -1 1
2268
- 0 -3 -4 1
2269
- -1 1 1 0
2270
- end
2271
- <BLANKLINE>
2272
- sage: print(C._Hrepresentation(A, B)[1])
2273
- H-representation
2274
- linearity 1 5
2275
- begin
2276
- 5 4 rational
2277
- 0 -1 -2 1
2278
- 0 -3 -4 1
2279
- 0 1 0 0
2280
- 0 0 1 0
2281
- -1 1 1 0
2282
- end
2283
- <BLANKLINE>
2284
- """
2285
- from sage .misc .superseded import deprecation
2286
- deprecation (27745 ,
2287
- "NormalFormGame._Hrepresentation is deprecated as it "
2288
- "creates the legacy input format. "
2289
- "Use NormalFormGame._lrs_nash_format instead" )
2290
-
2291
- from sage .geometry .polyhedron .misc import _to_space_separated_string
2292
- m = self .players [0 ].num_strategies
2293
- n = self .players [1 ].num_strategies
2294
- midentity = list (matrix .identity (m ))
2295
- nidentity = list (matrix .identity (n ))
2296
-
2297
- s = 'H-representation\n '
2298
- s += 'linearity 1 ' + str (m + n + 1 ) + '\n '
2299
- s += 'begin\n '
2300
- s += str (m + n + 1 ) + ' ' + str (m + 2 ) + ' rational\n '
2301
- for f in list (midentity ):
2302
- s += '0 ' + _to_space_separated_string (f ) + ' 0 \n '
2303
- for e in list (m2 .transpose ()):
2304
- s += '0 ' + _to_space_separated_string (- e ) + ' 1 \n '
2305
- s += '-1 '
2306
- for g in range (m ):
2307
- s += '1 '
2308
- s += '0 \n '
2309
- s += 'end\n '
2310
-
2311
- t = 'H-representation\n '
2312
- t += 'linearity 1 ' + str (m + n + 1 ) + '\n '
2313
- t += 'begin\n '
2314
- t += str (m + n + 1 ) + ' ' + str (n + 2 ) + ' rational\n '
2315
- for e in list (m1 ):
2316
- t += '0 ' + _to_space_separated_string (- e ) + ' 1 \n '
2317
- for f in list (nidentity ):
2318
- t += '0 ' + _to_space_separated_string (f ) + ' 0 \n '
2319
- t += '-1 '
2320
- for g in range (n ):
2321
- t += '1 '
2322
- t += '0 \n '
2323
- t += 'end\n '
2324
- return s , t
2325
-
2326
2243
def _lrs_nash_format (self , m1 , m2 ):
2327
2244
r"""
2328
2245
Create the input format for ``lrsnash``, version 6.1 or newer.
@@ -2346,53 +2263,24 @@ def _lrs_nash_format(self, m1, m2):
2346
2263
4 3
2347
2264
<BLANKLINE>
2348
2265
2349
- sage: legacy_format = C._Hrepresentation(A, B)
2350
- doctest:warning...
2351
- DeprecationWarning: NormalFormGame._Hrepresentation is deprecated as it
2352
- creates the legacy input format. Use NormalFormGame._lrs_nash_format instead
2353
- See https://github.com/sagemath/sage/issues/27745 for details.
2354
- sage: print('*game: player 1\n', legacy_format[0])
2355
- *game: player 1
2356
- H-representation
2357
- linearity 1 6
2358
- begin
2359
- 6 5 rational
2360
- 0 1 0 0 0
2361
- 0 0 1 0 0
2362
- 0 0 0 1 0
2363
- 0 -1 0 -4 1
2364
- 0 0 -2 -3 1
2365
- -1 1 1 1 0
2366
- end
2367
- <BLANKLINE>
2368
- sage: print('*game: player 2\n', legacy_format[1])
2369
- *game: player 2
2370
- H-representation
2371
- linearity 1 6
2372
- begin
2373
- 6 4 rational
2374
- 0 0 -6 1
2375
- 0 -2 -5 1
2376
- 0 -3 -3 1
2377
- 0 1 0 0
2378
- 0 0 1 0
2379
- -1 1 1 0
2380
- end
2266
+ .. NOTE::
2267
+
2268
+ The former legacy format has been removed in :issue:`39464`.
2381
2269
"""
2382
2270
from sage .geometry .polyhedron .misc import _to_space_separated_string
2383
2271
m = self .players [0 ].num_strategies
2384
2272
n = self .players [1 ].num_strategies
2385
2273
s = f'{ m } { n } \n \n '
2386
- for r in m1 .rows ():
2387
- s += _to_space_separated_string (r ) + '\n '
2274
+ s += '\n ' .join (_to_space_separated_string (r ) for r in m1 .rows ())
2275
+ s += '\n \n '
2276
+ s += '\n ' .join (_to_space_separated_string (r ) for r in m2 .rows ())
2388
2277
s += '\n '
2389
- for r in m2 .rows ():
2390
- s += _to_space_separated_string (r ) + '\n '
2391
2278
return s
2392
2279
2393
- def is_degenerate (self , certificate = False ):
2280
+ def is_degenerate (self , certificate = False ) -> bool :
2394
2281
"""
2395
2282
A function to check whether the game is degenerate or not.
2283
+
2396
2284
Will return a boolean.
2397
2285
2398
2286
A two-player game is called nondegenerate if no mixed strategy of
0 commit comments