-
Notifications
You must be signed in to change notification settings - Fork 2
/
PathCountLinkPredictor.cpp
48 lines (40 loc) · 2.09 KB
/
PathCountLinkPredictor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
------------------------------------------------
Copyright (C) 2010 by Ryan N. Lichtenwalter
Email: rlichtenwalter@gmail.com
This file is part of LPmade.
LPmade is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. LPmade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LPmade. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------
*/
#include <stack>
#include <utility>
#include "PathCountLinkPredictor.h"
using std::stack;
using std::make_pair;
PathCountLinkPredictor::PathCountLinkPredictor( const WeightedNetwork& network, const WeightedNetwork& completeNetwork,unsigned int l ) : LinkPredictor(network,completeNetwork), l(l) {
}
PathCountLinkPredictor::~PathCountLinkPredictor() {
}
double PathCountLinkPredictor::generateScore( vertex_t vertex, vertex_t neighbor ) {
if( this->vertex != vertex ) {
this->vertex = vertex;
this->scores = vector<double>( this->network.vertexCount() );
stack<pair<vertex_t,unsigned int> > search = stack<pair<vertex_t,unsigned int> >();
search.push( make_pair( vertex, 0 ) );
while( !search.empty() ) {
const pair<vertex_t,unsigned int>& searchItem = search.top();
vertex_t searchVertex = searchItem.first;
unsigned int distance = searchItem.second;
search.pop();
this->scores.at( searchVertex )++;
if( distance < l ) {
const neighbor_set_t& neighbors = this->network.outNeighbors( searchVertex );
for( neighbor_set_t::const_iterator neighborIterator = neighbors.begin(); neighborIterator != neighbors.end(); neighborIterator++ ) {
vertex_t neighbor = neighborIterator->first;
search.push( make_pair( neighbor, distance+1 ) );
}
}
}
}
return this->scores.at( neighbor );
}