36 template <
typename GUM_SCALAR >
41 template <
typename GUM_SCALAR >
43 n(from.
n),
l(from.
l) {
47 template <
typename GUM_SCALAR >
52 template <
typename GUM_SCALAR >
55 return (
n == from.
n) && (
l == from.
l);
58 template <
typename GUM_SCALAR >
61 return (
n != from.
n) && (
l != from.
l);
66 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
73 u(from.
u),
v(from.
v),
l(from.
l) {
77 template <
typename GUM_SCALAR >
82 template <
typename GUM_SCALAR >
85 return (
u == from.
u) && (
l_u == from.
l_u) && (
v == from.
v)
86 && (
l_v == from.
l_v) && (
l == from.
l);
89 template <
typename GUM_SCALAR >
92 return (
u != from.
u) && (
l_u != from.
l_u) && (
v != from.
v)
93 && (
l_v != from.
l_v) && (
l != from.
l);
98 template <
typename GUM_SCALAR >
108 for (
auto iter = sys.
begin(); iter != sys.
end(); ++iter) {
110 node->
n = iter.val();
113 __idMap.insert(node->
n, iter.key());
120 for (
const auto& elt :
__nodes) {
123 for (
const auto chain : data->
n->type().slotChains()) {
124 for (
const auto inst : data->
n->getInstances(chain->id())) {
127 v = (u != data) ? data : __nodes[
__idMap[inst]];
144 template <
typename GUM_SCALAR >
156 template <
typename GUM_SCALAR >
161 for (
const auto& elt :
__nodes)
164 for (
const auto& elt :
__edges)
181 template <
typename GUM_SCALAR >
187 template <
typename GUM_SCALAR >
192 std::stringstream sBuff;
193 sBuff << node->
n->type().name();
196 for (
const auto chain : node->
n->type().slotChains()) {
197 if (chain->isMultiple()) {
198 sBuff <<
"-" << node->
n->getInstances(chain->id()).
size();
199 sBuff << chain->name();
200 size *= node->
n->getInstances(chain->id()).
size()
201 * chain->lastElt().type().variable().domainSize();
203 size *= chain->lastElt().type().variable().domainSize();
208 for (
const auto nn : node->
n->type().containerDag().nodes()) {
209 if (node->
n->type().isOutputNode(node->
n->type().get(nn))) {
211 sBuff <<
"-" << node->
n->getRefAttr(nn).size()
212 << node->
n->get(nn).name();
213 size *= node->
n->get(nn).type().variable().domainSize();
221 if (!label_map.
exists(sBuff.str())) {
226 label->
l = sBuff.str();
231 node->
l = label_map[sBuff.str()];
235 template <
typename GUM_SCALAR >
240 std::stringstream sBuff;
241 sBuff << edge->
u->type().name() <<
"-" << edge->
v->type().name();
244 for (
const auto chain : edge->
u->type().slotChains()) {
245 if (edge->
u->getInstances(chain->id()).exists(edge->
v)) {
246 sBuff <<
"-" << edge->
v->type().name() <<
"." 247 << chain->lastElt().name();
248 size *= chain->lastElt().type().variable().domainSize();
253 for (
const auto chain : edge->
v->type().slotChains())
254 if (edge->
v->getInstances(chain->id()).exists(edge->
u)) {
255 sBuff <<
"-" << edge->
u->type().name() <<
"." 256 << chain->lastElt().name();
257 size *= chain->lastElt().type().variable().domainSize();
261 if (!label_map.
exists(sBuff.str())) {
265 label->
l = sBuff.str();
271 edge->
l = label_map[sBuff.str()];
275 template <
typename GUM_SCALAR >
280 template <
typename GUM_SCALAR >
285 template <
typename GUM_SCALAR >
290 template <
typename GUM_SCALAR >
296 template <
typename GUM_SCALAR >
305 template <
typename GUM_SCALAR >
311 template <
typename GUM_SCALAR >
317 template <
typename GUM_SCALAR >
323 template <
typename GUM_SCALAR >
329 template <
typename GUM_SCALAR >
334 template <
typename GUM_SCALAR >
340 template <
typename GUM_SCALAR >
346 template <
typename GUM_SCALAR >
352 template <
typename GUM_SCALAR >
358 template <
typename GUM_SCALAR >
364 template <
typename GUM_SCALAR >
370 template <
typename GUM_SCALAR >
378 template <
typename GUM_SCALAR >
386 template <
typename GUM_SCALAR >
389 out << data.
n->name() <<
"(" << data.
l->l <<
")";
393 template <
typename GUM_SCALAR >
396 out << data.
u->name() <<
" -> " << data.
v->name() <<
"(" << data.
l->l
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
std::ostream & operator<<(std::ostream &out, const DFSCode &code)
Print code in out.
Inner class to handle data about labels in this interface graph.
Bijection< Idx, LabelData *> & labels()
Returns the bijection between LabelData and their string representation.
PRMInstance< GUM_SCALAR > * u
One of the two instance represented by this edge.
PRMInstance< GUM_SCALAR > * n
The instance represented by this node.
iterator begin()
Returns an iterator over the instances in this system.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
std::string l
The string version of this label.
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
NodeProperty< NodeData< GUM_SCALAR > *> __nodes
Data associated with a node in __graph.
HashTable< LabelData *, Set< NodeData< GUM_SCALAR > *> *> __nodeMap
Mapping between a LabelData and the set of NodeData<GUM_SCALAR> with that label.
UndiGraph __graph
The interface graph.
LabelData * l_u
The label data of u.
NodeData< GUM_SCALAR > & node(const PRMInstance< GUM_SCALAR > *i)
Returns data about a node.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
Inner class to handle data about edges in __graph.
Idx __counter
A counter used of assigning ids to labels.
PRMInstance< GUM_SCALAR > * v
The other instance represented by thus edge.
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
~InterfaceGraph()
Destructor.
bool operator==(const EdgeData< GUM_SCALAR > &from) const
Equality operator.
EdgeProperty< EdgeData< GUM_SCALAR > *> __edges
Data associated with edges in __graph.
The class for generic Hash Tables.
LabelData * l
The labal data of this edge.
Representation of a setA Set is a structure that contains arbitrary elements.
const PRMSystem< GUM_SCALAR > * __sys
The gum::prm::PRMSystem<GUM_SCALAR> represented by this interface graph.
UndiGraph & graph()
Returns the graph of this interface graph.
bool operator==(const NodeData< GUM_SCALAR > &from) const
Equality operator.
HashTable< LabelData *, Set< EdgeData< GUM_SCALAR > *> *> __edgeMap
Mapping between a LabelData and the set of EdgeData<GUM_SCALAR> with that label.
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
InterfaceGraph(const PRMSystem< GUM_SCALAR > &sys)
Default constructor.
bool operator!=(const EdgeData< GUM_SCALAR > &from) const
Difference operator.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
LabelData * l
The label of this node.
Set of pairs of elements with fast search for both elements.
Set< EdgeData< GUM_SCALAR > *> & edges(const LabelData *l)
Returns the set of nodes labelled by l.
Inner class to handle data about nodes in __graph.
Idx id
An unique identifier for this label.
bool __erase_flag
For shallow copies.
LabelData * l_v
The label data of v.
NodeId id(const PRMInstance< GUM_SCALAR > &i) const
Returns the id of i in this interface graph.
The base class for all undirected edges.
HashTable< PRMInstance< GUM_SCALAR > *, NodeId > __idMap
Mapping between PRMInstance<GUM_SCALAR> dans their id in __graph.
LabelData * label(Idx id)
Returns a label given its id.
Bijection< Idx, LabelData *> * __labels
Bijection between labels and their ids.
Base class for undirected graphs.
void __label(NodeData< GUM_SCALAR > *node, HashTable< std::string, LabelData * > &label_map)
Compute the label of node and add it to __labels if it does not exists yet. Update node with the corr...
Size size(const LabelData *l) const
Returns the number of node or edges labelled by l.
Size Idx
Type for indexes.
Size tree_width
The size in terms of tree width of the given label.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const iterator & end()
Returns a iterator at the end of the set of PRMInstance in this PRMSystem.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
EdgeData< GUM_SCALAR > & edge(NodeId u, NodeId v)
Returns data about an edge.
Set< NodeData< GUM_SCALAR > *> & nodes(const LabelData *l)
Returns the set of nodes labelled by l.
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)
InterfaceGraph & operator=(const InterfaceGraph &source)
Copy operator.
bool operator!=(const NodeData< GUM_SCALAR > &from) const
Difference operator.