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 /** @file
23  * @brief Class for generating Bayesian networks.
24  *
25  * @author Pierre-Henri WUILLEMIN(_at_LIP6) and Jean-Christophe MAGNAN and Christophe
26  * GONZALES(_at_AMU)
27  */
28 #ifndef GUM_INF_DIAG_GENERATOR_H
29 #define GUM_INF_DIAG_GENERATOR_H
30 
31 #include <cstdio>
32 #include <cstdlib>
33 #include <iostream>
34 #include <vector>
35 
36 #include <agrum/BN/generator/simpleCPTGenerator.h>
37 #include <agrum/ID/generator/UTGenerator.h>
38 #include <agrum/ID/generator/simpleUTGenerator.h>
39 #include <agrum/ID/influenceDiagram.h>
40 #include <agrum/tools/variables/labelizedVariable.h>
41 
42 namespace gum {
43 
44   /**
45    * @class InfluenceDiagramGenerator influenceDiagramGenerator.h
46    *<agrum/ID/generator/influenceDiagramGenerator.h>
47    * @brief Class for generating influence diagram.
48    * @ingroup id_group
49    *
50    * This class randomly generates an influence diagram given four parameters:
51    * the number of nodes,the probability of adding an arc between two nodes,
52    * the proportion of chance node and the proportion of utility node (the
53    * proportion of decision node is deduce from thos two)
54    */
55   template < typename GUM_SCALAR >
56   class InfluenceDiagramGenerator {
57     public:
58     // ############################################################################
59     /// @name Constructors / Destructor
60     // ############################################################################
61     /// @{
62     /**
63      * Default constructor.
64      * Use the SimpleCPTGenerator for generating the IDs CPT.
65      * Use the SimpleUTGenerator for generating the IDs UT.
66      */
67     InfluenceDiagramGenerator();
68 
69     /**
70      * Use this constructor if you want to use a different policy for generating
71      * CPT than the default one.
72      * The cptGenerator will be erased when the destructor is called.
73      * @param cptGenerator The policy used to generate CPT.
74      */
75     explicit InfluenceDiagramGenerator(ICPTGenerator< GUM_SCALAR >* cptGenerator);
76 
77     /**
78      * Use this constructor if you want to use a different policy for generating
79      * UT than the default one.
80      * The utGenerator will be erased when the destructor is called.
81      * @param utGenerator The policy used to generate UT.
82      */
83     explicit InfluenceDiagramGenerator(UTGenerator* utGenerator);
84 
85     /**
86      * Use this constructor if you want to use a different policy for generating
87      * both CPT & UT than the defaults ones.
88      * The cptGenerator and utGenerator will be erased when the destructor is
89      * called.
90      * @param cptGenerator The policy used to generate CPT.
91      * @param utGenerator The policy used to generate UT.
92      */
93     InfluenceDiagramGenerator(ICPTGenerator< GUM_SCALAR >* cptGenerator, UTGenerator* utGenerator);
94 
95     /**
96      * Destructor.
97      */
98     ~InfluenceDiagramGenerator();
99     /// @}
100 
101     // ############################################################################
102     /// @name ID generation methods
103     // ############################################################################
104     /// @{
105     /**
106      * Generates an influence diagram using floats.
107      * @param nbrNodes The number of nodes in the generated ID.
108      * @param arcDensity The probability of adding an arc between two nodes.
109      * @param chanceNodeDensity The proportion of chance node
110      * @param utilityNodeDensity The proportion of utility node
111      * @param max_modality Each DRV has from 2 to max_modality modalities
112      * @return A IDs randomly generated.
113      */
114     InfluenceDiagram< GUM_SCALAR >* generateID(Size       nbrNodes,
115                                                GUM_SCALAR arcDensity,
116                                                GUM_SCALAR chanceNodeDensity,
117                                                GUM_SCALAR utilityNodeDensity,
118                                                Size       max_modality = 2);
119 
120     /// @}
121     private:
122     // Check if a temporal order exists and creates ones if not
123     void _checkTemporalOrder_(InfluenceDiagram< GUM_SCALAR >* infdiag);
124     // The Conditional Probability Table generator
125     ICPTGenerator< GUM_SCALAR >* _cptGenerator_;
126     // The Utility Table generator
127     UTGenerator* _utGenerator_;
128   };
129 
130 } /* namespace gum */
131 
132 #include <agrum/ID/generator/influenceDiagramGenerator_tpl.h>
133 #endif /* GUM_INF_DIAG_GENERATOR_H */
134