Loading...
Searching...
No Matches
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
38namespace 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 m_SSDT = 0.;
61 m_SSDTa = 0.;
62 m_SSDTb = 0.;
63 m_SSDi = 0.;
64 m_l = 0.;
65 m_popa = 0;
66 m_popb = 0;
67 };
68
69 /*! \brief Destructor. */
71
72 std::size_t m_edgeId; //!< Edge identification
73
74 double m_SSDT; //!< Sum of Square Difference for Tree
75 double m_SSDTa; //!< Sum of Square Difference for Tree A
76 double m_SSDTb; //!< Sum of Square Difference for Tree B
77 double m_SSDi; //!< Sum of m_SSDa and m_SSDb
78 double m_l; //!< Difference between m_SSDT and m_SSDi;
79 std::size_t m_popa; //!< Sum of population for Tree A
80 std::size_t m_popb; //!< Sum of population for Tree B
81 };
82
83 /*!
84 \class SkaterPartition
85
86 \brief Class that represents the skater partition operation.
87
88 */
90 {
91 public:
92
93 /*!
94 \brief Default constructor.
95
96 \param graph Pointer to a graph that represents a minimum spanning tree.
97 \param attrs Vector with attributes names used to calculate the skater operation
98 */
99 SkaterPartition(te::graph::AbstractGraph* graph, std::vector<std::string> attrs);
100
101 /*! \brief Virtual destructor. */
103
104 public:
105
106 /*!
107 \brief Function to execute the skater partition.
108
109 \param nGroups Number of cluster to be created.
110
111 \return Return a vector with the root vertex id for each cluster created.
112 */
113 std::vector<std::size_t> execute(std::size_t nGroups, std::string popAttr = "", std::size_t minPop = 0);
114
115 std::vector<std::size_t> execute(std::string popAttr, std::size_t minPop);
116
117 protected:
118
119 bool edgeToRemove(int startVertex, double& diffA, double& diffB, std::size_t& edgeToRemoveId);
120
121 double calculateEdgeDifference(int vertexFrom, int vertexTo, double& diffA, double& diffB, std::size_t& popA, std::size_t& popB);
122
123 std::vector<double> calculateRootMean(int startVertex, int vertexToIgnore, std::size_t& pop);
124
125 double calculateRootDeviation(int startVertex, int vertexToIgnore, std::vector<double>& meanVec);
126
127 double calculateDistance(te::graph::Vertex* vertex, std::vector<double>& meanVec);
128
129 protected:
130
131 te::graph::AbstractGraph* m_graph; //!< Pointer to a graph that represents a minimum spanning tree.
132
133 std::vector<std::string> m_attrs; //!< Vector with attributes names used to calculate the skater operation.
134
135 std::string m_popAttr; //!< The population attribute name.
136
137 std::size_t m_popMin; //!< The minimum population value allowed in a cluster.
138
139 std::vector<double> m_SSDiValues; //!< Vector with the sum square differences for each edge removed.
140
141 };
142 } // end namespace sa
143} // end namespace te
144
145#endif //__TERRALIB_SA_INTERNAL_SKATERPARTITION_H
This file contains a class that represents the skater parameters.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
From the point of view of graph theory, vertices are treated as featureless and indivisible objects,...
Definition: Vertex.h:69
Class that represents the skater partition operation.
bool edgeToRemove(int startVertex, double &diffA, double &diffB, std::size_t &edgeToRemoveId)
std::vector< double > calculateRootMean(int startVertex, int vertexToIgnore, std::size_t &pop)
~SkaterPartition()
Virtual destructor.
std::size_t m_popMin
The minimum population value allowed in a cluster.
std::vector< double > m_SSDiValues
Vector with the sum square differences for each edge removed.
std::vector< std::string > m_attrs
Vector with attributes names used to calculate the skater operation.
std::vector< std::size_t > execute(std::string popAttr, std::size_t minPop)
SkaterPartition(te::graph::AbstractGraph *graph, std::vector< std::string > attrs)
Default constructor.
double calculateEdgeDifference(int vertexFrom, int vertexTo, double &diffA, double &diffB, std::size_t &popA, std::size_t &popB)
std::string m_popAttr
The population attribute name.
std::vector< std::size_t > execute(std::size_t nGroups, std::string popAttr="", std::size_t minPop=0)
Function to execute the skater partition.
double calculateRootDeviation(int startVertex, int vertexToIgnore, std::vector< double > &meanVec)
te::graph::AbstractGraph * m_graph
Pointer to a graph that represents a minimum spanning tree.
double calculateDistance(te::graph::Vertex *vertex, std::vector< double > &meanVec)
TerraLib.
A struct that represents the skater partition values for each edge.
std::size_t m_popa
Sum of population for Tree A.
double m_SSDTb
Sum of Square Difference for Tree B.
EdgeRemovalInfo()
Default constructor.
std::size_t m_edgeId
Edge identification.
double m_SSDTa
Sum of Square Difference for Tree A.
double m_SSDT
Sum of Square Difference for Tree.
std::size_t m_popb
Sum of population for Tree B.
double m_l
Difference between m_SSDT and m_SSDi;.
double m_SSDi
Sum of m_SSDa and m_SSDb.
~EdgeRemovalInfo()
Destructor.
#define TESAEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:133