BCESolve
bcesolver.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 BCESOLVER_HPP
24#define BCESOLVER_HPP
25
26#include "bcecommon.hpp"
27#include "bcegame.hpp"
28#include "bcesolution.hpp"
29#include "bcecounter.hpp"
30#include "bceexception.hpp"
31#include "bceutilities.hpp"
32#include "gurobi_c++.h"
33
35
47{
48public:
49
51
55 {
60 };
62
66 {
70
79 };
80
82
87 {
88 };
89
91 void setMinAngleIncr(double incr) {
92 minAngleIncrement = incr;
93 }
94
95protected:
98
100 long int numColumns;
102 long int numRows;
105
109 long int numTypes_total;
114
115 // Stores the # of IC constraints for each player.
117 vector<int> numICConstraints;
124
125 // Gurobi components
126
127 GRBEnv env;
129 GRBLinExpr gurobiObjective;
130
132 GRBVar* variables;
134 vector<GRBLinExpr> constraints;
135
136 // We allow the user to define any number of objective functions.
137 // These are all stored in an array obfun. The index of the current
138 // objective is currentobfun.
140
142 vector<GRBLinExpr> objectiveFunctions;
143
146
148
154
158
161
163
169
172
173 // Lists for storing equilibria and boundary points.
175
177 list<double> boundaryXs;
179
182 list<double> boundaryYs;
185
188 void countActionsTypes();
189
190 // Helper functions. These functions map between a linear index i
191 // and valuations, types, and states. Mostly deprecated because of
192 // use of BCECounter class.
193 void indexToTypeActionDeviation(int index, int player, int &type, int &action, int &deviation);
194
195public:
197
198 BCESolver();
199
201
203 BCESolver(BCEAbstractGame & _game);
204
206 GRBModel model;
207
210 { delete[] variables; }
211
212 // Main routines
213
215
217 void populate();
218
220
221 void solve(vector<double>& objectiveWeights);
222
224
228 void mapBoundary(const char * fname);
229
231
233 void mapBoundary();
234
236
238 void mapBoundary(const char * fname,
239 const vector<vector<double> >& weights);
240
242
245 void mapBoundary(const vector<vector<double> >& weights);
246
248
249 void getSolution(BCESolution & output);
250
252
255 void bceToMap(map<int,double> & distribution);
256
257 // Get methods
259 GRBModel& getModel() { return model; }
261 const GRBLinExpr& getObjectiveFunction (int n) const { return objectiveFunctions[n]; }
263 GRBLinExpr& getObjective() { return gurobiObjective; }
264
265 // Clear
267 void clear();
268
269 // Set methods
278
279 // get methods
286
287 // Can't believe this doesn't exist in ANSI C++
289 static int pow(int base, int exponent)
290 {
291 int result=1;
292 for (int exponentCounter=0; exponentCounter<exponent; exponentCounter++)
293 result*=base;
294 return result;
295 }
296};
297
298#endif
The base class for games of incomplete information.
Definition: bceabstractgame.hpp:52
Class for storing data produced by BCESolver.
Definition: bcesolution.hpp:64
Solves a BCEAbstractGame using gurobi.
Definition: bcesolver.hpp:47
void clear()
Clears the BCESolver.
Definition: bcesolver.cpp:77
GRBLinExpr & getObjective()
Returns the objective for BCESolver::model.
Definition: bcesolver.hpp:263
list< int > nonZeroVariableLocations
List of indices of non-zero variables.
Definition: bcesolver.hpp:152
list< double > boundaryYs
Y coordinates of frontier.
Definition: bcesolver.hpp:182
void countActionsTypes()
Definition: bcesolver.cpp:57
double getParameter(BCESolver::DoubleParameter)
Get double parameter.
Definition: bcesolver.cpp:127
void setObfun(int n)
Set objective function.
Definition: bcesolver.hpp:277
GRBModel model
The GUROBI model.
Definition: bcesolver.hpp:206
BCESolution soln
BCESolution object for serializing output of the algorithm.
Definition: bcesolver.hpp:184
long int numColumns
Number of columns in the constraint matrix.
Definition: bcesolver.hpp:100
long int numProbabilityVariables
The number of probability variables.
Definition: bcesolver.hpp:121
int displayLevel
The display level.
Definition: bcesolver.hpp:171
void populate()
Main populate routine.
Definition: bcesolver.cpp:163
long int numICConstraints_total
The total number of IC constraints.
Definition: bcesolver.hpp:119
void mapBoundary()
Maps the frontier.
Definition: bcesolver.cpp:513
long int numProbabilityConstraints
The total number of constraints on probabilities.
Definition: bcesolver.hpp:123
vector< int > probabilityConstraintLocations
Locations of probability constraints.
Definition: bcesolver.hpp:156
const GRBLinExpr & getObjectiveFunction(int n) const
Returns the th objective function.
Definition: bcesolver.hpp:261
double minAngleIncrement
Minimum angle increment when mapping boundary.
Definition: bcesolver.hpp:165
static int pow(int base, int exponent)
returns .
Definition: bcesolver.hpp:289
DoubleParameter
Double parameters.
Definition: bcesolver.hpp:55
@ MinAngleIncrement
Definition: bcesolver.hpp:59
long int numActionsTypesPerPlayer_total
Total number of of actions and types for each player. Used?
Definition: bcesolver.hpp:111
IntParameter
Integer parameters.
Definition: bcesolver.hpp:66
@ BoundaryObjective1
The first objective used when mapping the boundary.
Definition: bcesolver.hpp:76
@ BoundaryObjective2
The second objective used when mapping the boundary.
Definition: bcesolver.hpp:78
@ DisplayLevel
Control algorithm output.
Definition: bcesolver.hpp:74
@ CurrentObjective
The index of the current objective. Not currently used?
Definition: bcesolver.hpp:68
BCEAbstractGame * game
Pointer to the BCEAbstractGame object that is being solved.
Definition: bcesolver.hpp:97
BCESolver()
Default constructor.
Definition: bcesolver.cpp:25
long int numRows
Number of rows in the constraint matrix.
Definition: bcesolver.hpp:102
long int numNonBasicVariables
Number of non-basic variables?
Definition: bcesolver.hpp:104
void solve(vector< double > &objectiveWeights)
Solve method.
Definition: bcesolver.cpp:474
BoolParameter
Bool parameters.
Definition: bcesolver.hpp:87
map< int, int > variableLocationsMap
Map from variable indices to non-zero variable locations.
Definition: bcesolver.hpp:160
void setParameter(BCESolver::DoubleParameter, double arg)
Set double parameter.
Definition: bcesolver.cpp:82
void getSolution(BCESolution &output)
Returns the data object.
Definition: bcesolver.cpp:700
GRBVar * variables
The variables for BCESolver::model.
Definition: bcesolver.hpp:132
list< double > boundaryXs
X coordinates of frontier.
Definition: bcesolver.hpp:177
void bceToMap(map< int, double > &distribution)
Copies the BCE to a map.
Definition: bcesolver.cpp:705
void setMinAngleIncr(double incr)
Used to set the minimum angle increment. Called by bcesolverworker.hpp.
Definition: bcesolver.hpp:91
GRBModel & getModel()
Returns the BCESolver::model object.
Definition: bcesolver.hpp:259
long int numActionsTypes_total
Total number of actions and types.
Definition: bcesolver.hpp:113
int currentObjective
Index of the current objective. Not currently being used.
Definition: bcesolver.hpp:167
vector< GRBLinExpr > objectiveFunctions
Objectives.
Definition: bcesolver.hpp:142
long int numActions_total
Total number of action profiles for the players.
Definition: bcesolver.hpp:107
vector< int > numICConstraints
The number of IC constraints for each player.
Definition: bcesolver.hpp:117
~BCESolver()
Destructor.
Definition: bcesolver.hpp:209
bool isPopulated
Indicates if solver has been populated yet.
Definition: bcesolver.hpp:145
vector< GRBLinExpr > constraints
The constraints for BCESolver::model.
Definition: bcesolver.hpp:134
long int numTypes_total
Total number of types for the players.
Definition: bcesolver.hpp:109
GRBLinExpr gurobiObjective
The objective for BCESolver::model.
Definition: bcesolver.hpp:129