changed optimize functions to const ( using find operator of a map instead of [] )
parent
af6d98253f
commit
b70f081ebc
|
@ -37,7 +37,7 @@ void ChordalBayesNet::erase(const string& key)
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// optimize, i.e. return x = inv(R)*d
|
// optimize, i.e. return x = inv(R)*d
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
boost::shared_ptr<FGConfig> ChordalBayesNet::optimize()
|
boost::shared_ptr<FGConfig> ChordalBayesNet::optimize() const
|
||||||
{
|
{
|
||||||
boost::shared_ptr<FGConfig> result(new FGConfig);
|
boost::shared_ptr<FGConfig> result(new FGConfig);
|
||||||
result = optimize(result);
|
result = optimize(result);
|
||||||
|
@ -45,15 +45,15 @@ boost::shared_ptr<FGConfig> ChordalBayesNet::optimize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
boost::shared_ptr<FGConfig> ChordalBayesNet::optimize(const boost::shared_ptr<FGConfig> &c)
|
boost::shared_ptr<FGConfig> ChordalBayesNet::optimize(const boost::shared_ptr<FGConfig> &c) const
|
||||||
{
|
{
|
||||||
boost::shared_ptr<FGConfig> result(new FGConfig);
|
boost::shared_ptr<FGConfig> result(new FGConfig);
|
||||||
result = c;
|
result = c;
|
||||||
|
|
||||||
/** solve each node in turn in topological sort order (parents first)*/
|
/** solve each node in turn in topological sort order (parents first)*/
|
||||||
BOOST_FOREACH(string key, keys) {
|
BOOST_FOREACH(string key, keys) {
|
||||||
ConditionalGaussian::shared_ptr cg = nodes[key]; // get node
|
const_iterator cg = nodes.find(key); // get node
|
||||||
Vector x = cg->solve(*result); // Solve it
|
Vector x = cg->second->solve(*result); // Solve it
|
||||||
result->insert(key,x); // store result in partial solution
|
result->insert(key,x); // store result in partial solution
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -30,9 +30,10 @@ protected:
|
||||||
std::list<std::string> keys;
|
std::list<std::string> keys;
|
||||||
|
|
||||||
/** nodes stored on key */
|
/** nodes stored on key */
|
||||||
std::map<std::string,ConditionalGaussian::shared_ptr> nodes;
|
typedef std::map<std::string,ConditionalGaussian::shared_ptr> Nodes;
|
||||||
|
Nodes nodes;
|
||||||
|
|
||||||
typedef std::map<std::string, ConditionalGaussian::shared_ptr>::iterator iterator;
|
typedef Nodes::iterator iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -56,13 +57,13 @@ public:
|
||||||
inline ConditionalGaussian::shared_ptr operator[](const std::string& key) { return nodes[key];}
|
inline ConditionalGaussian::shared_ptr operator[](const std::string& key) { return nodes[key];}
|
||||||
|
|
||||||
/** return begin and end of the nodes. FD: breaks encapsulation? */
|
/** return begin and end of the nodes. FD: breaks encapsulation? */
|
||||||
typedef std::map<std::string, ConditionalGaussian::shared_ptr>::const_iterator const_iterator;
|
typedef Nodes::const_iterator const_iterator;
|
||||||
const_iterator const begin() const {return nodes.begin();}
|
const_iterator const begin() const {return nodes.begin();}
|
||||||
const_iterator const end() const {return nodes.end();}
|
const_iterator const end() const {return nodes.end();}
|
||||||
|
|
||||||
/** optimize */
|
/** optimize */
|
||||||
boost::shared_ptr<FGConfig> optimize();
|
boost::shared_ptr<FGConfig> optimize() const;
|
||||||
boost::shared_ptr<FGConfig> optimize(const boost::shared_ptr<FGConfig> &c);
|
boost::shared_ptr<FGConfig> optimize(const boost::shared_ptr<FGConfig> &c) const;
|
||||||
|
|
||||||
/** print */
|
/** print */
|
||||||
void print() const;
|
void print() const;
|
||||||
|
|
Loading…
Reference in New Issue