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> 62 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int > > boostGraph;
64 typedef std::pair < int, int > boostEdge;
66 std::vector<boostEdge> edge_vec;
68 std::vector<double> weight_vec;
81 boostGraph graph(nVertex);
83 boost::property_map<boostGraph, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, graph);
85 for(std::size_t t = 0; t < nEdge; ++t)
87 boost::graph_traits<boostGraph>::edge_descriptor e;
91 boost::tie(e, inserted) = boost::add_edge(edge_vec[t].first, edge_vec[t].second, graph);
93 weightmap[e] = (
int)weight_vec[t];
97 typedef boost::graph_traits<boostGraph>::edge_descriptor Edge;
99 boost::property_map<boostGraph, boost::edge_weight_t>::type weight = boost::get(boost::edge_weight, graph);
101 std::vector<Edge> spanning_tree;
103 kruskal_minimum_spanning_tree(graph, std::back_inserter(spanning_tree));
113 for(std::size_t t = 0; t < spanning_tree.size(); ++t)
115 Edge eCur = spanning_tree[t];
117 int vertexSourceId =
static_cast<int>(boost::source(eCur, graph));
118 int vertexTargetId =
static_cast<int>(boost::target(eCur, graph));
120 double weightEdge = weight[eCur];
133 graphOut->
add(vFrom);
168 const std::string connInfo(
"memory:");
171 std::map<std::string, std::string> graphInfo;
172 graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] =
"MEM";
173 graphInfo[
"GRAPH_NAME"] =
"mst_graph";
174 graphInfo[
"GRAPH_DESCRIPTION"] =
"Generated by Minimum Spanning Tree.";
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.
Utilitary function for spatial analysis module.
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.
#define TE_SA_SKATER_ATTR_WEIGHT_NAME
std::set< int > & getPredecessors()
Returns the Predecessors vector.
static const std::string sm_factoryGraphTypeUndirectedGraph
Undirected Graph Factory Name.
virtual Property * clone() const =0
It returns a clone of the object.
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.
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.
te::graph::AbstractGraph * m_inputGraph
Pointer to input graph.
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.