gtsam 4.1.1
gtsam
BayesNet-inst.h
1/* ----------------------------------------------------------------------------
2
3* GTSAM Copyright 2010, Georgia Tech Research Corporation,
4* Atlanta, Georgia 30332-0415
5* All Rights Reserved
6* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8* See LICENSE for the license information
9
10* -------------------------------------------------------------------------- */
11
19#pragma once
20
21#include <gtsam/inference/FactorGraph-inst.h>
23
24#include <boost/range/adaptor/reversed.hpp>
25#include <fstream>
26
27namespace gtsam {
28
29/* ************************************************************************* */
30template <class CONDITIONAL>
32 const std::string& s, const KeyFormatter& formatter) const {
33 Base::print(s, formatter);
34}
35
36/* ************************************************************************* */
37template <class CONDITIONAL>
38void BayesNet<CONDITIONAL>::saveGraph(const std::string& s,
39 const KeyFormatter& keyFormatter) const {
40 std::ofstream of(s.c_str());
41 of << "digraph G{\n";
42
43 for (auto conditional : boost::adaptors::reverse(*this)) {
44 typename CONDITIONAL::Frontals frontals = conditional->frontals();
45 Key me = frontals.front();
46 typename CONDITIONAL::Parents parents = conditional->parents();
47 for (Key p : parents)
48 of << keyFormatter(p) << "->" << keyFormatter(me) << std::endl;
49 }
50
51 of << "}";
52 of.close();
53}
54
55} // namespace gtsam
Bayes network.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
A BayesNet is a tree of conditionals, stored in elimination order.
Definition: BayesNet.h:34
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print out graph
Definition: BayesNet-inst.h:31