aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
CNFWriter.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Definition of classe for BN file output manipulation
25  *
26  * This class servers to write the content of a Bayesian network in
27  * the BN format.
28  *
29  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
30  */
31 
32 #ifndef GUM_CNF_WRITER_H
33 #define GUM_CNF_WRITER_H
34 
35 #include <fstream>
36 #include <iostream>
37 #include <sstream>
38 #include <string>
39 
40 #include <agrum/BN/io/BNWriter.h>
41 #include <agrum/agrum.h>
42 #include <agrum/tools/core/approximations/approximationPolicy.h>
43 #include <agrum/tools/core/hashTable.h>
44 
45 // Ajout sur branche DDE pour pouvoir compiler (à retirer très probablement)
46 // problème sur template <typename> class IApproximationPolicy = ExactPolicy
47 // sinon
48 // (reconnaissance de ExactPolicy?)
49 #include <agrum/tools/core/approximations/exactPolicy.h>
50 
51 namespace gum {
52 
53  /**
54  * @class CNFWriter
55  * @headerfile CNFWriter.h <agrum/BN/io/cnf/CNFWriter.h>
56  * @ingroup bn_io
57  * @brief Writes a IBayesNet in the BN format.
58  *
59  * This class servers to write the content of a Bayesian network in
60  * the BN format. See
61  * TODO
62  * for information on this format.
63  *
64  */
65  template < typename GUM_SCALAR, template < typename > class IApproximationPolicy = ExactPolicy >
66  class CNFWriter: public BNWriter< GUM_SCALAR >, public IApproximationPolicy< GUM_SCALAR > {
67  public:
68  // ==========================================================================
69  /// @name Constructor & destructor
70  // ==========================================================================
71  /// @{
72 
73  /**
74  * Default constructor.
75  */
76  CNFWriter();
77 
78  /**
79  * Destructor.
80  */
81  ~CNFWriter() override;
82 
83  /// @}
84 
85  /**
86  * Writes a Bayesian network in the output stream using the BN format.
87  *
88  * @param output The output stream.
89  * @param bn The Bayesian network writen in output.
90  * @throws IOError Raised if and I/O error occurs.
91  */
92  void write(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn) override = 0;
93 
94  /**
95  * Writes a Bayesian network in the referenced file using the BN format.
96  * If the files doesn't exists, it is created.
97  *
98  * @param filePath The path to the file used to write the Bayesian network.
99  * @param bn The Bayesian network writed in the file.
100  * @throws IOError Raised if and I/O error occurs.
101  */
102  void write(const std::string& filePath, const IBayesNet< GUM_SCALAR >& bn) override = 0;
103 
104  inline GUM_SCALAR fromExact(const GUM_SCALAR& value) const override {
105  return IApproximationPolicy< GUM_SCALAR >::fromExact(value);
106  }
107  };
108 
109 
110 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
111  extern template class CNFWriter< double >;
112 #endif
113 
114 } /* namespace gum */
115 
116 #include <agrum/BN/io/cnf/CNFWriter_tpl.h>
117 #endif // GUM_NET_WRITER_H