From b70f081ebc7d7a1565e6b8eb1dbbe6c3e67909c4 Mon Sep 17 00:00:00 2001 From: Manohar Paluri Date: Thu, 27 Aug 2009 02:00:26 +0000 Subject: [PATCH] changed optimize functions to const ( using find operator of a map instead of [] ) --- cpp/ChordalBayesNet.cpp | 8 ++++---- cpp/ChordalBayesNet.h | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cpp/ChordalBayesNet.cpp b/cpp/ChordalBayesNet.cpp index 4bd11fb8c..3b0053d52 100644 --- a/cpp/ChordalBayesNet.cpp +++ b/cpp/ChordalBayesNet.cpp @@ -37,7 +37,7 @@ void ChordalBayesNet::erase(const string& key) /* ************************************************************************* */ // optimize, i.e. return x = inv(R)*d /* ************************************************************************* */ -boost::shared_ptr ChordalBayesNet::optimize() +boost::shared_ptr ChordalBayesNet::optimize() const { boost::shared_ptr result(new FGConfig); result = optimize(result); @@ -45,15 +45,15 @@ boost::shared_ptr ChordalBayesNet::optimize() } /* ************************************************************************* */ -boost::shared_ptr ChordalBayesNet::optimize(const boost::shared_ptr &c) +boost::shared_ptr ChordalBayesNet::optimize(const boost::shared_ptr &c) const { boost::shared_ptr 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; diff --git a/cpp/ChordalBayesNet.h b/cpp/ChordalBayesNet.h index 881c7a31e..ffbd18742 100644 --- a/cpp/ChordalBayesNet.h +++ b/cpp/ChordalBayesNet.h @@ -30,9 +30,10 @@ protected: std::list keys; /** nodes stored on key */ - std::map nodes; + typedef std::map Nodes; + Nodes nodes; - typedef std::map::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::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 optimize(); - boost::shared_ptr optimize(const boost::shared_ptr &c); + boost::shared_ptr optimize() const; + boost::shared_ptr optimize(const boost::shared_ptr &c) const; /** print */ void print() const;