SGSolve
sgrisksharing_3player_merged.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 _SGRISKSHARING_3PLAYER_MERGED_HPP
23 #define _SGRISKSHARING_3PLAYER_MERGED_HPP
24 
25 #include "sg.hpp"
26 
28 
32 {
33 private:
34  int numEndowments;
35  int c2e;
36  vector<double> E;
37  double eIncr;
38  double cIncr;
39  vector<int> numActions_total;
40  double probDenom;
41 
42  double consumption(int e, int t) const
43  {
44  assert(E[e]+t*cIncr>=-1e-6);
45  assert(E[e]+t*cIncr<=1+1e-6);
46  double cons = E[e]+t*cIncr;
47  if (cons < 0)
48  return 0;
49  if (cons > 1)
50  return 1;
51  return cons;
52  }
53 
54 public:
56  int _numEndowments,
57  int _c2e):
58  numEndowments(_numEndowments),
59  c2e(_c2e),
60  E(numEndowments,0),
61  numActions_total(_numEndowments,1),
63  _numEndowments,
64  vector< vector<int> > (_numEndowments,vector<int>(2,1)))
65  {
66  // // A couple of checks on the number of endowments
67  // assert( (numEndowments%2) == 1 );
68  // assert( numEndowments>2 );
69 
70  // Set up the endowment grid and the numbers of actions
71  for (int e = 0; e < numEndowments; e++)
72  {
73  E[e] = (1.0*e)/(numEndowments-1); // player 0's endowment
74 
75  numActions[e][0] = e*c2e+1;
76  numActions[e][1] = (numEndowments-e-1)*c2e+1;
77  numActions_total[e] = numActions[e][0]*numActions[e][1];
78  } // for e
79 
80  eIncr = (E[1]-E[0])/2.0;
81  cIncr = 1.0/( (numEndowments-1)*c2e );
82 
83  probDenom = 0.0;
84  for (int e = 0; e < numEndowments; e++)
85  probDenom += numEndowments-e;
86  } // constructor
87 
88  virtual SGPoint payoffs(int state, const vector<int> & actions) const
89  {
90  int t = actions[1]-actions[0]; // net transfer from 0 to 1
91  double c = consumption(state,t);
92 
93  return SGPoint(sqrt(c),2.0*sqrt((1-c)/2.0));
94  } // payoffs
95 
96  virtual double probability(int e, const vector<int> & actions, int ep) const
97  {
98  int t = actions[1]-actions[0];
99  int a = actions[0]+actions[1]*numActions[e][0];
100 
101  return (1.0*numEndowments-ep)/probDenom;
102  } // probability
103 
104  virtual bool isEquilibriumAction(int state, const vector<int> & actions) const
105  {
106  // Return true iff one of the players' actions is zero.
107  if ( (actions[0] == 0) || (actions[1] == 0) )
108  return true;
109  return false;
110  } // isEquilibriumAction
111 
112 };
113 
114 #endif
SGAbstractGame::numActions
vector< vector< int > > numActions
The numbers of actions in each state.
Definition: sgabstractgame.hpp:52
SGAbstractGame
A virtual class for constructing games.
Definition: sgabstractgame.hpp:41
SGPoint
A vector in .
Definition: sgpoint.hpp:35
RiskSharingGame_3Player_Merged::probability
virtual double probability(int e, const vector< int > &actions, int ep) const
Transition probabilities.
Definition: sgrisksharing_3player_merged.hpp:96
RiskSharingGame_3Player_Merged::payoffs
virtual SGPoint payoffs(int state, const vector< int > &actions) const
The payoff function.
Definition: sgrisksharing_3player_merged.hpp:88
RiskSharingGame_3Player_Merged
Two player version of the Kocherlakota (1996) risk sharing game.
Definition: sgrisksharing_3player_merged.hpp:32
RiskSharingGame_3Player_Merged::isEquilibriumAction
virtual bool isEquilibriumAction(int state, const vector< int > &actions) const
Definition: sgrisksharing_3player_merged.hpp:104
SGAbstractGame::SGAbstractGame
SGAbstractGame(int _numPlayers, double _delta, int _numStates, vector< vector< int > > _numActions)
Constructor for the pure virtual class.
Definition: sgabstractgame.hpp:70
SGAbstractGame::delta
double delta
The discount factor.
Definition: sgabstractgame.hpp:46