SGSolve
sgcontribution.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 _SGCONTRIBUTION_HPP
23 #define _SGCONTRIBUTION_HPP
24 
25 #include "sg.hpp"
26 
28 
31 {
32 public:
33  ContributionGame(int _numPlayers,
34  double _delta,
35  int _numStates):
36  SGAbstractGame(_numPlayers,
37  _delta,
38  _numStates,
39  vector< vector<int> >(_numStates,vector<int>(_numPlayers,2)))
40  {}
41 
42  virtual SGPoint payoffs(int state, const vector<int> & actions) const
43  {
44  SGPoint point(numPlayers,0.0);
45 
46  double actionSum = 0.0;
47  for (int p=0; p < numPlayers; p++)
48  actionSum += actions[p];
49 
50  // Payoff is 2*sum a_j - 3* a_i + 20*state.
51  for (int p=0; p < numPlayers; p++)
52  point[p] = 2.0*actionSum - 3.0*actions[p]
53  + 20.0*static_cast<double>(state)/(static_cast<double>(numStates)-1.0);
54 
55  return point;
56  } // payoffs
57 
58  virtual double probability(int state, const vector<int> & actions, int statep) const
59  {
60  return 1.0/static_cast<double>(numStates);
61  } // probability
62 
63 
64 }; // PD_TwoState_3Player
65 
66 
67 #endif
SGAbstractGame::numPlayers
int numPlayers
The number of players, always 2.
Definition: sgabstractgame.hpp:44
ContributionGame::probability
virtual double probability(int state, const vector< int > &actions, int statep) const
Transition probabilities.
Definition: sgcontribution.hpp:58
SGAbstractGame::numStates
int numStates
The number of states.
Definition: sgabstractgame.hpp:48
ContributionGame::payoffs
virtual SGPoint payoffs(int state, const vector< int > &actions) const
The payoff function.
Definition: sgcontribution.hpp:42
SGAbstractGame
A virtual class for constructing games.
Definition: sgabstractgame.hpp:41
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGAbstractGame::SGAbstractGame
SGAbstractGame(int _numPlayers, double _delta, int _numStates, vector< vector< int > > _numActions)
Constructor for the pure virtual class.
Definition: sgabstractgame.hpp:70
ContributionGame
N-player prisoners' contribution game.
Definition: sgcontribution.hpp:31