aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
spanningForestPrim.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief The Prim algorithm for computing min cost spanning trees or forests
24  *
25  * @author Jean-Philippe DUBUS & Christophe GONZALES(@AMU)
26  */
27 #ifndef GUM_SPANNING_FOREST_PRIM_H
28 #define GUM_SPANNING_FOREST_PRIM_H
29 
30 #include <agrum/tools/core/priorityQueue.h>
31 #include <agrum/tools/graphs/algorithms/spanningForest.h>
32 
33 namespace gum {
34 
35  /* ===========================================================================
36  */
37  /** @class SpanningForestPrim
38  * @brief The Prim algorithm for computing min cost spanning trees or forests
39  *
40  * Binary heap implementation : O(E log(V)) */
41  /* ===========================================================================
42  */
44  public:
45  // ############################################################################
46  /// @name Constructors / Destructors
47  // ############################################################################
48  /// @{
49 
50  /// Default constructor
51  /** Note that this algorithm takes into account the fact that the graph
52  * given
53  * in input is not connected (that, is, it may contain several connected
54  * components)
55  * @param graph the graph the spanning forest of which we look for
56  * @param costTable the cost for each edge of graph
57  * @warning note that, by aGrUM's rule, the graph and the costs are not
58  * copied but only referenced by the elimination sequence algorithm.
59  * @throws GraphError if the grand and/or the cost table are null pointers
60  */
61  SpanningForestPrim(const UndiGraph* graph,
62  const EdgeProperty< float >* costTable);
63 
64  /// Copy constructor
66 
67  /// Destructor
68  virtual ~SpanningForestPrim();
69 
70  /// @}
71 
72  // ############################################################################
73  /// @name Accessors / Modifiers
74  // ############################################################################
75  /// @{
76 
77  /// Returns the edges in a min cost spanning forest
78  /** @returns edges in the spanning forest */
80 
81  /// Construct the spanning forest
82  /** @return the spanning forest */
83  const UndiGraph& spanningForest();
84 
85  /// Returns the cost of the spanning forest
86  /** @return cost of the spanning forest */
87  float costOfSpanningForest();
88 
89  /// @}
90 
91  private:
92  /// the graph the spanning tree of which we wish to compute
94 
95  /// the costs of the edges
96  const EdgeProperty< float >& costTable__;
97 
98  /// the next edges that may be added to the spanning tree
100 
101  /// the computed spanning tree
103 
104  /// the cost of the spanning tree
106 
107  /// a Boolean indicating whether we need recompute the spanning tree
109 
110  /// Computes the spanning forest
111  void compute__();
112 
113  /// compute a spanning tree in a given connected component of graph__
114  void computeInAComponent__(const NodeId id);
115 
116  /// explore the neighborhood of a node belonging to the spanning tree
117  void exploreNode__(const NodeId id);
118 
119  /// Copy operator: private to prevent using it
121  };
122 
123 } /* namespace gum */
124 
125 #endif /* GUM_SPANNING_FOREST_PRIM_H */
void compute__()
Computes the spanning forest.
SpanningForestPrim(const SpanningForestPrim &toCopy)
Copy constructor.
void computeInAComponent__(const NodeId id)
compute a spanning tree in a given connected component of graph__
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
PriorityQueue< Edge, float > edgesToExplore__
the next edges that may be added to the spanning tree
UndiGraph spanning_tree__
the computed spanning tree
SpanningForestPrim(const UndiGraph *graph, const EdgeProperty< float > *costTable)
Default constructor.
const UndiGraph & spanningForest()
Construct the spanning forest.
The Prim algorithm for computing min cost spanning trees or forests.
bool require_computation__
a Boolean indicating whether we need recompute the spanning tree
const EdgeSet & edgesInSpanningForest()
Returns the edges in a min cost spanning forest.
float costOfSpanningForest()
Returns the cost of the spanning forest.
float spanning_tree_cost__
the cost of the spanning tree
void exploreNode__(const NodeId id)
explore the neighborhood of a node belonging to the spanning tree
virtual ~SpanningForestPrim()
Destructor.
SpanningForestPrim & operator=(const SpanningForestPrim &toCopy)
Copy operator: private to prevent using it.
const EdgeProperty< float > & costTable__
the costs of the edges
const UndiGraph & graph__
the graph the spanning tree of which we wish to compute