SGSolve
sgsolver_maxminmax.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_HPP
23 #define _SGSOLVER_MAXMINMAX_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 
34 
43 {
44 private:
45  // Data
46 
48  const SGEnv & env;
50  const SGGame & game;
53 
54  // References to objects in the game
55  const double delta;
57  const int numPlayers;
58  const int numStates;
61  const vector< vector<bool> > & eqActions;
65  const vector< vector<SGPoint> > & payoffs;
66  const vector< vector< vector<double> > > & probabilities;
67  const vector< vector<int> > numActions;
68  const vector< int > numActions_totalByState;
70  list<SGPoint> directions;
71  list< vector<double> > levels;
73  vector< list<SGAction_MaxMinMax> > actions;
75  const SGPoint dueEast = SGPoint(1.0,0.0);
76  const SGPoint dueNorth = SGPoint(0.0,1.0);
78  int numIter;
79  double errorLevel;
81 public:
84 
86 
88  SGSolver_MaxMinMax(const SGEnv & _env,
89  const SGGame & _game);
90 
93 
95 
100  void solve_fixed();
101 
103 
108  void solve();
109 
111 
112  double iterate();
113 
115 double pseudoHausdorff(const list<SGPoint> & newDirections,
116  const list<vector<double> > & newLevels) const;
117 
119  void initialize();
120 
121  std::string progressString() const;
122 
124  void robustOptimizePolicy(SGTuple & pivot,
125  vector<double> & penalties,
126  vector<SGActionIter> & actionTuple,
127  vector<SG::Regime> & regimeTuple,
128  vector<bool> & bestAPSNotBinding,
129  SGTuple & bestBindingPayoffs,
130  const SGPoint currDir,
131  const vector<list<SGAction_MaxMinMax> > & actions) const;
132 
135  double sensitivity(const SGTuple & pivot,
136  const vector<double> & penalties,
137  const vector<SGActionIter> & actionTuple,
138  const vector<SG::Regime> & regimeTuple,
139  const SGPoint currDir,
140  const vector<list<SGAction_MaxMinMax> > & actions) const;
141 
143  void policyToPayoffs(SGTuple & pivot,
144  const vector<SGActionIter> & actionTuple,
145  const vector<SG::Regime> & regimeTuple) const;
146 
149  void policyToPenalties(vector<double> & penalties,
150  const vector<SGActionIter> & actionTuple,
151  const vector<SG::Regime> & regimeTuple) const;
152 
154 
157  bool lexComp(const SGPoint & a,
158  const double aPenalty,
159  const SGPoint & b,
160  const double bPenalty,
161  const SGPoint & dir ) const;
162 
164  bool computeBestBindingPayoff(const SGActionIter ait,
165  int & bestBindingPlayer,
166  int & bestBindingPoint,
167  const SGPoint & dir) const;
168 
170  void updateBestBinding(const vector<SGActionIter> & actionTuple,
171  const vector<SG::Regime> & regimeTuple,
172  const SGPoint & dir,
173  SGTuple & bestBindingPayoffs,
174  vector<bool> & bestAPSNotBinding) const;
175 
177  void minimizeRegimes(SGTuple & pivot,
178  vector<double> & penalties,
179  const vector<SGActionIter> & actionTuple,
180  vector<SG::Regime> & regimeTuple,
181  const SGPoint & dir,
182  const SGTuple & bestBindingPayoffs,
183  const vector<bool> & bestAPSNotBinding) const;
184 
186 
187  bool lexAbove(const SGPoint & a, const SGPoint & b ) const;
188 
191  const SGSolution_MaxMinMax& getSolution() const {return soln;}
192 };
193 
194 
195 #endif
SGSolver_MaxMinMax::getSolution
const SGSolution_MaxMinMax & getSolution() const
Definition: sgsolver_maxminmax.hpp:191
SGSolver_MaxMinMax::computeBestBindingPayoff
bool computeBestBindingPayoff(const SGActionIter ait, int &bestBindingPlayer, int &bestBindingPoint, const SGPoint &dir) const
Computes the best binding payoff for an action.
Definition: sgsolver_maxminmax.cpp:749
SGSolver_MaxMinMax::threatTuple
SGTuple threatTuple
Definition: sgsolver_maxminmax.hpp:72
SGSolver_MaxMinMax::pseudoHausdorff
double pseudoHausdorff(const list< SGPoint > &newDirections, const list< vector< double > > &newLevels) const
Compute approximate Hausdorff distance.
Definition: sgsolver_maxminmax.cpp:435
SGSolver_MaxMinMax::updateBestBinding
void updateBestBinding(const vector< SGActionIter > &actionTuple, const vector< SG::Regime > &regimeTuple, const SGPoint &dir, SGTuple &bestBindingPayoffs, vector< bool > &bestAPSNotBinding) const
Update best binding payoffs and check if best APS is binding.
Definition: sgsolver_maxminmax.cpp:698
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGSolver_MaxMinMax::dueEast
const SGPoint dueEast
Definition: sgsolver_maxminmax.hpp:75
SGSolver_MaxMinMax::levels
list< vector< double > > levels
Definition: sgsolver_maxminmax.hpp:71
SGSolver_MaxMinMax::lexAbove
bool lexAbove(const SGPoint &a, const SGPoint &b) const
Lexicographic comparison of directions.
Definition: sgsolver_maxminmax.cpp:736
SGSolver_MaxMinMax::numStates
const int numStates
Definition: sgsolver_maxminmax.hpp:58
SGSolver_MaxMinMax::numActions
const vector< vector< int > > numActions
Definition: sgsolver_maxminmax.hpp:67
SGSolver_MaxMinMax::soln
SGSolution_MaxMinMax soln
SGSolution object used by SGApprox to store data.
Definition: sgsolver_maxminmax.hpp:52
sgutilities.hpp
SGSolver_MaxMinMax::iterate
double iterate()
One iteration of the endogenous algorith.
Definition: sgsolver_maxminmax.cpp:270
SGSolver_MaxMinMax::probabilities
const vector< vector< vector< double > > > & probabilities
Definition: sgsolver_maxminmax.hpp:66
SGSolver_MaxMinMax::solve_fixed
void solve_fixed()
Solve routine.
Definition: sgsolver_maxminmax.cpp:41
SGSolver_MaxMinMax::directions
list< SGPoint > directions
Definition: sgsolver_maxminmax.hpp:70
SGSolver_MaxMinMax::robustOptimizePolicy
void robustOptimizePolicy(SGTuple &pivot, vector< double > &penalties, vector< SGActionIter > &actionTuple, vector< SG::Regime > &regimeTuple, vector< bool > &bestAPSNotBinding, SGTuple &bestBindingPayoffs, const SGPoint currDir, const vector< list< SGAction_MaxMinMax > > &actions) const
Optimizes the policy for the given direction.
Definition: sgsolver_maxminmax.cpp:541
SGSolver_MaxMinMax::SGSolver_MaxMinMax
SGSolver_MaxMinMax()
Default constructor.
SGSolver_MaxMinMax::lexComp
bool lexComp(const SGPoint &a, const double aPenalty, const SGPoint &b, const double bPenalty, const SGPoint &dir) const
Lexicographic comparison of points.
Definition: sgsolver_maxminmax.cpp:718
SGSolver_MaxMinMax
Class for solving stochastic games.
Definition: sgsolver_maxminmax.hpp:43
SGSolver_MaxMinMax::actions
vector< list< SGAction_MaxMinMax > > actions
Definition: sgsolver_maxminmax.hpp:73
SGSolver_MaxMinMax::policyToPenalties
void policyToPenalties(vector< double > &penalties, const vector< SGActionIter > &actionTuple, const vector< SG::Regime > &regimeTuple) const
Definition: sgsolver_maxminmax.cpp:1008
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::payoffs
const vector< vector< SGPoint > > & payoffs
Definition: sgsolver_maxminmax.hpp:65
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGSolver_MaxMinMax::numIter
int numIter
Definition: sgsolver_maxminmax.hpp:78
SGSolver_MaxMinMax::~SGSolver_MaxMinMax
~SGSolver_MaxMinMax()
Destructor.
Definition: sgsolver_maxminmax.hpp:92
SGSolver_MaxMinMax::numActions_totalByState
const vector< int > numActions_totalByState
Definition: sgsolver_maxminmax.hpp:68
SGSolver_MaxMinMax::dueNorth
const SGPoint dueNorth
Definition: sgsolver_maxminmax.hpp:76
SGSolver_MaxMinMax::eqActions
const vector< vector< bool > > & eqActions
Definition: sgsolver_maxminmax.hpp:61
SGSolver_MaxMinMax::minimizeRegimes
void minimizeRegimes(SGTuple &pivot, vector< double > &penalties, const vector< SGActionIter > &actionTuple, vector< SG::Regime > &regimeTuple, const SGPoint &dir, const SGTuple &bestBindingPayoffs, const vector< bool > &bestAPSNotBinding) const
Switches regimes from binding to non-binding to minimize levels.
Definition: sgsolver_maxminmax.cpp:780
SGSolver_MaxMinMax::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.cpp:978
SGSolver_MaxMinMax::env
const SGEnv & env
SGEnv object to hold parameters.
Definition: sgsolver_maxminmax.hpp:48
SGSolver_MaxMinMax::solve
void solve()
Solve routine.
Definition: sgsolver_maxminmax.cpp:231
SGSolver_MaxMinMax::sensitivity
double sensitivity(const SGTuple &pivot, const vector< double > &penalties, const vector< SGActionIter > &actionTuple, const vector< SG::Regime > &regimeTuple, const SGPoint currDir, const vector< list< SGAction_MaxMinMax > > &actions) const
Definition: sgsolver_maxminmax.cpp:843
SGSolver_MaxMinMax::numPlayers
const int numPlayers
Definition: sgsolver_maxminmax.hpp:57
SGSolver_MaxMinMax::initialize
void initialize()
Initializes the solve routines.
Definition: sgsolver_maxminmax.cpp:470
SGSolver_MaxMinMax::errorLevel
double errorLevel
Definition: sgsolver_maxminmax.hpp:79
SGTuple
Definition: sgtuple.hpp:52
SGSolver_MaxMinMax::game
const SGGame & game
Constant reference to the game to be solved.
Definition: sgsolver_maxminmax.hpp:50
SGSolver_MaxMinMax::delta
const double delta
Definition: sgsolver_maxminmax.hpp:55