Advertisement
Guest User

Untitled

a guest
May 26th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public Integer surfWithJumpUntilHit(Integer v, Integer n, Double jumpThreshold) {
  2.     // PRE: v is vertex to start surf; n >= 0; 0 <= jumpThreshold <= 1.0
  3.     // POST: surfs the graph randomly until visit v for second time (maximum n moves),
  4.     //       choosing adjacent vertex according to distribution of edge weights if random number is below jumpThreshold,
  5.     //       choosing any vertex uniformly randomly otherwise;
  6.     //       modifies # visits in vertices
  7.     //       returns number of vertices visited
  8.         //System.out.println("Start "+v);
  9.         Iterator k = vertexSet().iterator();
  10.         int [] y = new int[vertexSet().size()];
  11.        
  12.         for (int h = 0; h < vertexSet().size();h++){
  13.             y[h] = (Integer) k.next();
  14.             visits.put(y[h], 0);
  15.         }
  16.        
  17.         int hit = v;
  18.         int counter =0;
  19.        
  20.         for (int i = 0; i < n; i++){
  21.             //System.out.println("v "+v);
  22.             setVisits(v);
  23.  
  24.             counter++;
  25.             Random r2 = new Random();
  26.             double t2 = 0 + r2.nextDouble() * 1.0;
  27.             if (counter < n){
  28.                
  29.                 int x = getRandomLink(v);
  30.                 //System.out.println(x);
  31.                 if (t2 < jumpThreshold){
  32.                     v = x;
  33.                 }else{
  34.                     Random rand = new Random();
  35.                     int f = rand.nextInt(vertexSet().size());
  36.                     v=f;
  37.                     //System.out.println(f);
  38.                 }
  39.             }else{
  40.                 return counter;
  41.             }
  42.            
  43.             if (v == hit){
  44.                 //System.out.println("hit"+v);
  45.                 return counter;
  46.             }
  47.            
  48.         }
  49.         return counter;
  50.     // TODO
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement