SGSolve
sgaction_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 // Classes for storing data for stochastic games.
23 #ifndef _SGACTION_MAXMINMAX_HPP
24 #define _SGACTION_MAXMINMAX_HPP
25 
26 #include "sgcommon.hpp"
27 #include "sgtuple.hpp"
28 #include "sgenv.hpp"
29 #include "sggame.hpp"
30 #include "sgbaseaction.hpp"
31 #include "sghyperplane.hpp"
32 
33 
35 
45 {
46 private:
47  const SGEnv * env;
56 public:
59  env(new SGEnv()),
60  SGBaseAction()
61  {}
62 
64 
65  SGAction_MaxMinMax(const SGEnv & _env):
66  env(&_env),
67  SGBaseAction()
68  {}
69 
71 
72  SGAction_MaxMinMax(const SGEnv & _env,
73  int _state,
74  int _action):
75  SGAction_MaxMinMax(_env,2,_state,_action)
76  {}
77 
79 
81  SGAction_MaxMinMax(const SGEnv & _env,
82  int _numPlayers,
83  int _state,
84  int _action):
85  env(&_env),
86  SGBaseAction(_numPlayers,_state,_action),
87  trimmedBndryDirs(_numPlayers,SGTuple(2,SGPoint(2,0.0)))
88  {
89  trimmedPoints.resize(_numPlayers);
90  // cout << numPlayers << endl;
91  }
92 
94 
97  void resetTrimmedPoints();
98 
100 
103  void resetTrimmedPoints(const SGPoint & payoffUB);
104 
106  void updateTrim();
107 
109  double distToTrimmed() const;
110 
112  bool intersectHalfSpace(const SGPoint & normal,
113  const double level,
114  int player,
115  SGTuple & segment,
116  SGTuple & segmentDirs);
117 
119  bool intersectPolygonHalfSpace(const SGPoint & normal,
120  const double level,
121  int player,
122  SGTuple & extPnts,
123  SGTuple & extPntDirs);
124 
126 
127  bool trim(const SGPoint & normal,
128  double level);
129 
131  void mergeDuplicatePoints(const double tol);
132 
134  void calculateMinIC(const SGGame & game,
135  const vector<bool> & update,
136  const SGTuple & threatTuple);
137 
139  void calculateMinIC(const SGGame & game,
140  const SGTuple & threatTuple)
141  {
142  calculateMinIC(game,vector<bool>(numPlayers,true),threatTuple);
143  }
144 
146 
149  static double calculateMinIC(int action,int state, int player,
150  const SGGame & game,
151  const SGTuple & threatTuple);
152 
154  const vector<SGTuple> & getTrimmedPoints() const { return trimmedPoints; }
155 
158 
160 
164  const SGPoint getBndryDir(const int player,const int point) const;
165 
166  // Returns whether the action can be supported
167  bool supportable() const;
168 
169 }; // SGAction_MaxMinMax
170 
172 
173 bool operator==(const SGAction_MaxMinMax & lhs,
174  const SGAction_MaxMinMax & rhs);
175 
177 
180 bool operator<(const SGAction_MaxMinMax & lhs,
181  const SGAction_MaxMinMax & rhs);
182 
183 template class std::list<SGAction_MaxMinMax>;
184 /*template std::list<SGAction_MaxMinMax>::const_iterator;
185  template std::list<SGAction_MaxMinMax>::iterator; */
186 
187 typedef list<SGAction_MaxMinMax>::const_iterator SGActionIter;
188 
189 #endif
SGAction_MaxMinMax::SGAction_MaxMinMax
SGAction_MaxMinMax(const SGEnv &_env, int _numPlayers, int _state, int _action)
Constructor.
Definition: sgaction_maxminmax.hpp:81
SGAction_MaxMinMax::getBndryDir
const SGPoint getBndryDir(const int player, const int point) const
Get boundary direction for 3 players.
Definition: sgaction_maxminmax.cpp:145
SGAction_MaxMinMax::mergeDuplicatePoints
void mergeDuplicatePoints(const double tol)
Merges duplicates up to the given tolerance.
Definition: sgaction_maxminmax.cpp:457
SGAction_MaxMinMax::updateTrim
void updateTrim()
Sets points equal to the trimmed points.
Definition: sgaction_maxminmax.cpp:116
SGBaseAction::numPlayers
int numPlayers
Definition: sgbaseaction.hpp:41
SGAction_MaxMinMax::distToTrimmed
double distToTrimmed() const
Calculates the distance between points and trimmedPoints in the sup norm.
Definition: sgaction_maxminmax.cpp:127
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGAction_MaxMinMax::getTrimmedBndryDirs
const vector< SGTuple > & getTrimmedBndryDirs() const
Get method for trimmed points.
Definition: sgaction_maxminmax.hpp:157
SGAction_MaxMinMax::SGAction_MaxMinMax
SGAction_MaxMinMax(const SGEnv &_env, int _state, int _action)
Constructor.
Definition: sgaction_maxminmax.hpp:72
SGAction_MaxMinMax::env
const SGEnv * env
Definition: sgaction_maxminmax.hpp:47
SGBaseAction::state
int state
Definition: sgbaseaction.hpp:42
SGAction_MaxMinMax::calculateMinIC
void calculateMinIC(const SGGame &game, const vector< bool > &update, const SGTuple &threatTuple)
Calculates the minimum incentive compatible continuation payoff.
Definition: sgaction_maxminmax.cpp:385
SGAction_MaxMinMax::trimmedBndryDirs
vector< SGTuple > trimmedBndryDirs
Definition: sgaction_maxminmax.hpp:52
SGAction_MaxMinMax
Enhanced version of SGBaseAction.
Definition: sgaction_maxminmax.hpp:45
SGAction_MaxMinMax::trim
bool trim(const SGPoint &normal, double level)
Trims the trimmedPoints using intersectRaySegment.
Definition: sgaction_maxminmax.cpp:81
SGAction_MaxMinMax::calculateMinIC
void calculateMinIC(const SGGame &game, const SGTuple &threatTuple)
Calculates the minimum incentive compatible continuation payoff.
Definition: sgaction_maxminmax.hpp:139
SGAction_MaxMinMax::intersectHalfSpace
bool intersectHalfSpace(const SGPoint &normal, const double level, int player, SGTuple &segment, SGTuple &segmentDirs)
Intersects the segment with a half space.
Definition: sgaction_maxminmax.cpp:157
SGAction_MaxMinMax::trimmedPoints
vector< SGTuple > trimmedPoints
Definition: sgaction_maxminmax.hpp:50
SGEnv
Manages parameters for algorithm behavior.
Definition: sgenv.hpp:35
std::vector< SGTuple >
Definition: sgstl.cpp:27
SGAction_MaxMinMax::SGAction_MaxMinMax
SGAction_MaxMinMax()
Default constructor.
Definition: sgaction_maxminmax.hpp:58
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGAction_MaxMinMax::resetTrimmedPoints
void resetTrimmedPoints()
Resets the trimmed points for two players.
Definition: sgaction_maxminmax.cpp:28
SGBaseAction
Describes an action in the game.
Definition: sgbaseaction.hpp:39
SGTuple
Definition: sgtuple.hpp:52
SGAction_MaxMinMax::SGAction_MaxMinMax
SGAction_MaxMinMax(const SGEnv &_env)
Constructor.
Definition: sgaction_maxminmax.hpp:65
SGBaseAction::action
int action
Definition: sgbaseaction.hpp:43
SGAction_MaxMinMax::getTrimmedPoints
const vector< SGTuple > & getTrimmedPoints() const
Get method for trimmed points.
Definition: sgaction_maxminmax.hpp:154
SGAction_MaxMinMax::intersectPolygonHalfSpace
bool intersectPolygonHalfSpace(const SGPoint &normal, const double level, int player, SGTuple &extPnts, SGTuple &extPntDirs)
Intersects the IC polygon with a half space.
Definition: sgaction_maxminmax.cpp:227