PropertySet.cpp
Go to the documentation of this file.
1 /*
2  * PropertySet.cpp
3  *
4  * Created on: March, 2011
5  * Author: Jos Elfring, Sjoerd van den Dries
6  * Affiliation: Eindhoven University of Technology
7  */
8 
10 #include "wire/core/Property.h"
11 #include "wire/models/FixedState.h"
12 
13 using namespace std;
14 
15 namespace mhf {
16 
17 int PropertySet::N_PROPERTY_SET = 0;
18 
19 PropertySet::PropertySet(Time timestamp) : timestamp_(timestamp) {
21 }
22 
24  for(map<Attribute, Property*>::iterator it = properties_.begin(); it != properties_.end(); ++it) {
25  delete it->second;
26  }
27 
29 }
30 
32  for(map<Attribute, Property*>::const_iterator it = orig.properties_.begin(); it != orig.properties_.end(); ++it) {
33  properties_[it->first] = it->second->clone();
34  }
35 }
36 
38  return new PropertySet(*this);
39 }
40 
41 void PropertySet::addProperty(const Attribute& attribute, const pbl::PDF& value) {
43  if (it == properties_.end()) {
44  properties_[attribute] = new Property(attribute, FixedState(value));
45  } else {
46  delete it->second;
47  it->second = new Property(attribute, FixedState(value));
48  }
49 }
50 
51 void PropertySet::addProperty(const string& att, const pbl::PDF& value) {
53 }
54 
55 void PropertySet::addProperty(const Attribute& attribute, const IStateEstimator& estimator) {
57  if (it == properties_.end()) {
58  properties_[attribute] = new Property(attribute, estimator);
59  } else {
60  delete it->second;
61  it->second = new Property(attribute, estimator);
62  }
63 }
64 
67  if (it == properties_.end()) {
68  properties_[property->getAttribute()] = property;
69  } else {
70  delete it->second;
71  it->second = property;
72  }
73 }
74 
75 const Property* PropertySet::getProperty(const Attribute& attribute) const {
77  if (it != properties_.end()) {
78  return it->second;
79  }
80  return 0;
81 }
82 
85  if (it != properties_.end()) {
86  return it->second;
87  }
88  return 0;
89 }
90 
91 const Property* PropertySet::getProperty(const std::string& attribute) const {
92  return getProperty(AttributeConv::attribute(attribute));
93 }
94 
95 void PropertySet::propagate(const Time& time) {
96  if (fabs(time - timestamp_) < 0.001) {
97  return;
98  }
99 
100  for(map<Attribute, Property*>::iterator it = properties_.begin(); it != properties_.end(); ++it) {
101  it->second->propagate(time);
102  }
103 
104  timestamp_ = time;
105 }
106 
107 void PropertySet::update(const pbl::PDF& z, const Time& time) {
108  assert(false);
109 }
110 
112  for(map<Attribute, Property*>::iterator it = properties_.begin(); it != properties_.end(); ++it) {
113  it->second->reset();
114  }
115 }
116 
118  assert(false);
119 }
120 
121 double PropertySet::getLikelihood(const PropertySet& P) const {
122  double likelihood = 1;
123 
124  const map<Attribute, Property*>& other_props = P.properties_;
125 
126  for(map<Attribute, Property*>::const_iterator it = other_props.begin(); it != other_props.end(); ++it) {
127 
128  const Attribute& attribute = it->first;
129  const Property* other_prop = it->second;
130 
131  const Property* this_prop = getProperty(attribute);
132 
133  if (this_prop) {
134 
135  /*
136  std::cout << "Attribute: " << AttributeConv::attribute_str(it->first) << std::endl;
137  std::cout << "PDF mine: " << it_prop->second->getValue().toString() << std::endl;
138  std::cout << "PDF other: " << it->second->getValue().toString() << std::endl;
139  std::cout << "Likelihood: " << it_prop->second->getLikelihood(it->second->getValue()) << std::endl;
140  */
141 
142  likelihood *= this_prop->getLikelihood(other_prop->getValue());
143  } else {
144  printf("Error during likelihood calculation: property '%s' is not in property set.\n", AttributeConv::attribute_str(attribute).c_str());
145 
146  printf("This (%p) constains:\n", this);
147  for(map<Attribute, Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it) {
148  printf(" - %s\n", AttributeConv::attribute_str(it->first).c_str());
149  }
150 
151  printf("Other (%p) constains:\n", &P);
152  for(map<Attribute, Property*>::const_iterator it = other_props.begin(); it != other_props.end(); ++it) {
153  printf(" - %s\n", AttributeConv::attribute_str(it->first).c_str());
154  }
155  }
156 
157  }
158 
159  return likelihood;
160 }
161 
162 const std::map<Attribute, Property*>& PropertySet::getPropertyMap() const {
163  return properties_;
164 }
165 
167  return timestamp_;
168 }
169 
170 string PropertySet::toString() const {
171  stringstream s;
172  for(map<Attribute, Property*>::const_iterator it = properties_.begin(); it != properties_.end(); ++it) {
173  s << " - " << AttributeConv::attribute_str(it->first) << endl;
174  }
175  return s.str();
176 }
177 
178 }
const Property * getProperty(const Attribute &attribute) const
Definition: PropertySet.cpp:75
eT value() const
Time getTimestamp() const
static Attribute attribute(const std::string &attribute_str)
attribute
Definition: datatypes.cpp:16
const Attribute & getAttribute() const
Definition: Property.cpp:40
void update(const pbl::PDF &z, const Time &time)
Updates the internal state based on measurement z.
const std::map< Attribute, Property * > & getPropertyMap() const
XmlRpcServer s
virtual double getLikelihood(const pbl::PDF &pdf) const
Definition: Property.cpp:68
std::map< Attribute, Property * > properties_
Definition: PropertySet.h:62
static int N_PROPERTY_SET
Definition: PropertySet.h:16
void addProperty(const Attribute &attribute, const pbl::PDF &value)
Definition: PropertySet.cpp:41
Base class for all state estimators used by the world model.
static std::string attribute_str(const Attribute &attribute)
attribute_str
Definition: datatypes.cpp:27
iterator(field< oT > &in_M, const bool at_end=false)
double Time
Definition: datatypes.h:52
FixedState is a simple wrapper such that probability density function can be threaded as state estima...
Definition: FixedState.h:20
PropertySet * clone() const
Definition: PropertySet.cpp:37
int Attribute
Definition: datatypes.h:49
void reset()
Resets the internal state of the estimator to its initial value.
const pbl::PDF & getValue() const
Returns the current estimated state value.
const_iterator(const field< oT > &in_M, const bool at_end=false)
virtual double getLikelihood(const PropertySet &P) const
const pbl::PDF & getValue() const
Definition: Property.cpp:48
void propagate(const Time &time)
Propagates the internal state to Time time.
Definition: PropertySet.cpp:95
std::string toString() const
PropertySet(Time timestamp=0)
Definition: PropertySet.cpp:19
virtual ~PropertySet()
Definition: PropertySet.cpp:23
Definition: ClassModel.h:44


wire_core
Author(s): Sjoerd van den Dries, Jos Elfring
autogenerated on Fri Apr 16 2021 02:32:27