SGSolve
sgstep.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 _SGSTEP_HPP
23 #define _SGSTEP_HPP
24 
25 #include "sgaction_maxminmax.hpp"
26 #include "sghyperplane.hpp"
27 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/serialization/utility.hpp>
30 
32 
35 class SGStep
36 {
37 private:
41  vector<int> actionTuple;
45  vector<SG::Regime> regimeTuple;
46 public:
47  SGStep ()
48  {} // default constructor
49 
51  SGStep(const vector< list<SGAction_MaxMinMax>::const_iterator > & _actionTuple,
52  const vector<SG::Regime> & _regimeTuple,
53  const SGTuple & _pivot,
54  const SGHyperplane & _hyperplane,
55  const vector< list<SGAction_MaxMinMax> > & actions):
56  actionTuple (_actionTuple.size(),0),
57  regimeTuple{_regimeTuple},
58  pivot{_pivot},
59  hyperplane{_hyperplane}
60  {
61  for (int state = 0; state < _actionTuple.size(); state++)
62  {
63  // Find the element of the actions array that corresponds to
64  // the optimal action
65  auto action = actions[state].cbegin();
66  while (action->getAction() != _actionTuple[state]->getAction()
67  && action != actions[state].cend() )
68  {
69  actionTuple[state]++;
70  ++action;
71  }
72  }
73  } // Constructor
74 
75  // Get method for the pivot
76  const SGTuple & getPivot() const {return pivot;}
77  // Get method for the action tuple
78  const vector<int> & getActionTuple() const {return actionTuple;}
79  // Get method for the regimeTuple
80  const vector<SG::Regime> & getRegimeTuple() const {return regimeTuple;}
81  // Get method for the hyperplane
82  const SGHyperplane & getHyperplane() const {return hyperplane;}
83 
86 
88  template<class Archive>
89  void serialize(Archive &ar, const unsigned int version)
90  {
91  ar & pivot;
92  ar & hyperplane;
93  ar & actionTuple;
94  ar & regimeTuple;
95  }
96 
97 }; // SGStep
98 
99 #endif
SGStep::access
friend class boost::serialization::access
Serializes the SGStep object using boost.
Definition: sgstep.hpp:85
SGStep::regimeTuple
vector< SG::Regime > regimeTuple
Definition: sgstep.hpp:45
SGStep::pivot
SGTuple pivot
Definition: sgstep.hpp:38
SGStep
A single step of the max-min-max algorithm.
Definition: sgstep.hpp:36
SGStep::SGStep
SGStep(const vector< list< SGAction_MaxMinMax >::const_iterator > &_actionTuple, const vector< SG::Regime > &_regimeTuple, const SGTuple &_pivot, const SGHyperplane &_hyperplane, const vector< list< SGAction_MaxMinMax > > &actions)
Constructor.
Definition: sgstep.hpp:51
SGHyperplane
Represents a hyperplane in .
Definition: sghyperplane.hpp:39
SGStep::hyperplane
SGHyperplane hyperplane
Definition: sgstep.hpp:39
SGStep::serialize
void serialize(Archive &ar, const unsigned int version)
Serialize the iteration using Boost.
Definition: sgstep.hpp:89
SGStep::actionTuple
vector< int > actionTuple
Definition: sgstep.hpp:41
SGTuple
Definition: sgtuple.hpp:52