-1

I have a list of vertices as a big array which are:

vert[N]
        100, 1350, 200, 400, 12000, ....

It means that the labels are saved in an array which is : v[1]=100, v[2]=1350, v[3]=200, v[4]=400, v[5]=12000, ....

and I also know the connectivity relation

100 12000
1350 200
400 15000
.
.
.

so, edge is also in a another array n[1]=12000, n[2]=200, n[3]=15000, .... so it means 100 is connected to 12000. how can i create a graph in boost with these inputs.

ziv
  • 189
  • 1
  • 9
  • You decide how to represent them and load the data into your data structure. Why is the question tagged [tag:boost]? – sehe Apr 11 '14 at 06:36
  • I do not understand, what do you mean. I am new in boost that is why I asked this and wanna using Boost graph library to create graph so it tagged boost. – ziv Apr 11 '14 at 09:44
  • Ah. There was no such information, so the tag boost alone wasn't even enough to confirm that you are in fact using c++ :) What you want is a http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/edge_list.html or http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/adjacency_list.html – sehe Apr 11 '14 at 10:02

1 Answers1

0

Let's assume that the labels are standard strings.

The first thing you need to do is store the labels in a set, so that you ensure that there are no duplicates and you can find the index of a particular label quickly.

std::set<std::string> set_vertex_labels;
for( int i = 0; i < size_of_vert; i++ ) {
   set_vertex_labels.insert( vert[i] );
}

Now lets assume that you can iterate over your connection data, getting the two labels of the edge

std::string label1, label2;
magic_function_to_get_next_two_connected_labels( label1, label2 );

Find the index of the first connected vertex

std::set<std::string>::iterator it = set_vertex_labels.find( label1 );
if( it == set_vertex_labels.end() ) {
    // oops!
    exit(1);
}
int index_vertex1 = std::distance( set_vertex_labels.begin(), it );

Do the same for the second vertex.

Finally you are ready to insert your edge into your graph

add_edge( index_vertex1, index_vertex2, myGraph );
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
  • Thanks, yes they are labels. I have the labels in an array which is : v[1]=100, v[2]=1350, v[3]=200, v[4]=400, v[5]=12000, .... and the edge is also in a another array n[1]=12000, n[2]=200, n[3]=15000, .... so it means 100 is connected to 12000. I hope this would clarify my point. So – ziv Apr 11 '14 at 14:59