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 
45 {
46  //create weight property
47  int weightIdx = createWeightAttribute(gpm);
48 
49  int nEdgeAttrs = gpm->getGraph()->getMetadata()->getEdgePropertySize();
50 
51  //iterate over all vertex
53 
55 
57 
58  while(v)
59  {
60  std::set<int> neighbours = v->getSuccessors();
61  std::set<int>::iterator itNeighbours = neighbours.begin();
62 
63  //calculate weight
64  double weight = 1.;
65 
66  if(m_normalize)
67  weight = 1./ neighbours.size();
68 
69  while(itNeighbours != neighbours.end())
70  {
71  te::graph::Edge* e = g->getEdge(*itNeighbours);
72 
73  if(e)
74  {
75  e->setAttributeVecSize(nEdgeAttrs);
76 
78  }
79 
80  ++itNeighbours;
81  }
82 
83  v = it->getNextVertex();
84  }
85 }
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&#39;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.
int createWeightAttribute(GeneralizedProximityMatrix *gpm)
Added to the edge a new attribute for weight information and return the attr index.
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
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.