SGSolve
sgiteration_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 _SGITERATION_MAXMINMAX_HPP
23 #define _SGITERATION_MAXMINMAX_HPP
24 
25 #include "sggame.hpp"
26 #include "sgstep.hpp"
27 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/serialization/utility.hpp>
30 
32 
38 {
39 private:
40  vector< vector<SGBaseAction> > actions;
48 public:
51 
54 
58  SGIteration_MaxMinMax (const vector<list<SGAction_MaxMinMax> > & _actions,
59  const SGTuple & _threatTuple):
60  threatTuple{_threatTuple}
61  {
62  // Copy the actions and recast them as SGBaseActions
63  actions.resize(_actions.size());
64  for (int state = 0; state < _actions.size(); state++)
65  {
66  actions[state].reserve(_actions[state].size());
67  for (auto ait = _actions[state].begin();
68  ait != _actions[state].end();
69  ait++)
70  actions[state].push_back(static_cast<SGBaseAction>(*ait));
71  }
72  }
73 
75  void push_back(const SGStep & step)
76  {
77  steps.push_back(step);
78  }
80  const list<SGStep> & getSteps() const { return steps; }
82  const vector< vector<SGBaseAction> > & getActions() const { return actions; }
84  const SGTuple & getThreatTuple() const { return threatTuple; }
85 
88  template<class Archive>
89 
91  void serialize(Archive &ar, const unsigned int version)
92  {
93  ar & steps;
94  ar & actions;
95  ar & threatTuple;
96  }
97 }; // SGIteration_MaxMinMax
98 
99 #endif
SGIteration_MaxMinMax::actions
vector< vector< SGBaseAction > > actions
Definition: sgiteration_maxminmax.hpp:40
std::list< SGStep >
Definition: sgstl.cpp:35
SGIteration_MaxMinMax::access
friend class boost::serialization::access
Serializes the SGIteration_MaxMinMax object using boost.
Definition: sgiteration_maxminmax.hpp:87
SGIteration_MaxMinMax::steps
list< SGStep > steps
Definition: sgiteration_maxminmax.hpp:46
SGStep
A single step of the max-min-max algorithm.
Definition: sgstep.hpp:36
SGIteration_MaxMinMax::SGIteration_MaxMinMax
SGIteration_MaxMinMax(const vector< list< SGAction_MaxMinMax > > &_actions, const SGTuple &_threatTuple)
Definition: sgiteration_maxminmax.hpp:58
SGIteration_MaxMinMax::getSteps
const list< SGStep > & getSteps() const
Get method for the steps.
Definition: sgiteration_maxminmax.hpp:80
SGIteration_MaxMinMax::SGIteration_MaxMinMax
SGIteration_MaxMinMax()
Default constructor.
Definition: sgiteration_maxminmax.hpp:50
SGIteration_MaxMinMax::serialize
void serialize(Archive &ar, const unsigned int version)
Serialize the iteration using Boost.
Definition: sgiteration_maxminmax.hpp:91
SGIteration_MaxMinMax::getActions
const vector< vector< SGBaseAction > > & getActions() const
Get method for the actions available at the current iteration.
Definition: sgiteration_maxminmax.hpp:82
SGIteration_MaxMinMax::threatTuple
SGTuple threatTuple
Definition: sgiteration_maxminmax.hpp:44
SGBaseAction
Describes an action in the game.
Definition: sgbaseaction.hpp:39
SGTuple
Definition: sgtuple.hpp:52
SGIteration_MaxMinMax
Stores data on the behavior of SGSolver_MaxMinMax.
Definition: sgiteration_maxminmax.hpp:38
SGIteration_MaxMinMax::push_back
void push_back(const SGStep &step)
Add an SGStep.
Definition: sgiteration_maxminmax.hpp:75
SGIteration_MaxMinMax::getThreatTuple
const SGTuple & getThreatTuple() const
Get method for the current threat tuple.
Definition: sgiteration_maxminmax.hpp:84