Review comments

release/4.3a0
Frank Dellaert 2025-01-28 14:50:11 -05:00
parent 9e98b805d6
commit 8c7e75bb25
2 changed files with 10 additions and 18 deletions

View File

@ -31,26 +31,18 @@ DiscreteJunctionTree::DiscreteJunctionTree(
const DiscreteEliminationTree& eliminationTree) const DiscreteEliminationTree& eliminationTree)
: Base(eliminationTree) {} : Base(eliminationTree) {}
/* ************************************************************************* */ /* ************************************************************************* */
namespace {
struct PrintForestVisitorPre {
const KeyFormatter& formatter;
PrintForestVisitorPre(const KeyFormatter& formatter) : formatter(formatter) {}
std::string operator()(
const std::shared_ptr<DiscreteJunctionTree::Cluster>& node,
const std::string& parentString) {
// Print the current node
node->print(parentString + "-", formatter);
node->factors.print(parentString + "-", formatter);
std::cout << std::endl;
// Increment the indentation
return parentString + "| ";
}
};
} // namespace
void DiscreteJunctionTree::print(const std::string& s, void DiscreteJunctionTree::print(const std::string& s,
const KeyFormatter& keyFormatter) const { const KeyFormatter& keyFormatter) const {
PrintForestVisitorPre visitor(keyFormatter); auto visitor = [&keyFormatter](
const std::shared_ptr<DiscreteJunctionTree::Cluster>& node,
const std::string& parentString) {
// Print the current node
node->print(parentString + "-", keyFormatter);
node->factors.print(parentString + "-", keyFormatter);
std::cout << std::endl;
return parentString + "| "; // Increment the indentation
};
std::string parentString = s; std::string parentString = s;
treeTraversal::DepthFirstForest(*this, parentString, visitor); treeTraversal::DepthFirstForest(*this, parentString, visitor);
} }

View File

@ -58,4 +58,4 @@ DiscreteBayesNet createAsiaExample() {
return asia; return asia;
} }
} // namespace asia_example } // namespace asia_example
} // namespace gtsam } // namespace gtsam