SGSolve
risksharing_maxminmax.cpp
// This file is part of the SGSolve library for stochastic games
// Copyright (C) 2019 Benjamin A. Brooks
//
// SGSolve free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SGSolve is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//
// Benjamin A. Brooks
// ben@benjaminbrooks.net
// Chicago, IL
#include "sgrisksharing.hpp"
#include "sgsolver_pencilsharpening.hpp"
#include "sgsolver_jyc.hpp"
#include "sgsolver_maxminmax_grb.hpp"
#include "sgsolver_maxminmax.hpp"
#include <ctime>
void runModels(const int numEndowments,
const int c2e,
const double delta,
bool maxminmax,
bool maxminmaxfixed,
int jycnumdirs);
int main()
{
// Run the benchmarks reported in ABS (2019)
runModels(2,200,0.7,true,false,0);
runModels(2,200,0.4,true,false,0);
return 0;
// Max-min-max fixed and endogenous
runModels(2,20,0.7,true,false,0);
runModels(2,40,0.7,true,false,0);
runModels(5,20,0.7,true,false,0);
runModels(9,15,0.7,true,false,0);
return 0;
// JYC 100
runModels(2,20,0.7,false,false,100);
runModels(2,40,0.7,false,false,100);
runModels(5,20,0.7,false,false,100);
runModels(9,15,0.7,false,false,100);
// JYC 200
runModels(2,20,0.7,false,false,200);
runModels(2,40,0.7,false,false,200);
runModels(5,20,0.7,false,false,200);
runModels(9,15,0.7,false,false,200);
return 0;
} // main
void runModels(const int numEndowments,
const int c2e,
const double delta,
bool maxminmax,
bool maxminmaxfixed,
int jycnumdirs)
{
double persistence = 0;
RiskSharingGame::EndowmentMode endowmentMode = RiskSharingGame::Consumption;
RiskSharingGame rsg(delta,numEndowments,
c2e,persistence,endowmentMode);
SGEnv env;
// env.setParam(SG::MAXITERATIONS,20);
SGGame game(rsg);
clock_t start;
double duration;
cout << "numEndowments: " << numEndowments
<< ", c2e: " << c2e
<< ", delta: " << delta
<< endl;
if (maxminmaxfixed)
{
start = clock();
SGSolver_MaxMinMax solver4(env,game);
try
{
solver4.solve_fixed();
}
catch(std::exception & e)
{
cout << e.what() << endl;
}
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout << fixed << "Fixed direction time elapsed: "<< duration << " seconds" << endl;
SGSolution_MaxMinMax soln2 = solver4.getSolution();
SGSolution_MaxMinMax::save(soln2,"./solutions/risksharing_maxminmax_fixed.sln");
}
if (maxminmax)
{
start = clock();
SGSolver_MaxMinMax solver5(env,game);
solver5.solve();
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout << fixed << "Endogenous direction time elapsed: "<< duration << " seconds" << endl;
SGSolution_MaxMinMax soln3 = solver5.getSolution();
stringstream ss;
ss << "./solutions/risksharing_nume=" << numEndowments
<< "_c2e=" << c2e
<< "_delta=" << delta;
ss << "_sgf=" << env.getParam(SG::SUBGENFACTOR);
ss << ".sln";
SGSolution_MaxMinMax::save(soln3,ss.str().c_str());
}
if (jycnumdirs>0)
{
start = clock();
SGSolver_JYC jycsolver(game,jycnumdirs);
jycsolver.solve();
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout << "JYC implementation time elapsed with " << jycnumdirs
<< " directions: "<< duration << " seconds" << endl;
}
} // runModels
SG::STOREITERATIONS
@ STOREITERATIONS
Definition: sgnamespace.hpp:148
SGEnv::getParam
double getParam(SG::DBL_PARAM param) const
Method for getting double parameters.
Definition: sgenv.cpp:96
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGSolver_JYC
Class that implements the JYC algorithm using Gurobi.
Definition: sgsolver_jyc.hpp:43
SGSolver_MaxMinMax
Class for solving stochastic games.
Definition: sgsolver_maxminmax.hpp:43
SG::ERRORTOL
@ ERRORTOL
Definition: sgnamespace.hpp:69
SGSolution_MaxMinMax
Records the progress of SGSolver_MaxMinMax::solve().
Definition: sgsolution_maxminmax.hpp:40
SGEnv
Manages parameters for algorithm behavior.
Definition: sgenv.hpp:35
SGEnv::setParam
void setParam(SG::DBL_PARAM param, double value)
Method for setting double parameters.
Definition: sgenv.cpp:68
SG::SUBGENFACTOR
@ SUBGENFACTOR
Definition: sgnamespace.hpp:103
RiskSharingGame
Two player version of the Kocherlakota (1996) risk sharing game.
Definition: sgrisksharing.hpp:29
SGSolution_MaxMinMax::save
static void save(const SGSolution_MaxMinMax &soln, const char *filename)
Static method for saving an SGSolution_MaxMinMax object to the file filename.
Definition: sgsolution_maxminmax.hpp:75