23 #ifndef DOXYGEN_SHOULD_SKIP_THIS 32 template <
typename GUM_SCALAR >
34 GUM_CONSTRUCTOR(UAIWriter);
40 template <
typename GUM_SCALAR >
42 GUM_DESTRUCTOR(UAIWriter);
52 template <
typename GUM_SCALAR >
54 const IBayesNet< GUM_SCALAR >& bn) {
56 GUM_ERROR(IOError,
"Stream states flags are not all unset.");
59 output << __preambule(bn) << std::endl;
61 for (
auto node : bn.nodes())
62 output << __cptBloc(bn, node) << std::endl;
68 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed."); }
80 template <
typename GUM_SCALAR >
82 const IBayesNet< GUM_SCALAR >& bn) {
83 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
89 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed."); }
92 template <
typename GUM_SCALAR >
95 std::stringstream str;
97 str <<
"BAYES" << std::endl;
99 str << bn.size() << std::endl;
101 for (
auto node : bn.nodes())
102 str << bn.variable(node).domainSize() <<
" ";
105 str << bn.size() << std::endl;
107 for (
auto node : bn.nodes()) {
108 const auto& p = bn.cpt(node);
109 str << p.nbrDim() <<
" ";
114 for (
auto k : p.variablesSequence()) {
117 first = bn.idFromName(k->name());
119 str << bn.idFromName(k->name()) <<
" ";
122 str << first <<
" # " << bn.variable(node).name() << std::endl;
128 template <
typename GUM_SCALAR >
132 std::stringstream str;
134 const auto& p = bn.cpt(node);
135 str << p.domainSize();
137 for (I.setFirst(); !I.end(); ++I) {
138 if (I.val(0) == 0) str << std::endl <<
" ";
148 #endif // DOXYGEN_SHOULD_SKIP_THIS ~UAIWriter() final
Destructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string __cptBloc(const IBayesNet< GUM_SCALAR > &bn, NodeId node)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void write(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes an bayes net in the given ouput stream.
UAIWriter()
Default constructor.
std::string __preambule(const IBayesNet< GUM_SCALAR > &bn)
Returns the header of the BIF file.
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)