29 #include "../../datatype/SimpleData.h"
30 #include "../../graph/core/AbstractGraph.h"
31 #include "../../graph/core/AbstractGraphFactory.h"
32 #include "../../graph/core/Edge.h"
33 #include "../../graph/core/GraphMetadata.h"
34 #include "../../graph/core/Vertex.h"
35 #include "../../graph/iterator/MemoryIterator.h"
36 #include "../../graph/Globals.h"
44 #include <boost/graph/adjacency_list.hpp>
45 #include <boost/graph/kruskal_min_spanning_tree.hpp>
64 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int > > boostGraph;
66 typedef std::pair < int, int > boostEdge;
68 std::vector<boostEdge> edge_vec;
70 std::vector<double> weight_vec;
83 boostGraph graph(nVertex);
85 boost::property_map<boostGraph, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, graph);
87 for(std::size_t t = 0; t < nEdge; ++t)
89 boost::graph_traits<boostGraph>::edge_descriptor e;
93 boost::tie(e, inserted) = boost::add_edge(edge_vec[t].first, edge_vec[t].second, graph);
95 weightmap[e] = (int)weight_vec[t];
99 typedef boost::graph_traits<boostGraph>::edge_descriptor Edge;
100 typedef boost::graph_traits<boostGraph>::vertex_descriptor Vertex;
102 boost::property_map<boostGraph, boost::edge_weight_t>::type weight = boost::get(boost::edge_weight, graph);
104 std::vector<Edge> spanning_tree;
106 kruskal_minimum_spanning_tree(graph, std::back_inserter(spanning_tree));
116 for(std::size_t t = 0; t < spanning_tree.size(); ++t)
118 Edge eCur = spanning_tree[t];
120 int vertexSourceId = boost::source(eCur, graph);
121 int vertexTargetId = boost::target(eCur, graph);
123 double weightEdge = weight[eCur];
136 graphOut->
add(vFrom);
171 std::map<std::string, std::string> connInfo;
174 std::map<std::string, std::string> graphInfo;
175 graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] =
"MEM";
176 graphInfo[
"GRAPH_NAME"] =
"mst_graph";
177 graphInfo[
"GRAPH_DESCRIPTION"] =
"Generated by Minimum Spanning Tree.";
183 for(
int i = 0; i < m_inputGraph->getMetadata()->getVertexPropertySize(); ++i)
virtual te::graph::Edge * getNextEdge()
It returns a pointer to the next edge element of a graph.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
~MinimumSpanningTree()
Virtual destructor.
te::graph::AbstractGraph * kruskal(int weightAttrIdx)
Function to execute the kruskal operation.
te::graph::AbstractGraph * createGraph()
Function to create a empty graph with vertex attributes from gpm graph.
std::set< int > & getPredecessors()
Returns the Predecessors vector.
virtual Property * clone() const =0
It returns a clone of the object.
static const std::string sm_factoryGraphTypeUndirectedGraph
Undirected Graph Factory Name.
Utilitary function for spatial analysis module.
virtual void add(Vertex *v)=0
Add a new vertex element to a graph.
It models a property definition.
This file contains a class that represents the Minimum Spanning Tree operation.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
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...
Abstract class used to define the main functions of graph struct. All graph implementations must used...
std::set< int > & getSuccessors()
Returns the Successors vector.
int getIdFrom()
It returns the vertex origin identification.
std::set< int > & getNeighborhood()
Returns the Neighborhood vector.
virtual te::graph::Edge * getFirstEdge()
It returns a pointer to the first edge element of a graph.
virtual size_t getEdgeInteratorCount()
It returns the number of elements of this iterator.
#define TE_SA_SKATER_ATTR_WEIGHT_NAME
virtual size_t getVertexInteratorCount()
It returns the number of elements of this iterator.
A template for atomic data types (integers, floats, strings and others).
TESAEXPORT int AddGraphEdgeAttribute(te::graph::AbstractGraph *graph, std::string attrName, int dataType)
Function used to create the edge attribute metadata in the graph of the gpm.
TESAEXPORT double GetDataValue(te::dt::AbstractData *ad)
Function used to get the numeric value from a gpm property.
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
virtual te::graph::Vertex * getVertex(int id)=0
It returns the vertex element if it's exist.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
MinimumSpanningTree(te::graph::AbstractGraph *inputGraph)
Default constructor.
int getIdTo()
It returns the vertex destiny identification.
void setParent(Property *p)
It associate this property to the informed parent.