Serialization and Deserialization¶
This API aims to be lean with little, if any, dependencies on third-party libraries. Thus, we do not
serialize/deserialize serde to any format other than CSV. Here’s an example of saving a BBN to a CSV.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | #include "Variable.h"
#include "BbnNode.h"
#include "Bbn.h"
#include "BbnUtil.h"
using namespace com::ooc::bbn;
int main(int argc, char *argv[]) {
  // create vector of nodes
  std::vector<graph::_bbnNode> nodes{
      graph::BbnNode::instance(graph::Variable::instance("0", "a", {"on", "off"}), {0.5, 0.5}),
      graph::BbnNode::instance(graph::Variable::instance("1", "b", {"on", "off"}), {0.5, 0.5, 0.5, 0.5})
  };
  // create vector of edges
  std::vector<graph::_edge> edges{
      graph::Edge::instance("0", "1", graph::EdgeType::DIRECTED)
  };
  // create bbn
  auto bbn = graph::Bbn::instance(nodes, edges);
  // serialize bbn
  util::BbnUtil::serialize("example.csv", bbn);
  return 0;
}
 | 
The example.csv generated will look like the following.
1 2 3  | 0,a,on,off,|,0.500000,0.500000
1,b,on,off,|,0.500000,0.500000,0.500000,0.500000
0,1,directed
 | 
Here’s an example of loading a BBN from a CSV.
1 2 3 4 5 6 7 8 9 10  | #include "BbnUtil.h"
using namespace com::ooc::bbn;
int main(int argc, char *argv[]) {
  // deserialize bbn
  auto bbn = util::BbnUtil::deserialize("example.csv");
  return 0;
}
 |