40 template <
typename GUM_SCALAR >
48 template <
typename GUM_SCALAR >
57 template <
typename GUM_SCALAR >
69 template <
typename GUM_SCALAR >
72 if (
this != &source) {
91 template <
typename GUM_SCALAR >
104 template <
typename GUM_SCALAR >
111 (*potentialCpy) <<
variable(pot.first);
122 for (
Idx i = 0; i < cpyInst.
nbrDim(); i++) {
127 potentialCpy->set(cpyInst, (*pot.second)[srcInst]);
138 (*utilityCpy) <<
variable(uti.first);
150 for (
Idx i = 0; i < cpyInst.
nbrDim(); i++) {
155 utilityCpy->set(cpyInst, (*uti.second)[srcInst]);
163 template <
typename GUM_SCALAR >
165 std::stringstream output;
166 std::stringstream decisionNode;
167 std::stringstream utilityNode;
168 std::stringstream chanceNode;
169 std::stringstream arcstream;
170 output <<
"digraph \"";
173 output << this->
property(
"name") <<
"\" {" << std::endl;
174 }
catch (
NotFound&) { output <<
"no_name\" {" << std::endl; }
176 output <<
" node [bgcolor=\"#AAAAAA\", style=filled];" << std::endl;
178 decisionNode <<
"node [shape = box];" << std::endl;
180 utilityNode <<
"node [shape = diamond];" << std::endl;
181 chanceNode <<
"node [shape = ellipse];" << std::endl;
182 std::string tab =
" ";
186 chanceNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 189 utilityNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 192 decisionNode << tab <<
"\"" <<
variable(node).
name() <<
"\"" 197 arcstream << tab <<
"\"" <<
variable(node).
name() <<
"\"" 203 output << decisionNode.str() << std::endl
204 << utilityNode.str() << std::endl
205 << chanceNode.str() << std::endl
206 << arcstream.str() << std::endl
212 template <
typename GUM_SCALAR >
214 std::stringstream output;
216 output <<
"Influence Diagram{" << std::endl;
220 output <<
" arcs: " <<
dag().
sizeArcs() <<
"," << std::endl;
225 output <<
" domainSize: 10^" << dSize;
227 output <<
" domainSize: " << std::round(std::pow(10.0, dSize));
229 output << std::endl <<
"}";
241 template <
typename GUM_SCALAR >
250 template <
typename GUM_SCALAR >
259 template <
typename GUM_SCALAR >
267 template <
typename GUM_SCALAR >
279 template <
typename GUM_SCALAR >
287 template <
typename GUM_SCALAR >
295 template <
typename GUM_SCALAR >
303 template <
typename GUM_SCALAR >
312 template <
typename GUM_SCALAR >
321 template <
typename GUM_SCALAR >
330 template <
typename GUM_SCALAR >
337 template <
typename GUM_SCALAR >
344 template <
typename GUM_SCALAR >
346 const std::string& name)
const {
354 template <
typename GUM_SCALAR >
365 template <
typename GUM_SCALAR >
386 template <
typename GUM_SCALAR >
397 template <
typename GUM_SCALAR >
417 template <
typename GUM_SCALAR >
436 template <
typename GUM_SCALAR >
443 "Utility var have no state ( which implicates a " 444 "single label for data output reasons ).");
461 template <
typename GUM_SCALAR >
471 proposedId = DesiredId;
486 template <
typename GUM_SCALAR >
514 template <
typename GUM_SCALAR >
521 template <
typename GUM_SCALAR >
523 NodeId id,
const std::string& new_name) {
533 template <
typename GUM_SCALAR >
554 template <
typename GUM_SCALAR >
574 template <
typename GUM_SCALAR >
586 template <
typename GUM_SCALAR >
597 if (par != par2) graph.
addEdge(par, par2);
605 template <
typename GUM_SCALAR >
615 if (orderIter == order.
end())
return true;
617 NodeId parentDecision = (*orderIter);
621 while (orderIter != order.
end()) {
625 parentDecision = *orderIter;
637 template <
typename GUM_SCALAR >
646 mark[src] = (int)src;
649 while (!nodeFIFO.
empty()) {
650 current = nodeFIFO.
front();
654 if (mark[new_one] != -1)
657 mark[new_one] = (int)current;
659 if (new_one == dest)
break;
665 if (mark[dest] == -1)
return false;
673 template <
typename GUM_SCALAR >
684 temporalGraph->
addArc(node, chi);
689 return temporalGraph;
695 template <
typename GUM_SCALAR >
697 NodeId parentDecision)
const {
707 mark[parentDecision] =
true;
711 while (!nodeFIFO.
empty()) {
712 current = nodeFIFO.
front();
716 if (mark[new_one])
continue;
718 mark[new_one] =
true;
723 childrenSeq.
insert(new_one);
734 template <
typename GUM_SCALAR >
738 std::vector< NodeId >* decisionSequence =
new std::vector< NodeId >();
743 return decisionSequence;
750 template <
typename GUM_SCALAR >
759 for (
Idx i = 0; i < decisionOrder->size(); i++) {
762 for (
const auto par :
_dag.
parents(decisionOrder->at(i))) {
764 partialOrderedSet.
insert(par);
769 if (!partialOrderedSet.
empty())
774 decisionSet.
insert(decisionOrder->at(i));
781 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.
Class representing Influence Diagrams.
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.
gum is the global namespace for all aGrUM entities
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.