Hits Algorithm using Adjacency Matrix representation

  adjacency-matrix, c++, graph-algorithm

I have a directed Graph data structure that implements the hits algorithm, to find the authority and hub values of each vertex in the Graph. I used a 2D vector for an adjacency matrix representation. I have two boolean values (iter_bound & err_bound)that are the stopping condition for the algorithm. I have the stopping condition for iter_bound working, but the err_bound stopping condition gets stuck in an infinite loop. Below is the portion of code that is giving me issues.

 else if (err_bound == true){
        int t = 0;
        std::fill (auth_t_1.begin(), auth_t_1.end(), iter0);
        std::fill (hub_t_1.begin(), hub_t_1.end(), iter0);
        std::fill (done.begin(), done.end(), false);
        Loop: while (stop != true){
            for (int i {}; i < auth_t.size(); i++){
                auth_t[i] = product(hub_t_1, transpose(this->node), i);
                hub_t[i] = product(auth_t, node, i);
                auth_scale += std::pow(auth_t[i],2);
                hub_scale += std::pow(hub_t[i],2);
            }
            for (int i {}; i < auth_t.size(); i++){
                auth_t[i] = auth_t[i]/std::sqrt(auth_scale);
                hub_t[i] = hub_t[i]/std::sqrt(hub_scale);
            }
            for (int i {}; i < auth_t.size(); i++){
                auth_diff = abs(auth_t[i] - auth_t_1[i]);
                hub_diff = abs(hub_t[i] - hub_t_1[i]);
                if (auth_diff < err && hub_diff < err){
                    done[i] == true;
                }
            }

            for (int i {}; i < auth_t.size(); i++){ 
                auth_t_1[i] = auth_t[i];
                hub_t_1[i] = auth_t[i];
            }
            for (int i {}; i < done.size(); i++){
                if(done[i] == true)
                    continue;
                else{
                    t++;
                    goto Loop;  
                }
                    
            }
            stop = true;
            std::cout << "Iter : " << t << "n";
            for (int i {}; i < N; i++){
                std::cout << "A/H[" << i << "]=" << auth_t[i] << "/" << hub_t[i] << "  " << "n"; 
            }

        }
    }

I don’t think I am using vectors efficiently, but its best I can do for now.

Source: Windows Questions C++

LEAVE A COMMENT