1 #ifndef FAIF_BELIEF_HPP_ 2 #define FAIF_BELIEF_HPP_ 6 #include <boost/serialization/serialization.hpp> 7 #include <boost/serialization/nvp.hpp> 9 #include "../Value.hpp" 14 typedef double Probability;
21 template<
typename Bel>
22 struct BeliefConcept : boost::DefaultConstructible<Bel>, boost::CopyConstructible<Bel>,
23 boost::Assignable<Bel>
26 typedef typename Bel::Value Value;
27 typedef typename Bel::ValueId ValueId;
28 typedef typename Bel::Beliefs Beliefs;
41 template <
typename Val>
class Belief {
46 typedef typename Val::DomainType::ValueId ValueId;
49 typedef typename std::vector<Belief<Val> > Beliefs;
51 Belief() : value_(Val::DomainType::getUnknownId() ), probability_(0.0) {}
53 Belief(ValueId value, Probability probability) : value_(value), probability_(probability) {}
55 ValueId getValue()
const {
return value_; }
56 Probability getProbability()
const {
return probability_; }
59 friend class boost::serialization::access;
61 template<
class Archive>
62 void save(Archive & ar,
const unsigned int )
const {
63 ar & boost::serialization::make_nvp(
"Value", value_ );
64 ar & boost::serialization::make_nvp(
"Probability", probability_ );
67 template<
class Archive>
68 void load(Archive & ar,
const unsigned int ) {
69 typename Val::DomainType::ValueIdSerialize i;
70 ar >> boost::serialization::make_nvp(
"Value", i);
71 value_ =
const_cast<ValueId
>(i);
72 ar & boost::serialization::make_nvp(
"Probability", probability_ );
75 template<
class Archive>
76 void serialize( Archive &ar,
const unsigned int file_version ){
77 boost::serialization::split_member(ar, *
this, file_version);
81 bool operator<(
const Belief &c)
const {
return probability_ > c.probability_; }
84 Probability probability_;
88 template <
typename Val> std::ostream& operator<<(std::ostream& os, const Belief<Val>& b) {
89 os <<
"Value:" << b.getValue() <<
" Prob:" << b.getProbability();
94 template <
typename Val> std::ostream& operator<<(std::ostream& os, const std::vector<Belief<Val> >& c) {
95 std::copy(c.begin(), c.end(), std::ostream_iterator<Belief<Val> >(os,
";") );
104 #endif //FAIF_BELIEF_HPP_
the value concept
Definition: Value.hpp:41
the belief concept
Definition: Belief.hpp:22
belief is value id with probability
Definition: Belief.hpp:41