Program Listing for File NeighborhoodDistanceIndex.hpp

Return to documentation for file (include/networkit/linkprediction/NeighborhoodDistanceIndex.hpp)

/*
 * NeighborhoodDistanceIndex.hpp
 *
 *  Created on: 24.06.2013
 *      Authors: cls, Kolja Esders
 */

#ifndef NETWORKIT_LINKPREDICTION_NEIGHBORHOOD_DISTANCE_INDEX_HPP_
#define NETWORKIT_LINKPREDICTION_NEIGHBORHOOD_DISTANCE_INDEX_HPP_

#include <cmath>

#include <networkit/linkprediction/LinkPredictor.hpp>

namespace NetworKit {

class NeighborhoodDistanceIndex final : public LinkPredictor {
    double runImpl(node u, node v) override {
        count uNeighborhood = G->degree(u);
        count vNeighborhood = G->degree(v);
        count intersection = NeighborhoodUtility::getCommonNeighbors(*G, u, v).size();
        return ((double)intersection) / (std::sqrt(uNeighborhood * vNeighborhood));
    }

public:
    using LinkPredictor::LinkPredictor;
};

} /* namespace NetworKit */
#endif // NETWORKIT_LINKPREDICTION_NEIGHBORHOOD_DISTANCE_INDEX_HPP_