This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/meld/examples/pagerank/pagerank.meld

50 lines
922 B
Plaintext
Raw Normal View History

type rank(node, int, float).
type calcRank(node, int, sum float).
2011-05-11 09:28:40 +01:00
% type persistent numPages(node, int).
type persistent numPages(node, sum int).
type numLinks(node, sum int).
2011-05-11 09:28:40 +01:00
type path(node, node).
const damping = 0.85.
2011-05-25 13:10:39 +01:00
const num_iterations = 100.
% extern float to_float(int).
% extern float float_abs(float).
2011-05-11 09:28:40 +01:00
rank(A, 0, 1.0 / to_float(T)) :- numPages(A,T).
rank(A, I, V) :-
2011-05-25 13:10:39 +01:00
numLinks(B,L),
2011-05-11 09:28:40 +01:00
numPages(A, Ps),
calcRank(A, I, T),
2011-05-25 13:10:39 +01:00
% Before = I - 1,
% rank(A, Before, VOld),
V = damping + (1.0 - damping) * T,
I =< num_iterations.
% //float_abs((damping + (1.0 - damping) * T) - VOld) > 0.001.
2011-05-25 13:10:39 +01:00
calcRank(A, I + 1, 0.0) :-
rank(A, I, _).
calcRank(A, I + 1, O / to_float(C)) :-
edge(B, A),
rank(B, I, O),
numLinks(B, C).
numLinks(A, 1) :-
edge(A,B).
2011-05-11 09:28:40 +01:00
numPages(A, 1) :- path(A,_).
2011-05-11 09:28:40 +01:00
path(A, B) :-
edge(A,B).
path(A, B) :-
edge(B,A).
path(A, B) :-
edge(A,C),
path(C,B).
path(A, B) :-
edge(C,A),
path(C,B).