BCESolve
bceabstractgame.hpp
1// This file is part of the BCESolve library for games of incomplete
2// information
3// Copyright (C) 2022 Benjamin A. Brooks
4//
5// BCESolve free software: you can redistribute it and/or modify it
6// under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// BCESolve is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see
17// <http://www.gnu.org/licenses/>.
18//
19// Benjamin A. Brooks
20// ben@benjaminbrooks.net
21// Chicago, IL
22
23
24#ifndef BCEABSTRACTGAME_HPP
25#define BCEABSTRACTGAME_HPP
26
27#include <sstream>
28#include "bcecommon.hpp"
29#include "bceexception.hpp"
30#include <boost/archive/text_iarchive.hpp>
31#include <boost/archive/text_oarchive.hpp>
32#include <boost/serialization/vector.hpp>
33
34
36
52{
53
59protected:
63 vector<int> numActions;
67 vector<int> numTypes;
70
72
76
80 vector<int> numPrivateStates;
82 vector<string> objectiveLabels;
83
84
85public:
89
91 BCEAbstractGame(int numStatesArg,
92 int numActionsArg,
93 int numTypesArg,
94 int numObjectivesArg);
96
98 BCEAbstractGame(int numStatesArg,
99 const vector<int> & numActionsArg,
100 const vector<int> & numTypesArg,
101 int numObjectivesArg);
102
105 {}
106
110 }
111
113
116 virtual double prior(int state, const vector<int> &types) const = 0;
117
119 double prior(const vector<int> & states, const vector<int> &types) const
120 {
122 && states[0] >= 0 && states[0] < numPrivateStates[0]
123 && states[1] >= 0 && states[1] < numPrivateStates[1])
124 return prior(states[0] + states[1]*numPrivateStates[0],types);
125 return -99;
126 }
127
129
135 double prior(int state, int type, int player) const; // marginal distribution
136
138
143 virtual double objective(int state, const vector<int> &actions,
144 int obj) const = 0;
145
147 double objective(const vector<int> &states,
148 const vector<int> &actions,
149 int obj) const
150 {
152 && states[0] >= 0 && states[0] < numPrivateStates[0]
153 && states[1] >= 0 && states[1] < numPrivateStates[1])
154 return objective(states[0] + states[1]*numPrivateStates[0],
155 actions,obj);
156 return -99;
157 }
158
160
164 virtual bool dominated(int action, int type, int player) const
165 {return false;};
166
168
171 bool dominated(const vector<int> &actions, const vector<int> &types) const;
172
174
178 virtual bool feasibleDeviation(int action, int dev,
179 int type, int player) const
180 {return true;};
181
184
187 bool setNumPrivateStates(const vector<int> & _numPrivateStates)
188 {
189 if (_numPrivateStates.size()!=numPlayers)
191
192 if (_numPrivateStates[0] == 0
193 && _numPrivateStates[1] == 0)
194 {
195 numPrivateStates = _numPrivateStates;
197 return true;
198 }
199
200 int player, product=1;
201 for (player=0; player<numPlayers; player++)
202 product*=_numPrivateStates[player];
203 if (product!=numStates)
204 return false;
205
206 numPrivateStates = _numPrivateStates;
208
209 return true;
210 }
211
213 string getObjLabels(int obj) {
214 return objectiveLabels[obj];
215 }
216
218 vector<string>& getObjLabels() {
219 return objectiveLabels;
220 }
221
223 void setObjLabel(int obj,string label) {
224 objectiveLabels[obj] = label;
225 }
226
228
230 void findLabelRedundancies(int obj);
231
233
236 void nameEmptyLabels();
237
240
242 const vector<int> & getNumPrivateStates () const { return numPrivateStates; }
243
245 int getNumObjectives() const { return numObjectives; }
247 int getNumStates() const { return numStates; }
249 const vector<int> & getNumActions() const { return numActions; }
251 const vector<int> & getNumTypes() const { return numTypes; }
253 int getNumPlayers() const { return numPlayers; }
254
255};
256
257#endif
The base class for games of incomplete information.
Definition: bceabstractgame.hpp:52
int numObjectives
The number of objective functions. Must be >= 2.
Definition: bceabstractgame.hpp:69
bool hasProductStructure() const
Returns whether or not the state has a product structure.
Definition: bceabstractgame.hpp:239
virtual bool feasibleDeviation(int action, int dev, int type, int player) const
Check if deviation is feasible.
Definition: bceabstractgame.hpp:178
virtual bool dominated(int action, int type, int player) const
Indicates if a combination of actions and types is dominated.
Definition: bceabstractgame.hpp:164
bool setNumPrivateStates(const vector< int > &_numPrivateStates)
Definition: bceabstractgame.hpp:187
double objective(const vector< int > &states, const vector< int > &actions, int obj) const
Overloaded objective if the game has a product structure.
Definition: bceabstractgame.hpp:147
int getNumObjectives() const
Returns the number of objectives.
Definition: bceabstractgame.hpp:245
const vector< int > & getNumPrivateStates() const
Returns the numbers of private states.
Definition: bceabstractgame.hpp:242
vector< int > numTypes
The number of private types for each player.
Definition: bceabstractgame.hpp:67
int numStates
The number of payoff relevant states.
Definition: bceabstractgame.hpp:65
virtual double objective(int state, const vector< int > &actions, int obj) const =0
Objective function.
vector< int > numActions
The number of action profiles for each player.
Definition: bceabstractgame.hpp:63
string getObjLabels(int obj)
Gets an entry from objective label vector.
Definition: bceabstractgame.hpp:213
int numPlayers
The number of players, always 2.
Definition: bceabstractgame.hpp:61
vector< string > & getObjLabels()
Gets all of the objective labels.
Definition: bceabstractgame.hpp:218
const vector< int > & getNumActions() const
Returns a vector of the numbers of actions.
Definition: bceabstractgame.hpp:249
const vector< int > & getNumTypes() const
Returns a vector of the numbers of types.
Definition: bceabstractgame.hpp:251
double prior(const vector< int > &states, const vector< int > &types) const
Overloaded prior if the game has a product structure.
Definition: bceabstractgame.hpp:119
void findLabelRedundancies(int obj)
Finds if a specific label matches any existing labels.
Definition: bceabstractgame.cpp:178
bool hasProductStructureData
Indicates if the state has a product structure.
Definition: bceabstractgame.hpp:74
int getNumPlayers() const
Returns the number of players (always 2)
Definition: bceabstractgame.hpp:253
void setHasProductStructureData(bool hasProductStructure)
Allows user to specify if the game has a product structure.
Definition: bceabstractgame.hpp:108
void setObjLabel(int obj, string label)
Sets a label in the objectiveLabels vector.
Definition: bceabstractgame.hpp:223
vector< int > numPrivateStates
Number of states for each player.
Definition: bceabstractgame.hpp:80
vector< string > objectiveLabels
Labels for the objectives.
Definition: bceabstractgame.hpp:82
void nameEmptyLabels()
Names objectives according to defaults if given label is empty.
Definition: bceabstractgame.cpp:150
~BCEAbstractGame()
Destructor.
Definition: bceabstractgame.hpp:104
int getNumStates() const
Returns the number of states.
Definition: bceabstractgame.hpp:247
virtual double prior(int state, const vector< int > &types) const =0
Prior over state and types.
BCEAbstractGame()
Default constructor.
Definition: bceabstractgame.cpp:25
Exception class for BCESolve.
Definition: bceexception.hpp:33
@ BadArgument
Definition: bceexception.hpp:51