SGSolve
sgsolver_maxminmax_3player.hpp
1 // This file is part of the SGSolve library for stochastic games
2 // Copyright (C) 2019 Benjamin A. Brooks
3 //
4 // SGSolve free software: you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // SGSolve is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see
16 // <http://www.gnu.org/licenses/>.
17 //
18 // Benjamin A. Brooks
19 // ben@benjaminbrooks.net
20 // Chicago, IL
21 
22 #ifndef _SGSOLVER_MAXMINMAX_3PLAYER_HPP
23 #define _SGSOLVER_MAXMINMAX_3PLAYER_HPP
24 
25 #include "sgcommon.hpp"
26 #include "sgutilities.hpp"
27 #include "sgenv.hpp"
28 #include "sggame.hpp"
29 #include "sgaction_maxminmax.hpp"
30 #include "sgexception.hpp"
31 #include "sgsolution_maxminmax.hpp"
32 #include "sgedgepolicy.hpp"
33 
35 
44 {
45 private:
46  // Data
47 
49  const SGEnv & env;
51  const SGGame & game;
54 
55  // References to objects in the game
56  const double delta;
58  const int numPlayers;
59  const int numStates;
62  const vector< vector<bool> > & eqActions;
66  const vector< vector<SGPoint> > & payoffs;
67  const vector< vector< vector<double> > > & probabilities;
68  const vector< vector<int> > numActions;
69  const vector< int > numActions_totalByState;
71  list<SGPoint> directions;
72  list< vector<double> > levels;
74  list<SGPoint> threatDirections;
76  vector< list<SGAction_MaxMinMax> > actions;
78  const SGPoint dueEast = SGPoint(1.0,0.0);
79  const SGPoint dueNorth = SGPoint(0.0,1.0);
81  int numIter;
82  double errorLevel;
90  bool debugMode;
92 public:
95 
97 
99  SGSolver_MaxMinMax_3Player(const SGEnv & _env,
100  const SGGame & _game);
101 
104 
106 
111  void solve(const int numDirsApprox = 200,
112  const bool dropRedundant = true,
113  const bool addEndogenous = true);
114 
116 
121  void solve_endogenous();
122 
124 
125  double iterate_endogenous();
126 
128 
129  double iterate(const int maxDirections,
130  const bool dropRedundant,
131  const bool addEndogenous);
132 
134  void initialize();
135 
136  std::string progressString() const;
137 
139  void optimizePolicy(SGTuple & pivot,
140  vector<SGActionIter> & actionTuple,
141  vector<SG::Regime> & regimeTuple,
142  const SGPoint & currDir,
143  const vector<list<SGAction_MaxMinMax> > & actions) const;
144 
148  bool computeOptimalPolicies(SGProductPolicy & optPolicies,
149  const SGTuple & pivot,
150  const SGPoint & currDir,
151  const vector<list<SGAction_MaxMinMax> > & actions) const;
152 
155  double sensitivity(SGPoint & optSubDir,
156  const SGTuple & pivot,
157  const SGPoint & currDir,
158  const SGPoint & newDir,
159  const vector<list<SGAction_MaxMinMax> > & actions) const;
160 
162  void policyToPayoffs(SGTuple & pivot,
163  const vector<SGActionIter> & actionTuple,
164  const vector<SG::Regime> & regimeTuple) const;
165 
168  const SGSolution_MaxMinMax& getSolution() const {return soln;}
169 };
170 
171 
172 #endif
SGSolver_MaxMinMax_3Player::numActions_totalByState
const vector< int > numActions_totalByState
Definition: sgsolver_maxminmax_3player.hpp:69
SGSolver_MaxMinMax_3Player::threatTuple
SGTuple threatTuple
Definition: sgsolver_maxminmax_3player.hpp:75
SGSolver_MaxMinMax_3Player::numActions
const vector< vector< int > > numActions
Definition: sgsolver_maxminmax_3player.hpp:68
SGSolver_MaxMinMax_3Player::directions
list< SGPoint > directions
Definition: sgsolver_maxminmax_3player.hpp:71
SGSolver_MaxMinMax_3Player::levels
list< vector< double > > levels
Definition: sgsolver_maxminmax_3player.hpp:72
SGProductPolicy
Class for storing product policies.
Definition: sgproductpolicy.hpp:39
SGSolver_MaxMinMax_3Player::numStates
const int numStates
Definition: sgsolver_maxminmax_3player.hpp:59
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGSolver_MaxMinMax_3Player::payoffUB
SGPoint payoffUB
Definition: sgsolver_maxminmax_3player.hpp:85
SGSolver_MaxMinMax_3Player::dueEast
const SGPoint dueEast
Definition: sgsolver_maxminmax_3player.hpp:78
SGSolver_MaxMinMax_3Player::actions
vector< list< SGAction_MaxMinMax > > actions
Definition: sgsolver_maxminmax_3player.hpp:76
SGSolver_MaxMinMax_3Player::errorLevel
double errorLevel
Definition: sgsolver_maxminmax_3player.hpp:82
SGSolver_MaxMinMax_3Player::iterate_endogenous
double iterate_endogenous()
One iteration of the endogenous algorithm.
Definition: sgsolver_maxminmax_3player.cpp:515
SGSolver_MaxMinMax_3Player::~SGSolver_MaxMinMax_3Player
~SGSolver_MaxMinMax_3Player()
Destructor.
Definition: sgsolver_maxminmax_3player.hpp:103
SGSolver_MaxMinMax_3Player::payoffs
const vector< vector< SGPoint > > & payoffs
Definition: sgsolver_maxminmax_3player.hpp:66
SGSolver_MaxMinMax_3Player::dueNorth
const SGPoint dueNorth
Definition: sgsolver_maxminmax_3player.hpp:79
SGSolver_MaxMinMax_3Player::optimizePolicy
void optimizePolicy(SGTuple &pivot, vector< SGActionIter > &actionTuple, vector< SG::Regime > &regimeTuple, const SGPoint &currDir, const vector< list< SGAction_MaxMinMax > > &actions) const
Optimizes the policy for the given direction.
Definition: sgsolver_maxminmax_3player.cpp:1010
sgutilities.hpp
SGSolver_MaxMinMax_3Player::computeOptimalPolicies
bool computeOptimalPolicies(SGProductPolicy &optPolicies, const SGTuple &pivot, const SGPoint &currDir, const vector< list< SGAction_MaxMinMax > > &actions) const
Definition: sgsolver_maxminmax_3player.cpp:1204
SGSolver_MaxMinMax_3Player::numPlayers
const int numPlayers
Definition: sgsolver_maxminmax_3player.hpp:58
SGSolver_MaxMinMax_3Player::payoffLB
SGPoint payoffLB
Definition: sgsolver_maxminmax_3player.hpp:84
SGSolver_MaxMinMax_3Player::debugMode
bool debugMode
Definition: sgsolver_maxminmax_3player.hpp:90
SGSolver_MaxMinMax_3Player::numEndogDirs
int numEndogDirs
Definition: sgsolver_maxminmax_3player.hpp:88
SGSolver_MaxMinMax_3Player::getSolution
const SGSolution_MaxMinMax & getSolution() const
Definition: sgsolver_maxminmax_3player.hpp:168
SGSolution_MaxMinMax
Records the progress of SGSolver_MaxMinMax::solve().
Definition: sgsolution_maxminmax.hpp:40
SGEnv
Manages parameters for algorithm behavior.
Definition: sgenv.hpp:35
SGSolver_MaxMinMax_3Player::numIter
int numIter
Definition: sgsolver_maxminmax_3player.hpp:81
SGSolver_MaxMinMax_3Player::eqActions
const vector< vector< bool > > & eqActions
Definition: sgsolver_maxminmax_3player.hpp:62
SGSolver_MaxMinMax_3Player
Class for solving stochastic games.
Definition: sgsolver_maxminmax_3player.hpp:44
SGSolver_MaxMinMax_3Player::numRedundDirs
int numRedundDirs
Definition: sgsolver_maxminmax_3player.hpp:87
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGSolver_MaxMinMax_3Player::policyToPayoffs
void policyToPayoffs(SGTuple &pivot, const vector< SGActionIter > &actionTuple, const vector< SG::Regime > &regimeTuple) const
Converts a policy function to a payoff function using bellman iteration.
Definition: sgsolver_maxminmax_3player.cpp:1459
SGSolver_MaxMinMax_3Player::env
const SGEnv & env
SGEnv object to hold parameters.
Definition: sgsolver_maxminmax_3player.hpp:49
SGSolver_MaxMinMax_3Player::solve
void solve(const int numDirsApprox=200, const bool dropRedundant=true, const bool addEndogenous=true)
Fixed direction solve routine.
Definition: sgsolver_maxminmax_3player.cpp:44
SGSolver_MaxMinMax_3Player::soln
SGSolution_MaxMinMax soln
SGSolution object used by SGApprox to store data.
Definition: sgsolver_maxminmax_3player.hpp:53
SGSolver_MaxMinMax_3Player::probabilities
const vector< vector< vector< double > > > & probabilities
Definition: sgsolver_maxminmax_3player.hpp:67
SGSolver_MaxMinMax_3Player::solve_endogenous
void solve_endogenous()
Endogenous direction solve routine.
Definition: sgsolver_maxminmax_3player.cpp:476
SGSolver_MaxMinMax_3Player::game
const SGGame & game
Constant reference to the game to be solved.
Definition: sgsolver_maxminmax_3player.hpp:51
SGSolver_MaxMinMax_3Player::iterate
double iterate(const int maxDirections, const bool dropRedundant, const bool addEndogenous)
One iteration of the algorithm.
Definition: sgsolver_maxminmax_3player.cpp:120
SGSolver_MaxMinMax_3Player::delta
const double delta
Definition: sgsolver_maxminmax_3player.hpp:56
SGTuple
Definition: sgtuple.hpp:52
SGSolver_MaxMinMax_3Player::initialize
void initialize()
Initializes the solve routines.
Definition: sgsolver_maxminmax_3player.cpp:957
SGSolver_MaxMinMax_3Player::SGSolver_MaxMinMax_3Player
SGSolver_MaxMinMax_3Player()
Default constructor.
SGSolver_MaxMinMax_3Player::sensitivity
double sensitivity(SGPoint &optSubDir, const SGTuple &pivot, const SGPoint &currDir, const SGPoint &newDir, const vector< list< SGAction_MaxMinMax > > &actions) const
Definition: sgsolver_maxminmax_3player.cpp:1301