BCESolve
bcesolution.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#ifndef BCESOLUTION_HPP
24#define BCESOLUTION_HPP
25
26#include "bcecommon.hpp"
27#include "bcegame.hpp"
28#include "bceexception.hpp"
29#include "bcequilibrium.hpp"
30#include "bcecounter.hpp"
31
32#include <boost/serialization/list.hpp>
33#include <boost/serialization/vector.hpp>
34#include <boost/serialization/map.hpp>
35#include <boost/archive/text_iarchive.hpp>
36#include <boost/archive/text_oarchive.hpp>
37#include <boost/archive/binary_iarchive.hpp>
38#include <boost/archive/binary_oarchive.hpp>
39#include <boost/serialization/utility.hpp>
40
42
64{
65private:
69 list<BCEquilibrium> newEquilibria;
71 vector<BCEquilibrium> equilibria;
75
79 vector<vector<double> > mapBoundaryWeights;
81 vector<double> mainObjectiveWeights;
84
85public:
87 template <class Archive>
88 void serialize(Archive& ar, const unsigned int version)
89 {
90 ar & newEquilibria;
91 ar & equilibria;
92 ar & game;
95 ar & boundaryMapped;
97 }
98
101 boundaryMapped(false),
102 mapBoundaryWeights(2,vector<double>(2,0)),
104 {}
105
107
109 BCESolution (const BCEGame & game);
110
113
114 /* Managing the equilibria. */
116 void addEquilibrium(const map<int,double> & distr);
118 void clearEquilibria();
120 void setBoundaryMapped(const bool isMapped)
121 { boundaryMapped = isMapped; }
123 void setMapBoundaryWeights(const vector<vector<double> >& weights)
124 { mapBoundaryWeights = weights; }
126 void setMainObjectiveWeights(const vector<double>& weights) {
127 mainObjectiveWeights = weights;
128 }
130
134 const BCEGame & getGame() const { return game; }
135
136
138 const BCEquilibrium & getEquilibrium(int equilibriumIndex) const;
140
142 void setCurrentEquilibrium(int equilibriumIndex);
143
145 BCESolution& operator=(const BCESolution &rhs);
146
147 /* Statistical routines */
149
151 void getExpectedObjectives(vector<double> &objectiveValues) const;
153
158 void getExpectedObjectives(vector< vector<double> > &objectiveValues) const;
160 void getExpectedObjectives(vector<double> &objectiveValues,
161 const map<int,double> &distribution) const;
162
164
167 double getDeviationObjectives(int player, int action, int type,
168 vector< vector<double> > & objectiveValues) const;
169
171
179 double getConditionalMarginal(const vector<int> &stateConditions,
180 const vector< vector<int> > &actionConditions,
181 const vector< vector<int> > &typeConditions,
182 bool stateMarginal,
183 const vector<bool> &actionMarginal,
184 const vector<bool> &typeMarginal,
185 vector<double> &distribution) const;
186
188 const vector<vector<double> >& getMapBoundaryWeights() const {
189 return mapBoundaryWeights;
190 }
191
193 const vector<double> getMainObjectiveWeights() const {
195 }
196
197 const bool getIsBoundaryMapped() const {
198 return boundaryMapped;
199 }
200
202 static void save(const BCESolution & data, const char* filename)
203 {
204 ofstream ofs(filename);
205
206 if (ofs.good())
207 {
208 boost::archive::text_oarchive oa(ofs);
209 oa << data;
210 ofs.close();
211 }
212 else
214
215 }
216
218 static void load(BCESolution & data, const char* filename)
219 {
220 ifstream ifs(filename);
221
222 if (ifs.good())
223 {
224 boost::archive::text_iarchive ia(ifs);
225 ia >> data;
226 ifs.close();
227 }
228 else
230
231 }
232
233 friend class boost::serialization::access;
234}; // BCESolution
235
236#endif
Exception class for BCESolve.
Definition: bceexception.hpp:33
@ FailedOpen
Definition: bceexception.hpp:46
The base class for games of incomplete information.
Definition: bcegame.hpp:40
Class for storing data produced by BCESolver.
Definition: bcesolution.hpp:64
void getExpectedObjectives(vector< double > &objectiveValues) const
Gets the expected objectives under the current BCE.
Definition: bcesolution.cpp:97
const vector< vector< double > > & getMapBoundaryWeights() const
Returns the mapBoundary weights.
Definition: bcesolution.hpp:188
static void load(BCESolution &data, const char *filename)
Deserialize a BCESolution object using Boost.
Definition: bcesolution.hpp:218
void clearEquilibria()
Clears all equilibria.
Definition: bcesolution.cpp:32
void consolidateEquilibria()
Consolidates equilibria.
Definition: bcesolution.cpp:44
vector< vector< double > > mapBoundaryWeights
Matrix of weights on mapBoundary objectives.
Definition: bcesolution.hpp:79
const vector< double > getMainObjectiveWeights() const
Returns the main objective weights.
Definition: bcesolution.hpp:193
BCESolution()
Default constructor.
Definition: bcesolution.hpp:100
vector< double > mainObjectiveWeights
Vector of weights on the main objective.
Definition: bcesolution.hpp:81
BCESolution & operator=(const BCESolution &rhs)
Assignment operator.
Definition: bcesolution.cpp:82
void addEquilibrium(const map< int, double > &distr)
Appends distr to the end of the list newEquilibria.
Definition: bcesolution.cpp:38
bool boundaryMapped
True if boundary was mapped in the solver.
Definition: bcesolution.hpp:83
~BCESolution()
Destructor.
Definition: bcesolution.hpp:112
double getDeviationObjectives(int player, int action, int type, vector< vector< double > > &objectiveValues) const
Calculates deviation objectives.
Definition: bcesolution.cpp:169
void setBoundaryMapped(const bool isMapped)
Sets boundaryMapped status.
Definition: bcesolution.hpp:120
void serialize(Archive &ar, const unsigned int version)
Serialization routine.
Definition: bcesolution.hpp:88
void setCurrentEquilibrium(int equilibriumIndex)
Set current equilibrium.
Definition: bcesolution.cpp:69
void setMapBoundaryWeights(const vector< vector< double > > &weights)
Sets mapBoundaryWeights.
Definition: bcesolution.hpp:123
const BCEGame & getGame() const
Returns the game.
Definition: bcesolution.hpp:134
BCEGame game
The game that the equilibria correspond to.
Definition: bcesolution.hpp:67
list< BCEquilibrium > newEquilibria
List of new equilibria that have not yet been consolidated.
Definition: bcesolution.hpp:69
vector< BCEquilibrium > equilibria
Consolidated vector of equilibria.
Definition: bcesolution.hpp:71
int currentEquilibrium
Index of the current equilibrium in BCESolution::equilibria.
Definition: bcesolution.hpp:73
const BCEquilibrium & getEquilibrium(int equilibriumIndex) const
Returns the equilibrium at equilibriumIndex.
Definition: bcesolution.cpp:58
static void save(const BCESolution &data, const char *filename)
Serialize a BCESolution object using Boost.
Definition: bcesolution.hpp:202
void setMainObjectiveWeights(const vector< double > &weights)
Sets main objective weights.
Definition: bcesolution.hpp:126
double getConditionalMarginal(const vector< int > &stateConditions, const vector< vector< int > > &actionConditions, const vector< vector< int > > &typeConditions, bool stateMarginal, const vector< bool > &actionMarginal, const vector< bool > &typeMarginal, vector< double > &distribution) const
Computes the marginal conditional distribution of a BCE.
Definition: bcesolution.cpp:261
Class for storing a BCE.
Definition: bcequilibrium.hpp:44