changed optimize functions to const ( using find operator of a map instead of [] )

release/4.3a0
Manohar Paluri 2009-08-27 02:00:26 +00:00
parent af6d98253f
commit b70f081ebc
2 changed files with 10 additions and 9 deletions

View File

@ -37,7 +37,7 @@ void ChordalBayesNet::erase(const string& key)
/* ************************************************************************* */
// 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);
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);
result = c;
/** solve each node in turn in topological sort order (parents first)*/
BOOST_FOREACH(string key, keys) {
ConditionalGaussian::shared_ptr cg = nodes[key]; // get node
Vector x = cg->solve(*result); // Solve it
const_iterator cg = nodes.find(key); // get node
Vector x = cg->second->solve(*result); // Solve it
result->insert(key,x); // store result in partial solution
}
return result;

View File

@ -30,9 +30,10 @@ protected:
std::list<std::string> keys;
/** 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:
@ -56,13 +57,13 @@ public:
inline ConditionalGaussian::shared_ptr operator[](const std::string& key) { return nodes[key];}
/** 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 end() const {return nodes.end();}
/** optimize */
boost::shared_ptr<FGConfig> optimize();
boost::shared_ptr<FGConfig> optimize(const boost::shared_ptr<FGConfig> &c);
boost::shared_ptr<FGConfig> optimize() const;
boost::shared_ptr<FGConfig> optimize(const boost::shared_ptr<FGConfig> &c) const;
/** print */
void print() const;