SGSolve
sgbaseaction.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 _SGBASEACTION_HPP
24 #define _SGBASEACTION_HPP
25 
26 #include "sgcommon.hpp"
27 #include "sgtuple.hpp"
28 #include "sgnamespace.hpp"
29 
31 
39 {
40 protected:
41  int numPlayers;
42  int state;
43  int action;
66  vector< vector< int > > tuples;
73  bool isNull;
76  bool corner;
80 public:
82 
84  numPlayers(2),
85  isNull(true),
86  action(-1),
87  state(-1)
88  {}
89 
91 
92  SGBaseAction(int _state, int _action):
93  SGBaseAction(2,_state,_action)
94  { }
95 
97 
99  SGBaseAction(int _numPlayers,
100  int _state,
101  int _action):
102  numPlayers(_numPlayers),
103  state(_state),
104  action(_action),
105  minIC(_numPlayers,-numeric_limits<double>::max()),
107  bndryDirs(_numPlayers,SGTuple(2)),
108  isNull(false),
109  corner(false)
110  {
111  tuples.resize(numPlayers);
112  }
113 
116 
118  bool getIsNull() const {return isNull;}
120  int getAction() const { return action; }
122  const vector<SGTuple> & getPoints() const { return points; }
124  const vector<SGTuple> & getBndryDirs() const { return bndryDirs; }
126  const vector< vector<int> > & getTuples() const { return tuples; }
128  int getState() const { return state; }
130  bool hasCorner() const { return corner; }
132  const SGPoint & getMinICPayoffs() const {return minIC;}
134  const vector<SGTuple> & getBindingContinuations() const { return points; }
135 
137  void setMinICPayoffs(const SGPoint & newMinIC)
138  {
139  minIC = newMinIC;
140  } // setMinIC
142  void setTuples(const vector< vector<int> > & newTuples)
143  {
144  assert(newTuples.size()<=numPlayers);
145  tuples = newTuples;
146  } // setTuples
148  void setPoints(const vector<SGTuple> & newPoints)
149  {
150  assert(newPoints.size()<=numPlayers);
151  points = newPoints;
152  } // setPoints
154  void setPointsAndTuples(const vector<SGTuple> & newPoints,
155  const vector< vector<int> > & newTuples)
156  {
157  assert(newPoints.size() <= numPlayers);
158  assert(newPoints.size() == newTuples.size());
159  points = newPoints;
160  tuples = newTuples;
161  } // setPointsAndTuples
163 
165  void setCorner(bool tf)
166  {
167  corner=tf;
168  }
169 
171  bool isCorner(const int p, const int k) const;
172 
174  template<class Archive>
175  void serialize(Archive &ar, const unsigned int version)
176  {
177  ar & numPlayers;
178  ar & state;
179  ar & action;
180  ar & minIC;
181  ar & points;
182  ar & tuples;
183  ar & bndryDirs;
184  ar & isNull;
185  ar & corner;
186  } // serialize
187 
188  friend class boost::serialization::access;
189 }; // SGBaseAction
190 
191 
192 #endif
SGBaseAction::isCorner
bool isCorner(const int p, const int k) const
Returns whether or not the minimum IC payoff is feasible.
Definition: sgbaseaction.cpp:24
SGBaseAction::numPlayers
int numPlayers
Definition: sgbaseaction.hpp:41
SGBaseAction::getState
int getState() const
Returns the state.
Definition: sgbaseaction.hpp:128
SGBaseAction::SGBaseAction
SGBaseAction(int _numPlayers, int _state, int _action)
Constructor.
Definition: sgbaseaction.hpp:99
SGBaseAction::setPointsAndTuples
void setPointsAndTuples(const vector< SGTuple > &newPoints, const vector< vector< int > > &newTuples)
Sets the points and tuples arrays.
Definition: sgbaseaction.hpp:154
SGBaseAction::isNull
bool isNull
Definition: sgbaseaction.hpp:73
SGBaseAction::hasCorner
bool hasCorner() const
Returns whether or not the action has a corner.
Definition: sgbaseaction.hpp:130
SGBaseAction::corner
bool corner
Definition: sgbaseaction.hpp:76
SGBaseAction::serialize
void serialize(Archive &ar, const unsigned int version)
Serializes the action using the boost::serialization library.
Definition: sgbaseaction.hpp:175
SGBaseAction::state
int state
Definition: sgbaseaction.hpp:42
SGBaseAction::setMinICPayoffs
void setMinICPayoffs(const SGPoint &newMinIC)
Sets the minimum IC continuation values.
Definition: sgbaseaction.hpp:137
SGBaseAction::getBndryDirs
const vector< SGTuple > & getBndryDirs() const
Get method for bndry dirs.
Definition: sgbaseaction.hpp:124
SGBaseAction::SGBaseAction
SGBaseAction()
Constructor.
Definition: sgbaseaction.hpp:83
SGBaseAction::points
vector< SGTuple > points
Definition: sgbaseaction.hpp:50
SGBaseAction::SGBaseAction
SGBaseAction(int _state, int _action)
Constructor.
Definition: sgbaseaction.hpp:92
SGBaseAction::setCorner
void setCorner(bool tf)
Sets the corner indicator.
Definition: sgbaseaction.hpp:165
SGBaseAction::setPoints
void setPoints(const vector< SGTuple > &newPoints)
Sets the points array
Definition: sgbaseaction.hpp:148
std::vector< SGTuple >
Definition: sgstl.cpp:27
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGBaseAction::getBindingContinuations
const vector< SGTuple > & getBindingContinuations() const
Returns the array of binding continuation values.
Definition: sgbaseaction.hpp:134
SGBaseAction::bndryDirs
vector< SGTuple > bndryDirs
Definition: sgbaseaction.hpp:62
SGBaseAction::~SGBaseAction
~SGBaseAction()
Destructor.
Definition: sgbaseaction.hpp:115
SGBaseAction::minIC
SGPoint minIC
Definition: sgbaseaction.hpp:44
SGBaseAction::tuples
vector< vector< int > > tuples
Definition: sgbaseaction.hpp:66
SGBaseAction::setTuples
void setTuples(const vector< vector< int > > &newTuples)
Sets the tuples array.
Definition: sgbaseaction.hpp:142
SGBaseAction::getMinICPayoffs
const SGPoint & getMinICPayoffs() const
Returns the minimum IC continuation values.
Definition: sgbaseaction.hpp:132
SGBaseAction::getAction
int getAction() const
Returns the action.
Definition: sgbaseaction.hpp:120
SGBaseAction::getTuples
const vector< vector< int > > & getTuples() const
Returns the tuples array.
Definition: sgbaseaction.hpp:126
SGBaseAction
Describes an action in the game.
Definition: sgbaseaction.hpp:39
SGTuple
Definition: sgtuple.hpp:52
SGBaseAction::action
int action
Definition: sgbaseaction.hpp:43
SGBaseAction::getIsNull
bool getIsNull() const
Returns true if the action is null.
Definition: sgbaseaction.hpp:118
SGBaseAction::getPoints
const vector< SGTuple > & getPoints() const
Returns the points array.
Definition: sgbaseaction.hpp:122