58 template < GUM_Numeric GUM_SCALAR >
63 template < GUM_Numeric GUM_SCALAR >
68 template < GUM_Numeric GUM_SCALAR >
73 template < GUM_Numeric GUM_SCALAR >
75 return (
n == from.
n) && (
l == from.
l);
78 template < GUM_Numeric GUM_SCALAR >
80 return (
n != from.
n) && (
l != from.
l);
85 template < GUM_Numeric GUM_SCALAR >
90 template < GUM_Numeric GUM_SCALAR >
92 u(from.
u),
v(from.
v),
l(from.
l) {
96 template < GUM_Numeric GUM_SCALAR >
101 template < GUM_Numeric GUM_SCALAR >
103 return (
u == from.
u) && (
l_u == from.
l_u) && (
v == from.
v) && (
l_v == from.
l_v)
107 template < GUM_Numeric GUM_SCALAR >
109 return (
u != from.
u) && (
l_u != from.
l_u) && (
v != from.
v) && (
l_v != from.
l_v)
115 template < GUM_Numeric GUM_SCALAR >
123 for (
auto iter = sys.
begin(); iter != sys.
end(); ++iter) {
125 node->n = iter.val();
127 _graph_.addNodeWithId(iter.key());
135 for (
const auto& elt:
_nodes_) {
138 for (
const auto chain: data->
n->type().slotChains()) {
139 for (
const auto inst: data->
n->getInstances(chain->id())) {
158 template < GUM_Numeric GUM_SCALAR >
168 template < GUM_Numeric GUM_SCALAR >
193 template < GUM_Numeric GUM_SCALAR >
199 template < GUM_Numeric GUM_SCALAR >
203 std::string sBuff =
node->n->type().name();
206 for (
const auto chain:
node->n->type().slotChains()) {
207 if (chain->isMultiple()) {
208 sBuff += std::format(
"-{}{}",
node->n->getInstances(chain->id()).size(), chain->name());
209 size *=
node->n->getInstances(chain->id()).size()
210 * chain->lastElt().type().variable().domainSize();
212 size *= chain->lastElt().type().variable().domainSize();
217 for (
const auto nn:
node->n->type().containerDag().nodes()) {
218 if (
node->n->type().isOutputNode(
node->n->type().get(nn))) {
219 if (
node->n->hasRefAttr(nn) &&
node->n->exists(nn)) {
221 += std::format(
"-{}{}",
node->n->getRefAttr(nn).size(),
node->n->get(nn).name());
222 size *=
node->n->get(nn).type().variable().domainSize();
228 auto p_lm = label_map.
tryGet(sBuff);
237 p_lm = label_map.
tryGet(sBuff);
244 template < GUM_Numeric GUM_SCALAR >
248 std::string sBuff = std::format(
"{}-{}",
edge->u->type().name(),
edge->v->type().name());
251 for (
const auto chain:
edge->u->type().slotChains()) {
252 if (
edge->u->getInstances(chain->id()).exists(
edge->v)) {
253 sBuff += std::format(
"-{}.{}",
edge->v->type().name(), chain->lastElt().name());
254 size *= chain->lastElt().type().variable().domainSize();
259 for (
const auto chain:
edge->v->type().slotChains())
260 if (
edge->v->getInstances(chain->id()).exists(
edge->u)) {
261 sBuff += std::format(
"-{}.{}",
edge->u->type().name(), chain->lastElt().name());
262 size *= chain->lastElt().type().variable().domainSize();
266 auto p_elm = label_map.
tryGet(sBuff);
275 p_elm = label_map.
tryGet(sBuff);
282 template < GUM_Numeric GUM_SCALAR >
287 template < GUM_Numeric GUM_SCALAR >
292 template < GUM_Numeric GUM_SCALAR >
297 template < GUM_Numeric GUM_SCALAR >
302 template < GUM_Numeric GUM_SCALAR >
308 template < GUM_Numeric GUM_SCALAR >
313 template < GUM_Numeric GUM_SCALAR >
319 template < GUM_Numeric GUM_SCALAR >
324 template < GUM_Numeric GUM_SCALAR >
330 template < GUM_Numeric GUM_SCALAR >
335 template < GUM_Numeric GUM_SCALAR >
340 template < GUM_Numeric GUM_SCALAR >
345 template < GUM_Numeric GUM_SCALAR >
351 template < GUM_Numeric GUM_SCALAR >
357 template < GUM_Numeric GUM_SCALAR >
362 template < GUM_Numeric GUM_SCALAR >
367 template < GUM_Numeric GUM_SCALAR >
369 if (
auto p =
_edges_.tryGet(
Edge(u, v)))
return *(*p);
373 template < GUM_Numeric GUM_SCALAR >
375 if (
auto p =
_edges_.tryGet(
Edge(u, v)))
return *(*p);
379 template < GUM_Numeric GUM_SCALAR >
381 out << data.
n->name() <<
"(" << data.
l->
l <<
")";
385 template < GUM_Numeric GUM_SCALAR >
387 out << data.
u->name() <<
" -> " << data.
v->name() <<
"(" << data.
l->
l <<
")";
Set of pairs of elements with fast search for both elements.
The base class for all undirected edges.
Exception : fatal (unknown ?) error.
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
Base class for undirected graphs.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
const iterator & end()
Returns an iterator at the end of the set of PRMInstance in this PRMSystem.
iterator begin()
Returns an iterator over the instances in this system.
Inner class to handle data about edges in graph.
bool operator!=(const EdgeData< GUM_SCALAR > &from) const
Difference operator.
bool operator==(const EdgeData< GUM_SCALAR > &from) const
Equality operator.
PRMInstance< GUM_SCALAR > * v
The other instance represented by thus edge.
PRMInstance< GUM_SCALAR > * u
One of the two instance represented by this edge.
LabelData * l_u
The label data of u.
LabelData * l
The labal data of this edge.
LabelData * l_v
The label data of v.
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
Set< NodeData< GUM_SCALAR > * > & nodes(const LabelData *l)
Returns the set of nodes labelled by l.
const PRMSystem< GUM_SCALAR > * _sys_
The gum::prm::PRMSystem<GUM_SCALAR> represented by this interface graph.
NodeProperty< NodeData< GUM_SCALAR > * > _nodes_
Data associated with a node in graph.
UndiGraph & internalGraph()
Returns the graph of this interface graph.
Size size(const LabelData *l) const
Returns the number of node or edges labelled by l.
UndiGraph _graph_
The interface graph.
InterfaceGraph & operator=(const InterfaceGraph &source)
Copy operator.
Idx _counter_
A counter used of assigning ids to labels.
InterfaceGraph(const PRMSystem< GUM_SCALAR > &sys)
Default constructor.
NodeData< GUM_SCALAR > & node(const PRMInstance< GUM_SCALAR > *i)
Returns data about a node.
HashTable< LabelData *, Set< NodeData< GUM_SCALAR > * > * > _nodeMap_
Mapping between a LabelData and the set of NodeData<GUM_SCALAR> with that label.
LabelData * label(Idx id)
Returns a label given its id.
EdgeProperty< EdgeData< GUM_SCALAR > * > _edges_
Data associated with edges in graph.
EdgeData< GUM_SCALAR > & edge(NodeId u, NodeId v)
Returns data about an edge.
~InterfaceGraph()
Destructor.
bool _erase_flag_
For shallow copies.
HashTable< LabelData *, Set< EdgeData< GUM_SCALAR > * > * > _edgeMap_
Mapping between a LabelData and the set of EdgeData<GUM_SCALAR> with that label.
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 correc...
NodeId id(const PRMInstance< GUM_SCALAR > &i) const
Returns the id of i in this interface graph.
Bijection< Idx, LabelData * > * _labels_
Bijection between labels and their ids.
Set< EdgeData< GUM_SCALAR > * > & edges(const LabelData *l)
Returns the set of nodes labelled by l.
Bijection< Idx, LabelData * > & labels()
Returns the bijection between LabelData and their string representation.
HashTable< PRMInstance< GUM_SCALAR > *, NodeId > _idMap_
Mapping between PRMInstance<GUM_SCALAR> dans their id in graph.
Inner class to handle data about nodes in graph.
bool operator==(const NodeData< GUM_SCALAR > &from) const
Equality operator.
PRMInstance< GUM_SCALAR > * n
The instance represented by this node.
bool operator!=(const NodeData< GUM_SCALAR > &from) const
Difference operator.
LabelData * l
The label of this node.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Headers of InterfaceGraph.
std::ostream & operator<<(std::ostream &out, const DFSCode &code)
Print code in out.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities
Inner class to handle data about labels in this interface graph.
std::string l
The string version of this label.