35 template <
typename GUM_SCALAR >
46 template <
typename GUM_SCALAR >
48 ICPTGenerator< GUM_SCALAR >* cptGenerator) {
50 __cptGenerator = cptGenerator;
58 template <
typename GUM_SCALAR >
63 __utGenerator = utGenerator;
72 template <
typename GUM_SCALAR >
74 ICPTGenerator< GUM_SCALAR >* cptGenerator,
UTGenerator* utGenerator) {
76 __cptGenerator = cptGenerator;
77 __utGenerator = utGenerator;
81 template <
typename GUM_SCALAR >
84 delete __cptGenerator;
95 template <
typename GUM_SCALAR >
99 GUM_SCALAR arcDensity,
100 GUM_SCALAR chanceNodeDensity,
101 GUM_SCALAR utilityNodeDensity,
107 std::stringstream strBuff;
110 for (
Idx i = 0; i < nbrNodes; ++i) {
112 nb_mod = (max_modality == 2) ? 2 : 2 + rand() % (max_modality - 1);
114 GUM_SCALAR cnd = chanceNodeDensity * (GUM_SCALAR)RAND_MAX;
115 GUM_SCALAR und = utilityNodeDensity * (GUM_SCALAR)RAND_MAX;
117 GUM_SCALAR d = (GUM_SCALAR)rand();
123 else if (d < (cnd + und))
136 GUM_SCALAR p = arcDensity * (GUM_SCALAR)RAND_MAX;
138 for (
Size i = 0; i < nbrNodes; ++i)
140 for (
Size j = i + 1; j < nbrNodes; ++j)
141 if (((GUM_SCALAR)rand()) < p) {
142 influenceDiagram->
addArc(map[i], map[j]);
146 for (
Size i = 0; i < nbrNodes; ++i)
148 __cptGenerator->generateCPT(
149 influenceDiagram->
cpt(map[i]).pos(influenceDiagram->
variable(map[i])),
150 influenceDiagram->
cpt(map[i]));
152 __utGenerator->generateUT(influenceDiagram->
utility(map[i]).pos(
153 influenceDiagram->
variable(map[i])),
154 influenceDiagram->
utility(map[i]));
156 __checkTemporalOrder(influenceDiagram);
158 return influenceDiagram;
161 template <
typename GUM_SCALAR >
167 auto orderIter = order.
begin();
172 if (orderIter == order.
end())
return;
174 NodeId parentDecision = (*orderIter);
178 for (; orderIter != order.
end(); ++orderIter)
180 infdiag->
addArc(parentDecision, (*orderIter));
181 parentDecision = (*orderIter);
InfluenceDiagram< GUM_SCALAR > * generateID(Size nbrNodes, GUM_SCALAR arcDensity, GUM_SCALAR chanceNodeDensity, GUM_SCALAR utilityNodeDensity, Size max_modality=2)
Generates an influence diagram using floats.
InfluenceDiagramGenerator()
Default constructor.
Class for generating Utility Tables.
iterator begin() const
Returns an unsafe begin iterator.
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram's potential nodes cpt if necessary.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it's associate node and it's CPT.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it's node id.
void __checkTemporalOrder(InfluenceDiagram< GUM_SCALAR > *infdiag)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/ID/generator/influenceDiagramGenerator.h>
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
<agrum/BN/generator/simpleCPTGenerator.h>
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
~InfluenceDiagramGenerator()
Destructor.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it's associate node and it's UT.
Size Idx
Type for indexes.
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const iterator & end() const noexcept
Returns the unsafe end iterator.
Abstract class for generating Utility Tables.
Size NodeId
Type for node ids.
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.