All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SkaterPartition.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/sa/core/SkaterPartition.h
22 
23  \brief This file contains a class that represents the skater partition operation.
24 
25  \reference Adapted from TerraLib4.
26 */
27 
28 #ifndef __TERRALIB_SA_INTERNAL_SKATERPARTITION_H
29 #define __TERRALIB_SA_INTERNAL_SKATERPARTITION_H
30 
31 // Terralib Includes
32 #include "SkaterParams.h"
33 #include "../Config.h"
34 
35 // STL Includes
36 #include <memory>
37 
38 namespace te
39 {
40  //forward declarations
41  namespace graph
42  {
43  class AbstractGraph;
44  class Edge;
45  class Vertex;
46  }
47 
48  namespace sa
49  {
50  /*!
51  \struct EdgeRemovalInfo
52 
53  \brief A struct that represents the skater partition values for each edge.
54  */
56  {
57  /*! \brief Default constructor. */
59 
60  /*! \brief Destructor. */
62 
63  std::size_t m_edgeId; //!< Edge identification
64 
65  double m_SSDT; //!< Sum of Square Difference for Tree
66  double m_SSDTa; //!< Sum of Square Difference for Tree A
67  double m_SSDTb; //!< Sum of Square Difference for Tree B
68  double m_SSDi; //!< Sum of m_SSDa and m_SSDb
69  double m_l; //!< Difference between m_SSDT and m_SSDi;
70  std::size_t m_popa; //!< Sum of population for Tree A
71  std::size_t m_popb; //!< Sum of population for Tree B
72  };
73 
74  /*!
75  \class SkaterPartition
76 
77  \brief Class that represents the skater partition operation.
78 
79  */
81  {
82  public:
83 
84  /*!
85  \brief Default constructor.
86 
87  \param graph Pointer to a graph that represents a minimum spanning tree.
88  \param attrs Vector with attributes names used to calculate the skater operation
89  */
90  SkaterPartition(te::graph::AbstractGraph* graph, std::vector<std::string> attrs);
91 
92  /*! \brief Virtual destructor. */
93  ~SkaterPartition();
94 
95  public:
96 
97  /*!
98  \brief Function to execute the skater partition.
99 
100  \param nGroups Number of cluster to be created.
101 
102  \return Return a vector with the root vertex id for each cluster created.
103  */
104  std::vector<std::size_t> execute(std::size_t nGroups, std::string popAttr = "", std::size_t minPop = 0);
105 
106  std::vector<std::size_t> execute(std::string popAttr, std::size_t minPop);
107 
108  protected:
109 
110  bool edgeToRemove(int startVertex, double& diffA, double& diffB, std::size_t& edgeToRemoveId);
111 
112  double calculateEdgeDifference(int vertexFrom, int vertexTo, double& diffA, double& diffB, std::size_t& popA, std::size_t& popB);
113 
114  std::vector<double> calculateRootMean(int startVertex, int vertexToIgnore, std::size_t& pop);
115 
116  double calculateRootDeviation(int startVertex, int vertexToIgnore, std::vector<double>& meanVec);
117 
118  double calculateDistance(te::graph::Vertex* vertex, std::vector<double>& meanVec);
119 
120  protected:
121 
122  te::graph::AbstractGraph* m_graph; //!< Pointer to a graph that represents a minimum spanning tree.
123 
124  std::vector<std::string> m_attrs; //!< Vector with attributes names used to calculate the skater operation.
125 
126  std::string m_popAttr; //!< The population attribute name.
127 
128  std::size_t m_popMin; //!< The minimum population value allowed in a cluster.
129 
130  std::vector<double> m_SSDiValues; //!< Vector with the sum square differences for each edge removed.
131 
132  };
133  } // end namespace sa
134 } // end namespace te
135 
136 #endif //__TERRALIB_SA_INTERNAL_SKATERPARTITION_H
Class that represents the skater partition operation.
double m_SSDTa
Sum of Square Difference for Tree A.
A struct that represents the skater partition values for each edge.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
std::size_t m_popMin
The minimum population value allowed in a cluster.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:55
double m_l
Difference between m_SSDT and m_SSDi;.
EdgeRemovalInfo()
Default constructor.
std::size_t m_edgeId
Edge identification.
std::size_t m_popa
Sum of population for Tree A.
std::string m_popAttr
The population attribute name.
std::vector< double > m_SSDiValues
Vector with the sum square differences for each edge removed.
double m_SSDi
Sum of m_SSDa and m_SSDb.
#define TESAEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:136
This file contains a class that represents the skater parameters.
std::size_t m_popb
Sum of population for Tree B.
double m_SSDT
Sum of Square Difference for Tree.
double m_SSDTb
Sum of Square Difference for Tree B.
~EdgeRemovalInfo()
Destructor.
te::graph::AbstractGraph * m_graph
Pointer to a graph that represents a minimum spanning tree.
std::vector< std::string > m_attrs
Vector with attributes names used to calculate the skater operation.