![]() |
aGrUM
0.14.2
|
Class for node sets in graph. More...
#include <nodeGraphPart.h>
Public Attributes | |
Signaler1< NodeId > | onNodeAdded |
Signaler1< NodeId > | onNodeDeleted |
Public Member Functions | |
Constructors / Destructors | |
NodeGraphPart (Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true) | |
default constructor More... | |
NodeGraphPart (const NodeGraphPart &s) | |
copy constructor More... | |
virtual | ~NodeGraphPart () |
destructor More... | |
Operators | |
NodeGraphPart & | operator= (const NodeGraphPart &p) |
copy operator More... | |
bool | operator== (const NodeGraphPart &p) const |
check whether two NodeGraphParts contain the same nodes More... | |
bool | operator!= (const NodeGraphPart &p) const |
check whether two NodeGraphParts contain different nodes More... | |
Accessors/Modifiers | |
void | populateNodes (const NodeGraphPart &s) |
populateNodes clears *this and fills it with the same nodes as "s" More... | |
template<typename T > | |
void | populateNodesFromProperty (const NodeProperty< T > &h) |
populateNodesFromProperty clears *this and fills it with the keys of "h" More... | |
NodeId | nextNodeId () const |
returns a new node id, not yet used by any node More... | |
virtual NodeId | addNode () |
insert a new node and return its id More... | |
std::vector< NodeId > | addNodes (Size n) |
insert n nodes More... | |
virtual void | addNodeWithId (const NodeId id) |
try to insert a node with the given id More... | |
virtual void | eraseNode (const NodeId id) |
erase the node with the given id More... | |
bool | existsNode (const NodeId id) const |
returns true iff the NodeGraphPart contains the given nodeId More... | |
bool | exists (const NodeId id) const |
alias for existsNode More... | |
bool | emptyNodes () const |
indicates whether there exists nodes in the NodeGraphPart More... | |
bool | empty () const |
alias for emptyNodes More... | |
virtual void | clearNodes () |
remove all the nodes from the NodeGraphPart More... | |
virtual void | clear () |
alias for clearNodes More... | |
Size | sizeNodes () const |
returns the number of nodes in the NodeGraphPart More... | |
Size | size () const |
alias for sizeNodes More... | |
NodeId | bound () const |
returns a number n such that all node ids are strictly lower than n More... | |
NodeSet | asNodeSet () const |
returns a copy of the set of nodes represented by the NodeGraphPart More... | |
const NodeGraphPart & | nodes () const |
return *this as a NodeGraphPart More... | |
node_iterator_safe | beginSafe () const |
a begin iterator to parse the set of nodes contained in the NodeGraphPart More... | |
const node_iterator_safe & | endSafe () const noexcept |
the end iterator to parse the set of nodes contained in the NodeGraphPart More... | |
node_iterator | begin () const noexcept |
a begin iterator to parse the set of nodes contained in the NodeGraphPart More... | |
const node_iterator & | end () const noexcept |
the end iterator to parse the set of nodes contained in the NodeGraphPart More... | |
std::string | toString () const |
a function to display the set of nodes More... | |
template<typename VAL > | |
NodeProperty< VAL > | nodesProperty (VAL(*f)(const NodeId &), Size size=0) const |
a method to create a HashTable with key:NodeId and value:VAL More... | |
template<typename VAL > | |
NodeProperty< VAL > | nodesProperty (const VAL &a, Size size=0) const |
a method to create a hashMap with key:NodeId and value:VAL More... | |
template<typename VAL > | |
List< VAL > | listMapNodes (VAL(*f)(const NodeId &)) const |
a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x)) More... | |
Public Types | |
typedef NodeGraphPartIterator | NodeIterator |
typedef NodeGraphPartIterator | NodeConstIterator |
typedef NodeGraphPartIteratorSafe | NodeIteratorSafe |
typedef NodeGraphPartIteratorSafe | NodeConstIteratorSafe |
using | node_iterator = NodeGraphPartIterator |
types for STL compliance More... | |
using | node_const_iterator = NodeGraphPartIterator |
types for STL compliance More... | |
using | node_iterator_safe = NodeGraphPartIteratorSafe |
types for STL compliance More... | |
using | node_const_iterator_safe = NodeGraphPartIteratorSafe |
types for STL compliance More... | |
Friends | |
class | NodeGraphPartIterator |
class | NodeGraphPartIteratorSafe |
class | gum_tests::NodeGraphPartTestSuite |
to enable testunits to use __check More... | |
Class for node sets in graph.
NodeGraphPart represents the set of nodes of all the graphs. It is built to be as light as possible and it implements its own NodeId factory. The set of NodeId is 0 ... (__bound-1) minus the NodeIds in __holes.
Definition at line 253 of file nodeGraphPart.h.
types for STL compliance
Definition at line 258 of file nodeGraphPart.h.
types for STL compliance
Definition at line 260 of file nodeGraphPart.h.
types for STL compliance
Definition at line 257 of file nodeGraphPart.h.
types for STL compliance
Definition at line 259 of file nodeGraphPart.h.
Definition at line 267 of file nodeGraphPart.h.
Definition at line 269 of file nodeGraphPart.h.
Definition at line 266 of file nodeGraphPart.h.
Definition at line 268 of file nodeGraphPart.h.
|
explicit |
default constructor
A NodeGrphPart does not store all its nodes. To be lighter in terms of memory consumption, it store its maximal NodeId and the set of NodeIds between 0 and this maximum that do not actually belong to the set of its nodes (the so-called set of holes). In practice, it turns out that the set of holes is most often very small.
holes_size | the size of the hash table used to store all holes |
holes_resize_policy | the resizing policy of this hash table |
Definition at line 35 of file nodeGraphPart.cpp.
References __holes, and __updateEndIteratorSafe().
gum::NodeGraphPart::NodeGraphPart | ( | const NodeGraphPart & | s | ) |
copy constructor
s | the NodeGraphPart to be copied |
Definition at line 43 of file nodeGraphPart.cpp.
References __holes, and __updateEndIteratorSafe().
|
virtual |
destructor
Definition at line 55 of file nodeGraphPart.cpp.
References __holes.
|
private |
to add a hole.
Definition at line 74 of file nodeGraphPart.cpp.
References __boundVal, __holes, __holes_resize_policy, __holes_size, __updateEndIteratorSafe(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), and gum::Set< Key, Alloc >::insert().
|
private |
code for clearing nodes (called twice)
Definition at line 152 of file nodeGraphPart.cpp.
References __boundVal, __holes, __inHoles(), __updateEndIteratorSafe(), bound(), GUM_EMIT1, and onNodeDeleted.
|
private |
to delete hole.
Definition at line 236 of file nodeGraphPart_inl.h.
Referenced by addNodeWithId().
Definition at line 374 of file nodeGraphPart_inl.h.
Referenced by __clearNodes(), gum::NodeGraphPartIterator::_validate(), addNodeWithId(), and toString().
|
private |
Definition at line 379 of file nodeGraphPart_inl.h.
|
private |
updating endIterator (always at __max+1)
Definition at line 322 of file nodeGraphPart_inl.h.
Referenced by __addHole(), __clearNodes(), addNodeWithId(), NodeGraphPart(), and populateNodes().
|
virtual |
insert a new node and return its id
Reimplemented in gum::CliqueGraph.
Definition at line 250 of file nodeGraphPart_inl.h.
References GUM_EMIT1.
Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::__addChild(), gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::__addInterface2Dag(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::__addNode(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__addTypes2Dag(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddNodesToDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::insert(), and gum::LeafAggregator::update().
insert n nodes
n | the number of nodes to add |
Definition at line 268 of file nodeGraphPart_inl.h.
|
virtual |
try to insert a node with the given id
DuplicateElement | exception if the id already exists |
Definition at line 129 of file nodeGraphPart.cpp.
References __boundVal, __eraseHole(), __holes, __holes_resize_policy, __holes_size, __inHoles(), __updateEndIteratorSafe(), GUM_EMIT1, GUM_ERROR, gum::Set< Key, Alloc >::insert(), and onNodeAdded.
Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__computeInAComponent(), gum::learning::genericBNLearner::__learnDAG(), gum::learning::genericBNLearner::__prepare_miic_3off2(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::prm::gspan::Pattern::addNodeWithLabel(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::InterfaceGraph(), gum::learning::Miic::learnStructure(), gum::UndiGraph::partialUndiGraph(), and gum::learning::StructuralConstraintDAG::StructuralConstraintDAG().
INLINE NodeSet gum::NodeGraphPart::asNodeSet | ( | ) | const |
returns a copy of the set of nodes represented by the NodeGraphPart
Definition at line 358 of file nodeGraphPart_inl.h.
References gum::Set< Key, Alloc >::insert().
Referenced by gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder().
|
noexcept |
a begin iterator to parse the set of nodes contained in the NodeGraphPart
Definition at line 330 of file nodeGraphPart_inl.h.
References gum::NodeGraphPartIterator::_validate().
Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::parent().
INLINE NodeGraphPartIteratorSafe gum::NodeGraphPart::beginSafe | ( | ) | const |
a begin iterator to parse the set of nodes contained in the NodeGraphPart
Definition at line 316 of file nodeGraphPart_inl.h.
References gum::NodeGraphPartIterator::_validate().
INLINE NodeId gum::NodeGraphPart::bound | ( | ) | const |
returns a number n such that all node ids are strictly lower than n
Definition at line 305 of file nodeGraphPart_inl.h.
Referenced by __clearNodes(), gum::StaticTriangulation::__computeEliminationTree(), gum::NodeGraphPartIterator::_setPos(), and gum::NodeGraphPartIterator::_validate().
|
virtual |
alias for clearNodes
Reimplemented in gum::MixedGraph, gum::DiGraph, gum::UndiGraph, and gum::CliqueGraph.
Definition at line 314 of file nodeGraphPart_inl.h.
Referenced by populateNodes().
|
virtual |
remove all the nodes from the NodeGraphPart
Definition at line 307 of file nodeGraphPart_inl.h.
Referenced by gum::DiGraph::clear(), gum::UndiGraph::clear(), gum::MixedGraph::clear(), and gum::MixedGraph::operator=().
INLINE bool gum::NodeGraphPart::empty | ( | ) | const |
alias for emptyNodes
Definition at line 303 of file nodeGraphPart_inl.h.
Referenced by gum::prm::gspan::Pattern::remove().
INLINE bool gum::NodeGraphPart::emptyNodes | ( | ) | const |
indicates whether there exists nodes in the NodeGraphPart
Definition at line 301 of file nodeGraphPart_inl.h.
|
noexcept |
the end iterator to parse the set of nodes contained in the NodeGraphPart
Definition at line 336 of file nodeGraphPart_inl.h.
|
noexcept |
the end iterator to parse the set of nodes contained in the NodeGraphPart
Definition at line 326 of file nodeGraphPart_inl.h.
|
virtual |
erase the node with the given id
If the NodeGraphPart does not contain the nodeId, then nothing is done. In particular, no exception is raised. However, the signal onNodeDeleted is fired only if a node is effectively removed.
Reimplemented in gum::MixedGraph, gum::DiGraph, gum::UndiGraph, and gum::CliqueGraph.
Definition at line 293 of file nodeGraphPart_inl.h.
References GUM_EMIT1.
Referenced by gum::LeafAggregator::__removeContext(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::UndiGraph::eraseNode(), gum::DiGraph::eraseNode(), and gum::MixedGraph::eraseNode().
alias for existsNode
Definition at line 289 of file nodeGraphPart_inl.h.
Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::prm::ClassBayesNet< GUM_SCALAR >::__get(), gum::DAG::__hasDirectedPath(), gum::learning::genericBNLearner::__learnDAG(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::NodeGraphPartIterator::_setPos(), gum::prm::gspan::Pattern::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), and gum::prm::gspan::Pattern::exists().
returns true iff the NodeGraphPart contains the given nodeId
Definition at line 283 of file nodeGraphPart_inl.h.
Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__compute(), gum::SpanningForestPrim::__computeInAComponent(), gum::SpanningForestPrim::__exploreNode(), gum::OrderedEliminationSequenceStrategy::__isOrderNeeded(), gum::PartialOrderedEliminationSequenceStrategy::_isPartialOrderNeeded(), gum::OrderedEliminationSequenceStrategy::eliminationUpdate(), gum::DefaultPartialOrderedEliminationSequenceStrategy::eliminationUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), gum::UndiGraph::partialUndiGraph(), gum::OrderedEliminationSequenceStrategy::setOrder(), and gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder().
List< VAL > gum::NodeGraphPart::listMapNodes | ( | VAL(*)(const NodeId &) | f | ) | const |
a method to create a list of VAL from a set of nodes (using for every nodee, say x, the VAL f(x))
f | a function assigning a VAL to any node |
INLINE NodeId gum::NodeGraphPart::nextNodeId | ( | ) | const |
returns a new node id, not yet used by any node
Definition at line 223 of file nodeGraphPart_inl.h.
Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_addNode().
INLINE const NodeGraphPart & gum::NodeGraphPart::nodes | ( | ) | const |
return *this as a NodeGraphPart
Definition at line 370 of file nodeGraphPart_inl.h.
Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__compute(), gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__threadUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::StaticTriangulation::fillIns(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::UndiGraph::hasUndirectedCycle(), gum::DAG::moralGraph(), gum::MarkovBlanket::nodes(), gum::EssentialGraph::nodes(), gum::prm::gspan::Pattern::nodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::UndiGraph::toDot(), gum::DiGraph::toDot(), and gum::MixedGraph::toDot().
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty | ( | VAL(*)(const NodeId &) | f, |
Size | size = 0 |
||
) | const |
a method to create a HashTable with key:NodeId and value:VAL
VAL are computed from the nodes using for all node x, VAL f(x). This method is a wrapper of the same method in HashTable.
f | a function assigning a VAL to any node |
size | an optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you. |
Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), and gum::UndiGraph::hasUndirectedCycle().
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty | ( | const VAL & | a, |
Size | size = 0 |
||
) | const |
a method to create a hashMap with key:NodeId and value:VAL
for all nodes, the value stored is a. This method is a wrapper of the same method in HashTable.
a | the default value assigned to each edge in the returned Property |
size | an optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you. |
INLINE bool gum::NodeGraphPart::operator!= | ( | const NodeGraphPart & | p | ) | const |
check whether two NodeGraphParts contain different nodes
p | the NodeGraphPart to be compared with "this" |
Definition at line 354 of file nodeGraphPart_inl.h.
References gum::NodeGraphPartIterator::operator==().
INLINE NodeGraphPart & gum::NodeGraphPart::operator= | ( | const NodeGraphPart & | p | ) |
copy operator
p | the NodeGraphPart to be copied |
Definition at line 216 of file nodeGraphPart_inl.h.
Referenced by gum::UndiGraph::operator=(), gum::DiGraph::operator=(), and gum::MixedGraph::operator=().
INLINE bool gum::NodeGraphPart::operator== | ( | const NodeGraphPart & | p | ) | const |
check whether two NodeGraphParts contain the same nodes
p | the NodeGraphPart to be compared with "this" |
Definition at line 340 of file nodeGraphPart_inl.h.
References __boundVal, and __holes.
Referenced by gum::UndiGraph::operator==(), gum::DiGraph::operator==(), and gum::MixedGraph::operator==().
void gum::NodeGraphPart::populateNodes | ( | const NodeGraphPart & | s | ) |
populateNodes clears *this and fills it with the same nodes as "s"
populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.
s | the NodeGraphPart to be copied |
Definition at line 61 of file nodeGraphPart.cpp.
References __boundVal, __holes, __holes_resize_policy, __holes_size, __updateEndIteratorSafe(), and clear().
Referenced by gum::DAGmodel::__moralGraph(), and gum::DAG::moralGraph().
void gum::NodeGraphPart::populateNodesFromProperty | ( | const NodeProperty< T > & | h | ) |
populateNodesFromProperty clears *this and fills it with the keys of "h"
populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.
INLINE Size gum::NodeGraphPart::size | ( | ) | const |
alias for sizeNodes
Definition at line 281 of file nodeGraphPart_inl.h.
Referenced by gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::StaticTriangulation::__computeRecursiveThinning(), gum::OrderedEliminationSequenceStrategy::__isOrderNeeded(), gum::DiGraph::__topologicalOrder(), gum::StaticTriangulation::__triangulate(), gum::PartialOrderedEliminationSequenceStrategy::_isPartialOrderNeeded(), gum::BarrenNodesFinder::barrenNodes(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::StaticTriangulation::setGraph(), gum::MarkovBlanket::size(), gum::EssentialGraph::size(), gum::DAGmodel::size(), gum::prm::gspan::Pattern::size(), gum::StaticTriangulation::StaticTriangulation(), and gum::UndiGraph::toDot().
INLINE Size gum::NodeGraphPart::sizeNodes | ( | ) | const |
returns the number of nodes in the NodeGraphPart
Definition at line 277 of file nodeGraphPart_inl.h.
Referenced by gum::BinaryJoinTreeConverterDefault::__markConnectedComponent(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::EliminationSequenceStrategy::setGraph(), gum::MarkovBlanket::sizeNodes(), and gum::EssentialGraph::sizeNodes().
std::string gum::NodeGraphPart::toString | ( | ) | const |
a function to display the set of nodes
Definition at line 102 of file nodeGraphPart.cpp.
References __boundVal, and __inHoles().
Referenced by gum::DiGraph::toString(), gum::UndiGraph::toString(), and gum::MixedGraph::toString().
|
friend |
to enable testunits to use __check
Definition at line 467 of file nodeGraphPart.h.
|
friend |
Definition at line 462 of file nodeGraphPart.h.
|
friend |
Definition at line 463 of file nodeGraphPart.h.
|
private |
the id below which NodeIds may belong to the NodeGraphPart
Definition at line 511 of file nodeGraphPart.h.
Referenced by __addHole(), __clearNodes(), addNodeWithId(), operator==(), populateNodes(), and toString().
|
private |
the end iterator (used to speed-up parsings of the NodeGraphPart)
Definition at line 508 of file nodeGraphPart.h.
|
private |
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
Definition at line 499 of file nodeGraphPart.h.
Referenced by __addHole(), __clearNodes(), addNodeWithId(), NodeGraphPart(), operator==(), populateNodes(), and ~NodeGraphPart().
|
private |
value for __holes configuration
Definition at line 505 of file nodeGraphPart.h.
Referenced by __addHole(), addNodeWithId(), and populateNodes().
|
private |
value for __holes configuration
Definition at line 502 of file nodeGraphPart.h.
Referenced by __addHole(), addNodeWithId(), and populateNodes().
Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded |
Definition at line 271 of file nodeGraphPart.h.
Referenced by addNodeWithId().
Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted |
Definition at line 272 of file nodeGraphPart.h.
Referenced by __clearNodes().