SGSolve
sgsolution_pencilsharpening.hpp
1 // This file is part of the SGSolve library for stochastic games
2 // Copyright (C) 2016 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_HPP
23 #define _SGSOLUTION_HPP
24 
25 #include "sggame.hpp"
26 #include "sgiteration_pencilsharpening.hpp"
27 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/serialization/utility.hpp>
30 
32 
41 {
42 private:
44  list<SGIteration_PencilSharpening> iterations;
50 public:
55  game(_game)
56  {}
57 
59  const SGGame & getGame() const { return game; }
61  const list<SGIteration_PencilSharpening> & getIterations() const { return iterations; }
63  const list<SGTuple> & getExtremeTuples() const { return extremeTuples; }
64 
67  void clear() {iterations.clear(); extremeTuples.clear();}
69  void push_back(const SGIteration_PencilSharpening & iteration)
70  { iterations.push_back(iteration); }
72  void push_back(const SGTuple & tuple)
73  { extremeTuples.push_back(tuple); }
75  void pop_back()
76  { extremeTuples.pop_back(); }
77 
79  template<class Archive>
80  void serialize(Archive &ar, const unsigned int version)
81  {
82  ar & game & iterations & extremeTuples;
83  }
84 
86  static void save(const SGSolution_PencilSharpening & soln, const char* filename)
87  {
88  std::ofstream ofs(filename,std::fstream::out);
89 
90  if (ofs.good())
91  {
92  boost::archive::text_oarchive oa(ofs);
93  oa << soln;
94  }
95  else
97  }
98 
100  static void load(SGSolution_PencilSharpening & soln, const char* filename)
101  {
102  std::ifstream ifs(filename,std::fstream::in);
103  if (ifs.good() && ifs.is_open())
104  {
105  boost::archive::text_iarchive ia(ifs);
106  ia >> soln;
107  }
108  else
110  }
111 
112  friend class boost::serialization::access;
113 }; // SGSolution
114 
115 #endif
SGSolution_PencilSharpening::save
static void save(const SGSolution_PencilSharpening &soln, const char *filename)
Static method for saving an SGSolution object to the file filename.
Definition: sgsolution_pencilsharpening.hpp:86
SGSolution_PencilSharpening::getExtremeTuples
const list< SGTuple > & getExtremeTuples() const
Get method for the extremeTuples.
Definition: sgsolution_pencilsharpening.hpp:63
SGSolution_PencilSharpening::getGame
const SGGame & getGame() const
Get method for the game.
Definition: sgsolution_pencilsharpening.hpp:59
SGSolution_PencilSharpening::load
static void load(SGSolution_PencilSharpening &soln, const char *filename)
Static method for loading an SGSolution object from the file filename.
Definition: sgsolution_pencilsharpening.hpp:100
SGSolution_PencilSharpening::iterations
list< SGIteration_PencilSharpening > iterations
Definition: sgsolution_pencilsharpening.hpp:44
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SG::FAILED_OPEN
@ FAILED_OPEN
Definition: sgnamespace.hpp:32
SGSolution_PencilSharpening::getIterations
const list< SGIteration_PencilSharpening > & getIterations() const
Get method for the iterations.
Definition: sgsolution_pencilsharpening.hpp:61
SGException
SGSolve specific exceptions.
Definition: sgexception.hpp:36
SGSolution_PencilSharpening
Records the progress of SGSolver::solve().
Definition: sgsolution_pencilsharpening.hpp:41
SGSolution_PencilSharpening::serialize
void serialize(Archive &ar, const unsigned int version)
Serializes the SGSolution object using boost.
Definition: sgsolution_pencilsharpening.hpp:80
SGSolution_PencilSharpening::extremeTuples
list< SGTuple > extremeTuples
Definition: sgsolution_pencilsharpening.hpp:47
SGSolution_PencilSharpening::SGSolution_PencilSharpening
SGSolution_PencilSharpening()
Default constructor.
Definition: sgsolution_pencilsharpening.hpp:52
SGSolution_PencilSharpening::clear
void clear()
Definition: sgsolution_pencilsharpening.hpp:67
SGSolution_PencilSharpening::pop_back
void pop_back()
Pops the last tuple off of SGSolution::extremeTuples.
Definition: sgsolution_pencilsharpening.hpp:75
SGSolution_PencilSharpening::SGSolution_PencilSharpening
SGSolution_PencilSharpening(const SGGame &_game)
Initializes an SGSolution object with a copy of the SGGame _game.
Definition: sgsolution_pencilsharpening.hpp:54
SGIteration_PencilSharpening
Stores data on the behavior of SGApprox::generate()
Definition: sgiteration_pencilsharpening.hpp:43
SGSolution_PencilSharpening::push_back
void push_back(const SGTuple &tuple)
Adds a new tuple to the back of SGSolution::extremeTuples.
Definition: sgsolution_pencilsharpening.hpp:72
std::list< SGTuple >
Definition: sgstl.cpp:32
SGSolution_PencilSharpening::game
SGGame game
Definition: sgsolution_pencilsharpening.hpp:43
SGTuple
Definition: sgtuple.hpp:52
SGSolution_PencilSharpening::push_back
void push_back(const SGIteration_PencilSharpening &iteration)
Adds a new iteration to the back of SGSolution::iterations.
Definition: sgsolution_pencilsharpening.hpp:69