SGSolve
sgsolution_maxminmax.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 _SGSOLUTION_MAXMINMAX_HPP
23 #define _SGSOLUTION_MAXMINMAX_HPP
24 
25 #include "sggame.hpp"
26 #include "sgiteration_maxminmax.hpp"
27 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/archive/binary_iarchive.hpp>
30 #include <boost/archive/binary_oarchive.hpp>
31 #include <boost/serialization/utility.hpp>
32 
34 
40 {
41 private:
47 public:
52  game(_game)
53  {}
54 
56  const SGGame & getGame() const { return game; }
59 
62  void clear() {iterations.clear(); }
64  void push_back(const SGIteration_MaxMinMax & iteration)
65  { iterations.push_back(iteration); }
66 
68  template<class Archive>
69  void serialize(Archive &ar, const unsigned int version)
70  {
71  ar & game & iterations;
72  }
73 
75  static void save(const SGSolution_MaxMinMax & soln, const char* filename)
76  {
77  std::ofstream ofs(filename,std::fstream::out);
78 
79  if (ofs.good())
80  {
81  boost::archive::binary_oarchive oa(ofs);
82  oa << soln;
83  }
84  else
86 
87  ofs.close();
88  }
89 
91  static void load(SGSolution_MaxMinMax & soln, const char* filename)
92  {
93  std::ifstream ifs(filename,std::fstream::in);
94  if (ifs.good() && ifs.is_open())
95  {
96  boost::archive::binary_iarchive ia(ifs);
97  ia >> soln;
98  }
99  else
101 
102  ifs.close();
103  }
104 
105  friend class boost::serialization::access;
106 }; // SGSolution_MaxMinMax
107 
108 #endif
SGSolution_MaxMinMax::getGame
const SGGame & getGame() const
Get method for the game.
Definition: sgsolution_maxminmax.hpp:56
SGSolution_MaxMinMax::game
SGGame game
Definition: sgsolution_maxminmax.hpp:42
SGSolution_MaxMinMax::SGSolution_MaxMinMax
SGSolution_MaxMinMax()
Default constructor.
Definition: sgsolution_maxminmax.hpp:49
SGSolution_MaxMinMax::SGSolution_MaxMinMax
SGSolution_MaxMinMax(const SGGame &_game)
Initializes an SGSolution_MaxMinMax object with a copy of the SGGame _game.
Definition: sgsolution_maxminmax.hpp:51
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SG::FAILED_OPEN
@ FAILED_OPEN
Definition: sgnamespace.hpp:32
SGException
SGSolve specific exceptions.
Definition: sgexception.hpp:36
SGSolution_MaxMinMax::clear
void clear()
Definition: sgsolution_maxminmax.hpp:62
SGSolution_MaxMinMax::load
static void load(SGSolution_MaxMinMax &soln, const char *filename)
Static method for loading an SGSolution_MaxMinMax object from the file filename.
Definition: sgsolution_maxminmax.hpp:91
SGSolution_MaxMinMax
Records the progress of SGSolver_MaxMinMax::solve().
Definition: sgsolution_maxminmax.hpp:40
SGSolution_MaxMinMax::iterations
list< SGIteration_MaxMinMax > iterations
Definition: sgsolution_maxminmax.hpp:43
std::list< SGIteration_MaxMinMax >
Definition: sgstl.cpp:34
SGSolution_MaxMinMax::getIterations
const list< SGIteration_MaxMinMax > & getIterations() const
Get method for the iterations.
Definition: sgsolution_maxminmax.hpp:58
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
SGSolution_MaxMinMax::serialize
void serialize(Archive &ar, const unsigned int version)
Serializes the SGSolution_MaxMinMax object using boost.
Definition: sgsolution_maxminmax.hpp:69
SGIteration_MaxMinMax
Stores data on the behavior of SGSolver_MaxMinMax.
Definition: sgiteration_maxminmax.hpp:38
SGSolution_MaxMinMax::push_back
void push_back(const SGIteration_MaxMinMax &iteration)
Adds a new iteration to the back of SGSolution_MaxMinMax::iterations.
Definition: sgsolution_maxminmax.hpp:64