pass FactorGraph as reference into split

release/4.3a0
Kai Ni 2010-01-08 20:27:10 +00:00
parent 06b7f8ee04
commit d4f92c7bb6
4 changed files with 6 additions and 8 deletions

View File

@ -331,9 +331,8 @@ map<string, string> FactorGraph<Factor>::findMinimumSpanningTree() const {
}
template<class Factor>
pair<FactorGraph<Factor>, FactorGraph<Factor> > FactorGraph<Factor>::split(map<string, string> tree) const {
void FactorGraph<Factor>::split(map<string, string> tree, FactorGraph<Factor>& Ab1, FactorGraph<Factor>& Ab2) const {
FactorGraph<Factor> Ab1, Ab2;
BOOST_FOREACH(sharedFactor factor, factors_){
if (factor->keys().size() > 2)
throw(invalid_argument("split: only support factors with at most two keys"));
@ -350,8 +349,6 @@ pair<FactorGraph<Factor>, FactorGraph<Factor> > FactorGraph<Factor>::split(map<s
else
Ab2.push_back(factor);
}
return make_pair(Ab1, Ab2);
}

View File

@ -125,7 +125,8 @@ namespace gtsam {
* Split the graph into two parts: one corresponds to the given spanning tre,
* and the other corresponds to the rest of the factors
*/
std::pair<FactorGraph<Factor>, FactorGraph<Factor> > split(std::map<std::string, std::string> tree) const;
void split(std::map<std::string, std::string> tree,
FactorGraph<Factor>& Ab1, FactorGraph<Factor>& Ab2) const;
private:
/** Associate factor index with the variables connected to the factor */

View File

@ -64,6 +64,8 @@ VectorConfig optimize(const GaussianBayesNet& bn)
/** solve each node in turn in topological sort order (parents first)*/
BOOST_REVERSE_FOREACH(GaussianConditional::shared_ptr cg, bn) {
cg->print();
result.print();
Vector x = cg->solve(result); // Solve for that variable
result.insert(cg->key(),x); // store result in partial solution
}

View File

@ -769,9 +769,7 @@ TEST( GaussianFactorGraph, split )
tree["x4"] = "x1";
GaussianFactorGraph Ab1, Ab2;
pair<FactorGraph<GaussianFactor>, FactorGraph<GaussianFactor> > gg = g.split(tree);
Ab1 = *reinterpret_cast<GaussianFactorGraph*>(&(gg.first));
Ab2 = *reinterpret_cast<GaussianFactorGraph*>(&(gg.second));
g.split(tree, Ab1, Ab2);
LONGS_EQUAL(3, Ab1.size());
LONGS_EQUAL(2, Ab2.size());
}