All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GPMWeightsNoWeightsStrategy.cpp
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 GPMWeightsNoWeightsStrategy.cpp
22 
23  \brief This class defines a class to calculates a weight for a GPM using No Weights strategy.
24 */
25 
26 // Terralib Includes
27 #include "../../datatype/SimpleData.h"
28 #include "../../graph/core/AbstractGraph.h"
29 #include "../../graph/core/Edge.h"
30 #include "../../graph/core/GraphMetadata.h"
31 #include "../../graph/core/Vertex.h"
32 #include "../../graph/iterator/MemoryIterator.h"
35 
37  m_normalize(normalize)
38 {
40 }
41 
43 {
44 }
45 
47 {
48  //create weight property
49  int weightIdx = createWeightAttribute(gpm);
50 
51  int nEdgeAttrs = gpm->getGraph()->getMetadata()->getEdgePropertySize();
52 
53  //iterate over all vertex
55 
57 
59 
60  while(v)
61  {
62  std::set<int> neighbours = v->getSuccessors();
63  std::set<int>::iterator itNeighbours = neighbours.begin();
64 
65  //calculate weight
66  double weight = 1.;
67 
68  if(m_normalize)
69  weight = 1./ neighbours.size();
70 
71  while(itNeighbours != neighbours.end())
72  {
73  te::graph::Edge* e = g->getEdge(*itNeighbours);
74 
75  if(e)
76  {
77  e->setAttributeVecSize(nEdgeAttrs);
78 
80  }
81 
82  ++itNeighbours;
83  }
84 
85  v = it->getNextVertex();
86  }
87 }
virtual te::graph::Vertex * getFirstVertex()
It returns a pointer to the first vertex element of a graph.
This class defines a class to calculates a weight for a GPM using No Weights strategy.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
Definition: Edge.cpp:86
virtual te::graph::Vertex * getNextVertex()
It returns a pointer to the next vertex element of a graph.
This class defines a Generalized Proximity Matrix.
virtual te::graph::Edge * getEdge(int id)=0
It returns the edge element if it's exist.
GPMWeightsStrategyType m_type
Weight Type.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
GPMWeightsNoWeightsStrategy(bool normalize)
Default constructor.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:55
std::set< int > & getSuccessors()
Returns the Successors vector.
Definition: Vertex.cpp:106
This class defines a an Abstract class to calculates a weight for a GPM.
virtual ~GPMWeightsNoWeightsStrategy()
Virtual destructor.
virtual int getEdgePropertySize()
Used to verify the number of properties associated to edge elements.
virtual void calculate(GeneralizedProximityMatrix *gpm)
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
Definition: Edge.cpp:91
This class defines the GPM class.