43 template <
typename GUM_SCALAR >
51 template <
typename GUM_SCALAR >
60 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
75 if (
this != &source) {
94 template <
typename GUM_SCALAR >
107 template <
typename GUM_SCALAR >
114 (*potentialCpy) <<
variable(pot.first);
125 for (
Idx i = 0; i < cpyInst.
nbrDim(); i++) {
130 potentialCpy->set(cpyInst, (*pot.second)[srcInst]);
141 (*utilityCpy) <<
variable(uti.first);
153 for (
Idx i = 0; i < cpyInst.
nbrDim(); i++) {
158 utilityCpy->set(cpyInst, (*uti.second)[srcInst]);
166 template <
typename GUM_SCALAR >
168 std::stringstream output;
169 std::stringstream decisionNode;
170 std::stringstream utilityNode;
171 std::stringstream chanceNode;
172 std::stringstream arcstream;
173 output <<
"digraph \"";
176 output << this->
property(
"name") <<
"\" {" << std::endl;
177 }
catch (
NotFound&) { output <<
"no_name\" {" << std::endl; }
179 output <<
" node [bgcolor=\"#AAAAAA\", style=filled];" << std::endl;
181 decisionNode <<
"node [shape = box];" << std::endl;
183 utilityNode <<
"node [shape = diamond];" << std::endl;
184 chanceNode <<
"node [shape = ellipse];" << std::endl;
185 std::string tab =
" ";
189 chanceNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 192 utilityNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 195 decisionNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 200 arcstream << tab <<
"\"" <<
variable(node).
name() <<
"\"" 206 output << decisionNode.str() << std::endl
207 << utilityNode.str() << std::endl
208 << chanceNode.str() << std::endl
209 << arcstream.str() << std::endl
215 template <
typename GUM_SCALAR >
217 std::stringstream output;
219 output <<
"Influence Diagram{" << std::endl;
223 output <<
" arcs: " <<
dag().
sizeArcs() <<
"," << std::endl;
228 output <<
" domainSize: 10^" << dSize;
230 output <<
" domainSize: " << std::round(std::pow(10.0, dSize));
232 output << std::endl <<
"}";
244 template <
typename GUM_SCALAR >
253 template <
typename GUM_SCALAR >
262 template <
typename GUM_SCALAR >
270 template <
typename GUM_SCALAR >
282 template <
typename GUM_SCALAR >
290 template <
typename GUM_SCALAR >
298 template <
typename GUM_SCALAR >
306 template <
typename GUM_SCALAR >
315 template <
typename GUM_SCALAR >
324 template <
typename GUM_SCALAR >
333 template <
typename GUM_SCALAR >
340 template <
typename GUM_SCALAR >
347 template <
typename GUM_SCALAR >
349 const std::string& name)
const {
357 template <
typename GUM_SCALAR >
368 template <
typename GUM_SCALAR >
389 template <
typename GUM_SCALAR >
400 template <
typename GUM_SCALAR >
420 template <
typename GUM_SCALAR >
439 template <
typename GUM_SCALAR >
446 "Utility var have no state ( which implicates a " 447 "single label for data output reasons ).");
464 template <
typename GUM_SCALAR >
474 proposedId = DesiredId;
489 template <
typename GUM_SCALAR >
517 template <
typename GUM_SCALAR >
524 template <
typename GUM_SCALAR >
526 NodeId id,
const std::string& new_name) {
536 template <
typename GUM_SCALAR >
557 template <
typename GUM_SCALAR >
577 template <
typename GUM_SCALAR >
589 template <
typename GUM_SCALAR >
600 if (par != par2) graph.
addEdge(par, par2);
608 template <
typename GUM_SCALAR >
618 if (orderIter == order.
end())
return true;
620 NodeId parentDecision = (*orderIter);
624 while (orderIter != order.
end()) {
628 parentDecision = *orderIter;
640 template <
typename GUM_SCALAR >
649 mark[src] = (int)src;
652 while (!nodeFIFO.
empty()) {
653 current = nodeFIFO.
front();
657 if (mark[new_one] != -1)
660 mark[new_one] = (int)current;
662 if (new_one == dest)
break;
668 if (mark[dest] == -1)
return false;
676 template <
typename GUM_SCALAR >
687 temporalGraph->
addArc(node, chi);
692 return temporalGraph;
698 template <
typename GUM_SCALAR >
700 NodeId parentDecision)
const {
710 mark[parentDecision] =
true;
714 while (!nodeFIFO.
empty()) {
715 current = nodeFIFO.
front();
719 if (mark[new_one])
continue;
721 mark[new_one] =
true;
726 childrenSeq.
insert(new_one);
737 template <
typename GUM_SCALAR >
741 std::vector< NodeId >* decisionSequence =
new std::vector< NodeId >();
746 return decisionSequence;
753 template <
typename GUM_SCALAR >
762 for (
Idx i = 0; i < decisionOrder->size(); i++) {
765 for (
const auto par :
_dag.
parents(decisionOrder->at(i))) {
767 partialOrderedSet.
insert(par);
772 if (!partialOrderedSet.
empty())
777 decisionSet.
insert(decisionOrder->at(i));
784 for (
const auto node : nodeList)
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
virtual const VariableNodeMap & variableNodeMap() const
Returns a constant reference to the VariableNodeMap of this Influence Diagram.
aGrUM's Potential is a multi-dimensional array with tensor operators.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable's id and their CPT.
Virtual base class for PGMs using a DAG.
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 empty() const noexcept
Indicates whether the set is the empty set.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his childs.
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.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
std::string toString() const
gum::DAG * getDecisionGraph() const
Returns the temporal Graph.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Container used to map discrete variables with nodes.
Size decisionNodeSize() const
Returns the number of decision nodes.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
virtual const DiscreteVariable & variableFromName(const std::string &name) const
Getter by name.
void changeVariableName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
Size chanceNodeSize() const
Returns the number of chance nodes.
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
bool exists(NodeId id) const
Return true if id matches a node.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
std::vector< NodeId > * getDecisionOrder() const
Returns the sequence of decision nodes in the directed path.
VariableNodeMap __variableMap
Mapping between id and variable.
void erase(const Key &k)
Erases an element from the set.
Base class for discrete random variable.
Generic doubly linked lists.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size utilityNodeSize() const
Returns the number of utility nodes.
void popFront()
Removes the first element of a List, if any.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable's id and their utility table.
NodeId head() const
returns the head of the arc
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
The class for generic Hash Tables.
std::string toDot() const
Idx val(Idx i) const
Returns the current value of the variable at position i.
void erase(NodeId id)
Removes a var and it's id of this mapping. The pointer is deleted.
Representation of a setA Set is a structure that contains arbitrary elements.
const List< NodeSet > & getPartialTemporalOrder(bool clear=true) const
Returns partial temporal ordering.
virtual Size domainSize() const =0
Size size() const
Returns the number of variables in this Directed Graphical Model.
DAG _dag
The DAG of this Directed Graphical Model.
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...
List< NodeSet > __temporalOrder
The temporal order.
const std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
void inc()
Operator increment.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
virtual ~InfluenceDiagram()
Destructor.
Base class for all aGrUM's exceptions.
Multidimensional matrix stored as an array in memory.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
NodeId idFromName(const std::string &name) const
Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
virtual void _moralGraph(UndiGraph &graph) const
Returns the moral graph of this InfluenceDiagram.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
InfluenceDiagram< GUM_SCALAR > & operator=(const InfluenceDiagram< GUM_SCALAR > &source)
Copy Operator.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Class for assigning/browsing values to tuples of discrete variables.
Val & front() const
Returns a reference to first element of a list, if any.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram's potential nodes cpt if necessary.
void setFirst()
Assign the first values to the tuple of the Instantiation.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it's associate node and it's UT.
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
Base class for undirected graphs.
InfluenceDiagram()
Default constructor.
NodeId add(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it's associate node and it's CPT.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
NodeId nextNodeId() const
returns a new node id, not yet used by any node
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
virtual NodeId nodeId(const DiscreteVariable &var) const
Return id node from discrete var pointer.
double log10DomainSize() const
Size size() const noexcept
Returns the number of elements in the set.
const DiscreteVariable & variableFromName(const std::string &name) const
const iterator & end() const noexcept
Returns the unsafe end iterator.
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
void _removeTables()
Removing ancient table.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
NodeId tail() const
returns the tail of the arc
#define GUM_ERROR(type, msg)
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it's node id.
bool end() const
Returns true if the Instantiation reached the end.
Class representing an Influence Diagram.
void insert(const Key &k)
Insert an element at the end of the sequence.