vendredi 19 août 2016

bfsTree empty with unused value warning

I am trying to implement bfsTree. It should take a graph as input and give the bfs tree as output. However the line that adds the edge to the bfs tree seems to be not working. The bfstree is empty. I think it is related to this unused value warning. Why it gives the warning? And how to fix it? Thanks.

Here is the warning:

vertex.cpp:35:10: warning: expression result unused [-Wunused-value]
for (neighbor; neighbor != this->_neighbors.end(); neighbor++) {

Here is the bfs tree code snippet:

Graph Bicc::breadthFirstSearch(Graph& sparseGraph) {
    Graph bfsTree;

    auto lev = 0;
    vector<Vertex> verticies = sparseGraph.getVerticies();
    for(int i = 0; i < verticies.size(); i++){
        verticies[i].color = "white";
        verticies[i].level = lev;
    }

    Vertex start = verticies[0];
    list<Vertex> VertexQueue;
    VertexQueue.push_back(start);

    while (!VertexQueue.empty())    
    {
        Vertex current = VertexQueue.front();
        current.color = "gray"; //current vertex is being processed
        auto neighbors = current.getNeighbors();

        //process all neighbors of current vertex
        for(auto n = neighbors.begin(); n != neighbors.end(); n++) {

            if (n->color == "white") {   // This is an unvisited vertex
                n->level = lev + 1;          // Set level
                n->parent = &current;       // Set parent
                n->color = "gray";          // Set color visited
                bfsTree.add(current, *n); //add the edge to bfsTree
                VertexQueue.push_back(*n);    // Add it to the queue    
            }
        }
        VertexQueue.pop_front();    // Pop out the processed vertex
        ++lev;  // The next level
    }
    return bfsTree;
}

Here is the vertex.cpp code snippet that was called by the warning:

bool Vertex::hasNeighbor(const Vertex& vertex) const {
    auto neighbor = this->_neighbors.begin();
    for (neighbor; neighbor != this->_neighbors.end(); neighbor++) {
        if (*neighbor == vertex) {
            break;
        }
    }
    return neighbor != this->_neighbors.end();
}

Aucun commentaire:

Enregistrer un commentaire