1 /** 2 * 3 * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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 file for UAI exportation class 25 * 26 * Writes a bayes net in UAI format 27 * 28 * @author Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU) 29 */ 30 31 #ifndef UAI_BN_WRITER_H 32 #define UAI_BN_WRITER_H 33 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 43 namespace gum { 44 /** 45 * @class UAIBNWriter UAIBNWriter.h 46 *<agrum/BN/io/UAI/UAIBNWriter.h> 47 * @ingroup bn_io 48 * @brief Writes an bayes net in a text file with UAI format 49 * 50 * This class export a bayes net into an text file, using UAI format 51 * 52 * cf. http://www.cs.huji.ac.il/project/PASCAL/fileFormat.php 53 * 54 */ 55 template < typename GUM_SCALAR > 56 class UAIBNWriter: public BNWriter< GUM_SCALAR > { 57 public: 58 // ========================================================================== 59 /// @name Constructor & destructor 60 // ========================================================================== 61 /// @{ 62 63 /** 64 * Default constructor. 65 */ 66 UAIBNWriter(); 67 68 /** 69 * Destructor. 70 */ 71 ~UAIBNWriter(); 72 73 /// @} 74 75 /** 76 * Writes an bayes net in the given ouput stream. 77 * 78 * @param output The output stream. 79 * @param bn The bayes net writen in the stream. 80 * @throws IOError Raised if an I/O error occurs. 81 */ 82 void write(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn) final; 83 84 /** 85 * Writes an bayes net in the file referenced by filePath. 86 * If the file doesn't exists, it is created. 87 * If the file exists, it's content will be erased. 88 * 89 * @param filePath The path to the file used to write the bayes net. 90 * @param bn The bayes net writen in the file. 91 * @throw IOError Raised if an I/O error occurs. 92 */ 93 void write(const std::string& filePath, const IBayesNet< GUM_SCALAR >& bn) final; 94 95 private: 96 /** 97 * Returns the header of the BIF file. 98 */ 99 std::string _preambule_(const IBayesNet< GUM_SCALAR >& bn); 100 101 std::string _cptBloc_(const IBayesNet< GUM_SCALAR >& bn, NodeId node); 102 }; 103 104 105 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 106 extern template class UAIBNWriter< double >; 107 #endif 108 109 } /* namespace gum */ 110 111 #include <agrum/BN/io/UAI/UAIBNWriter_tpl.h> 112 #endif // UAI_BN_WRITER_H 113