MultiAgentDecisionProcess  Release 0.2.1
BeliefSparse.h
Go to the documentation of this file.
1 
28 /* Only include this header file once. */
29 #ifndef _BELIEFSPARSE_H_
30 #define _BELIEFSPARSE_H_ 1
31 
32 /* the include directives */
33 #include <iostream>
34 #include "Globals.h"
35 #include "BeliefInterface.h"
36 
37 #include <boost/numeric/ublas/vector_sparse.hpp>
38 #include <boost/numeric/ublas/io.hpp>
39 
41 class StateDistribution;
42 
44 
45 class BeliefSparse : virtual public BeliefInterface
46 {
47 private:
48 
49  friend class BeliefIteratorSparse;
50 
51 protected:
52 
53 #if BOOST_1_32_OR_LOWER // they renamed sparse_vector to mapped_vector
54  typedef boost::numeric::ublas::sparse_vector<double> BS;
55 #else
56  typedef boost::numeric::ublas::compressed_vector<double> BS;
57 #endif
58 
59  typedef BS::const_iterator BScit;
60  typedef BS::iterator BSit;
61 
64 
65 public:
66 
68  BeliefSparse();
69 
71  BeliefSparse(size_t size);
72 
74  BeliefSparse(const std::vector<double> &belief);
75 
77  BeliefSparse(const BeliefInterface &belief);
78  BeliefSparse(const StateDistribution& belief);
79 
81  ~BeliefSparse();
82 
83  // operators:
86 
87 #if BOOST_1_32_OR_LOWER
88  // uses sparse_vector instead of mapped_vector. The former, however, does
89  // not define .ref()
90  double& operator[] (Index& i) {
91  return
92  //_m_b(i);
93  //_m_b.BS::operator[](i);
94  *_m_b.find_element(i);
95  }
96 
97  double& operator[] (int& i) {
98  return
99  //_m_b(i);
100  //_m_b.BS::operator()(i);
101  *_m_b.find_element(i);
102  }
103 #else
104  double& operator[] (Index& i) {
105  return _m_b.ref(i); //_m_b.BS::operator[](i);
106  }
107 
108  double& operator[] (int& i) {
109  return _m_b.ref(i); //_m_b.BS::operator[](i);
110  }
111 #endif
112 
113  //data manipulation (set) functions:
114  void Set(const BS &belief);
115 
116  void Set(const std::vector<double> &belief);
117 
118  void Set(Index sI, double prob) { _m_b[sI]=prob; }
119 
120  void Set(const BeliefInterface &belief);
121 
122  virtual void Set(const StateDistribution& belief);
123 
124  //get (data) functions:
125 
126  double Get(Index sI) const { return(_m_b[sI]); };
127  std::vector<double> Get() const
128  {
129  throw E("BeliefSparse::Get() is not yet implemented");
130  };
131 
132  void Clear();
133 
134  std::string SoftPrint() const;
135 
136  void Print() const { std::cout << SoftPrint(); }
137 
138  unsigned int Size() const { return(_m_b.size()); }
139 
140  bool SanityCheck() const;
141 
142  double InnerProduct(const std::vector<double> &values) const;
143 
144  std::vector<double> InnerProduct(const VectorSet &v) const;
145 
146  std::vector<double> InnerProduct(const VectorSet &v,
147  const std::vector<bool> &mask) const;
148 
150 
152  virtual BeliefSparse* Clone() const
153  { return new BeliefSparse(*this); }
154 
155 };
156 
157 
158 #endif /* !_BELIEFSPARSE_H_ */
159 
160 // Local Variables: ***
161 // mode:c++ ***
162 // End: ***