I have three different vectors of objects that I need to make a tree structure from them. Let's assume we have vector <obj> parents
, vector <obj> children
, and vector <obj> leaves
. Therefore, each member of vector <obj> children
has several children that sits at the end of the tree as leaves, and has one parent that sits as parents. What I am using is defining Vertex properties
and Edges properties
as below, and then define a bidirectional graph
:
struct VertexData
{
std::string obj_name; // concatenation of labels
std::string obj_class_num;
int num;
vector <int> segments_list;
bool is_leaf=false;
};
struct EdgeData
{
std::string edge_name;
double confidence;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::bidirectionalS,
VertexData,
boost::property<boost::edge_weight_t, double, EdgeData> > Graph;
Graph graph;
What I am doing currently, is looping through the vector <obj> leaves
, for each member, I find the parent and make an edge. Then assign properties to the edge and vertices. But then for next leaf, I should check if already it has a parent in the tree or I should add a new vertex for its parent. Another thing that I tried, was looping through the vector <obj> children
, and for each member try to make its leaves and parent. But I am not sure what is the correct way to do this. Here is a link: adding custom vertices to a boost graph that I try to do the same but with iterations.
Aucun commentaire:
Enregistrer un commentaire