SGSolve
sghyperplane.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 _SGHYPERPLANE_HPP
23 #define _SGHYPERPLANE_HPP
24 
25 #include "sgcommon.hpp"
26 #include "sgpoint.hpp"
27 #include "sgexception.hpp"
28 
30 
39 {
40 private:
42  vector<double> levels;
44 public:
46  SGHyperplane(int numStates): levels(numStates,0)
47  {}
48 
50  SGHyperplane(const SGPoint & _normal,
51  const vector<double> & _levels):
52  normal(_normal),
53  levels(_levels)
54  {}
55 
57  SGHyperplane(): normal(0,0), levels(1,0) {}
58  ~SGHyperplane() {}
59 
61 
63  double expectation(const vector<double> & prob) const;
64 
66  static double distance(const SGHyperplane& t0,
67  const SGHyperplane& t1);
68 
70  void push_back(double level);
72  void clear();
73 
75  int size() const { return levels.size(); }
76 
78  void setNormal(const SGPoint & newNorm)
79  { normal = newNorm; }
81  const SGPoint & getNormal() const
82  { return normal; }
84  const vector<double> & getLevels() const
85  { return levels; }
86 
87  // Operators
89  double& operator[](int state);
91  const double& operator[](int state) const;
93  SGHyperplane& operator=(const SGHyperplane & rhs);
95  SGHyperplane& operator+=(const SGHyperplane & rhs);
97  SGHyperplane& operator-=(const SGHyperplane & rhs);
99 
100  SGHyperplane& operator+=(double rhs);
102  SGHyperplane& operator*=(double d);
104  friend SGHyperplane operator*(double d,const SGHyperplane & hp);
106  friend SGHyperplane operator*(const SGHyperplane & hp,double d);
108  friend ostream& operator<<(ostream& out, const SGHyperplane& rhs);
109 
111  void round(double tol);
112 
114  template<class Archive>
115  void serialize(Archive &ar, const unsigned int version)
116  {
117  ar & normal & levels;
118  }
119 
120  friend class boost::serialization::access;
121 }; // SGHyperplane
122 
123 #endif
SGHyperplane::SGHyperplane
SGHyperplane(int numStates)
Initializes tuple to _numStates zero-vectors.
Definition: sghyperplane.hpp:46
SGHyperplane::getLevels
const vector< double > & getLevels() const
Get the levels.
Definition: sghyperplane.hpp:84
SGHyperplane::operator+=
SGHyperplane & operator+=(const SGHyperplane &rhs)
Augmented addition of tuples.
Definition: sghyperplane.cpp:65
SGHyperplane::levels
vector< double > levels
Definition: sghyperplane.hpp:42
SGHyperplane::getNormal
const SGPoint & getNormal() const
Get the normal.
Definition: sghyperplane.hpp:81
SGHyperplane::operator=
SGHyperplane & operator=(const SGHyperplane &rhs)
Assignment operator.
Definition: sghyperplane.cpp:55
SGHyperplane::distance
static double distance(const SGHyperplane &t0, const SGHyperplane &t1)
Calculates the distance between t0 and t1 in the sup norm.
Definition: sghyperplane.cpp:98
SGHyperplane::operator*
friend SGHyperplane operator*(double d, const SGHyperplane &hp)
Left scalar multiplication of a tuple.
Definition: sghyperplane.cpp:92
SGHyperplane::SGHyperplane
SGHyperplane(const SGPoint &_normal, const vector< double > &_levels)
Initializes tuple to _numPoints copies of point.
Definition: sghyperplane.hpp:50
SGHyperplane
Represents a hyperplane in .
Definition: sghyperplane.hpp:39
SGHyperplane::operator*=
SGHyperplane & operator*=(double d)
Scalar multiplication of the hyperplane.
Definition: sghyperplane.cpp:85
SGHyperplane::clear
void clear()
Sets the levels equal to an empty vector.
Definition: sghyperplane.cpp:121
SGHyperplane::setNormal
void setNormal(const SGPoint &newNorm)
Set the normal.
Definition: sghyperplane.hpp:78
SGHyperplane::serialize
void serialize(Archive &ar, const unsigned int version)
Serialize using boost.
Definition: sghyperplane.hpp:115
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGHyperplane::round
void round(double tol)
Round off significant digits smaller than tol.
Definition: sghyperplane.cpp:126
SGHyperplane::operator<<
friend ostream & operator<<(ostream &out, const SGHyperplane &rhs)
Output formatted tuple to file stream.
Definition: sghyperplane.cpp:133
SGHyperplane::normal
SGPoint normal
Definition: sghyperplane.hpp:41
SGHyperplane::size
int size() const
Returns the number of levels in the tuple.
Definition: sghyperplane.hpp:75
SGHyperplane::push_back
void push_back(double level)
Adds a new level to the back of the hyperplane.
Definition: sghyperplane.cpp:116
SGHyperplane::expectation
double expectation(const vector< double > &prob) const
Mathematical expectation.
Definition: sghyperplane.cpp:26
SGHyperplane::operator[]
double & operator[](int state)
Random access the elements of the tuple.
Definition: sghyperplane.cpp:37
SGHyperplane::operator+=
SGHyperplane & operator+=(double rhs)
Augmented addition of tuple with a point.
SGHyperplane::operator-=
SGHyperplane & operator-=(const SGHyperplane &rhs)
Augmented subtraction of tuples.
Definition: sghyperplane.cpp:75
SGHyperplane::SGHyperplane
SGHyperplane()
Default constructor for empty tuple.
Definition: sghyperplane.hpp:57