]> gitweb.michael.orlitzky.com - dunshire.git/blob - errors.py
Add the errors module, in a non-working state.
[dunshire.git] / errors.py
1 """
2 Errors that can occur when solving a linear game.
3 """
4
5 class GameUnsolvableException(Exception):
6 """
7 Every linear game has a solution (this follows from a general
8 min-max theorem). If we can't solve the conic program associated
9 with a linear game, then something is wrong with either the model of
10 the input.
11 """
12 def __init__(self, solution_dict):
13 """
14 Create a new GameUnsolvableException object.
15
16 INPUT:
17
18 - ``primal`` -- the objective value of the primal cone program.
19
20 - ``dual`` -- the objective value of the dual cone program.
21
22 - ``solution_dict`` -- the solution dictionary returned from the cone program.
23
24 """
25 tpl = 'solution failed with error: {:s}\n' \
26 'CVXOPT returned:\n{!s}'
27 self.message = tpl.format(solution_dict['status'], solution_dict)
28
29
30 class GameValueMismatchException(Exception):
31 """
32 This error occurs when the primal and dual objective value of the
33 conic program associated with a linear game do not agree. By
34 construction, every conic program derived from a linear game must
35 have a solution and the same objective value (the "value of the
36 game") is shared by both players.
37
38 Each instance of this class will know the two mismatched values, and
39 its ``message`` field will explain why they can't be so.
40 """
41 def __init__(self, primal, dual, solution_dict):
42 """
43 Create a new GameValueMismatchException.
44
45 INPUT:
46
47 - ``primal`` -- the objective value of the primal cone program.
48
49 - ``dual`` -- the objective value of the dual cone program.
50
51 - ``solution_dict`` -- the solution dictionary returned from the cone program.
52
53 """
54 tpl = 'game value mismatch for player1={:.7f}, player2={:.7f}\n' \
55 'CVXOPT returned:\n{!s}'
56 self.message = tpl.format(primal, dual, solution_dict)