gtsam  4.1.0
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 
27 namespace gtsam {
28 
29  /* ************************************************************************* */
30  template<class CONDITIONAL>
31  void BayesNet<CONDITIONAL>::print(const std::string& s, const KeyFormatter& formatter) const
32  {
33  Base::print(s, formatter);
34  }
35 
36  /* ************************************************************************* */
37  template<class CONDITIONAL>
38  void BayesNet<CONDITIONAL>::saveGraph(const std::string &s, const KeyFormatter& keyFormatter) const
39  {
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 }
BayesNet.h
Bayes network.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
gtsam::BayesNet
A BayesNet is a tree of conditionals, stored in elimination order.
Definition: BayesNet.h:34
gtsam::KeyFormatter
boost::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
gtsam::BayesNet::print
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const
print out graph
Definition: BayesNet-inst.h:31