Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Integer surfWithJumpUntilHit(Integer v, Integer n, Double jumpThreshold) {
- // PRE: v is vertex to start surf; n >= 0; 0 <= jumpThreshold <= 1.0
- // POST: surfs the graph randomly until visit v for second time (maximum n moves),
- // choosing adjacent vertex according to distribution of edge weights if random number is below jumpThreshold,
- // choosing any vertex uniformly randomly otherwise;
- // modifies # visits in vertices
- // returns number of vertices visited
- //System.out.println("Start "+v);
- Iterator k = vertexSet().iterator();
- int [] y = new int[vertexSet().size()];
- for (int h = 0; h < vertexSet().size();h++){
- y[h] = (Integer) k.next();
- visits.put(y[h], 0);
- }
- int hit = v;
- int counter =0;
- for (int i = 0; i < n; i++){
- //System.out.println("v "+v);
- setVisits(v);
- counter++;
- Random r2 = new Random();
- double t2 = 0 + r2.nextDouble() * 1.0;
- if (counter < n){
- int x = getRandomLink(v);
- //System.out.println(x);
- if (t2 < jumpThreshold){
- v = x;
- }else{
- Random rand = new Random();
- int f = rand.nextInt(vertexSet().size());
- v=f;
- //System.out.println(f);
- }
- }else{
- return counter;
- }
- if (v == hit){
- //System.out.println("hit"+v);
- return counter;
- }
- }
- return counter;
- // TODO
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement