! Compute the Google Page rank of a set of 
  connected pages;
! Keywords: Google, Page rank, World wide web;
SETS:
  Page: x, deg;
  PXP( Page, Page);
ENDSETS
DATA: alpha = .95; ! 1-alpha = seed value for the page rank, e.g., every page has a rank of at least 1-alpha; ! The pages; Page = 1..10; ! The page i points to page j pairs; PXP= 1,10 2,6 3,10 4,5 5,3 6,1 6,3 6,4 7,2 8,2 9,7 10,9; ENDDATA SUBMODEL pagerank: ! Solve for the page rank. Page j has a high page rank if page i points to j, page i has a high page rank, and page i does not point to lots of pages; @FOR( Page(j): x(j) = (1-alpha) + alpha* @SUM(PXP(i,j)| i #NE# j: x(i)/deg(i)); ); ENDSUBMODEL
CALC: ! Compute the outdegree, i.e., pages pointed to, of each page; @FOR( Page(i): deg(i) = 0); @FOR( PXP(i,j)| i #NE# j: deg(i) = deg(i) + 1; ); @SOLVE( pagerank); ! Optionally scale so ranks sum to a specified target, e.g. 1; CURSUM = @SUM( Page(i): x(i)); @FOR( Page(i): x(i) = x(i)/CURSUM ); ENDCALC