aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
UGmodel.cpp
Go to the documentation of this file.
1 
24 
25 #ifdef GUM_NO_INLINE
27 #endif /* GUM_NO_INLINE */
28 
29 namespace gum {
30  UGmodel::UGmodel() { GUM_CONSTRUCTOR(UGmodel); }
31 
32  UGmodel::UGmodel(const UGmodel& from) : _graph(from._graph) {
33  GUM_CONS_CPY(UGmodel);
34  }
35 
36  UGmodel::~UGmodel() { GUM_DESTRUCTOR(UGmodel); }
37 
39  if (this != &source) {
41  _graph = source._graph;
42  }
43 
44  return *this;
45  }
46 
47  bool UGmodel::hasSameStructure(const UGmodel& other) {
48  if (this == &other) return true;
49 
50  if (size() != other.size()) return false;
51 
52  if (sizeEdges() != other.sizeEdges()) return false;
53 
54  for (const auto& nid: nodes()) {
55  try {
56  other.idFromName(variable(nid).name());
57  } catch (NotFound) { return false; }
58  }
59 
60  for (const auto& edge: edges()) {
61  if (!other.edges().exists(
62  Edge(other.idFromName(variable(edge.first()).name()),
63  other.idFromName(variable(edge.second()).name()))))
64  return false;
65  }
66 
67  return true;
68  }
69 } // namespace gum
UGmodel & operator=(const UGmodel &source)
Private copy operator.
Definition: UGmodel.cpp:38
UndiGraph _graph
The DAG of this Directed Graphical Model.
Definition: UGmodel.h:137
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
const EdgeSet & edges() const
returns the neighbours of a node as set of nodes
Definition: UGmodel_inl.h:44
virtual ~UGmodel()
Destructor.
Definition: UGmodel.cpp:36
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
UGmodel()
Default constructor.
Definition: UGmodel.cpp:30
Virtual base class for PGMs using a undirected graph.
Definition: UGmodel.h:46
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:609
GraphicalModel & operator=(const GraphicalModel &source)
Private copy operator.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:53
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Definition: UGmodel_inl.h:42
The base class for all undirected edges.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: UGmodel_inl.h:39
bool hasSameStructure(const UGmodel &other)
Definition: UGmodel.cpp:47