How can I fix this edge iterator assignment error?

154 views Asked by At

I want to iterate through a graph and remove edges, calculate the number of connected components, and then add the removed edges back again to the graph.

I am stuck at the place where I should assign the edge iterator to the first and last edge of the graph

edge_iter ei,ei_end,next;

    ei = edges(g).first;

It doesn't seem to work even like this:

tie(ei,ei_end) = edges(g);

I get the following error:

no viable overloaded "="

what does this mean?

Here is my program for now:

  using namespace boost;
  using namespace std;

    typedef adjacency_list <listS, vecS, undirectedS> Graph;
    typedef graph_traits < Graph >::edge_descriptor Edge;

    typedef std::pair<int,int> E;

    typedef graph_traits<Graph>::vertex_descriptor Vertex;
    typedef property_map<Graph, vertex_index_t>::type IndexMap;

    typedef std::pair<int,int> E;
    typedef graph_traits<Graph>::vertex_iterator vertex_iter;
    typedef graph_traits<Graph>::out_edge_iterator edge_iter;
    typedef property_map<Graph, vertex_index_t>::type VertexIndexMap;



  int main(int,char*[])
  {

   int num_nodes,num_edges;
   cin >> num_nodes >> num_edges;

   Graph g(num_nodes);

    for(int i = 0;i < num_edges; i++) // i/p edges into graph g
    {

        int e1,e2;
        cin >> e1 >> e2;

        Edge e;
        bool success;


        tie(e,success) = add_edge(e1-1, e2-1, g);
    }

    //graph entry completed



    edge_iter ei,ei_end,next;

    ei = edges(g).first;
1

There are 1 answers

0
sehe On BEST ANSWER

You got the graph edges with edges(g). However, edge_iter is defined as the out_edge_iterator.

These are not the same (I think for all graph models that have out_edge collections).

So, either,

typedef graph_traits<Graph>::edge_iterator edge_iter;

or

graph_traits<Graph>::vertex_descriptor v;
ei = out_edges(v, g).first;

depending on what you are trying to achieve, functionally