Ejemplo n.º 1
0
  public void randomwalk(int v) {
    // weighted random walk
    RandomWalk rw = new RandomWalk(p_w);
    int status = rw.stay_move();
    ArrayList<Integer> walkpath = new ArrayList<Integer>();
    Integer u = v;
    walkpath.add(v);
    while (status == 1) // keep moving until status = 0
    {
      u = rw.move(G, u);
      if (u == null) // no neighbors
      break;
      if (!walkpath.contains(u)) walkpath.add(u);
      status = rw.stay_move();
    }
    //		System.out.println("walking length: "+ Integer.toString(walkpath.size()));

    for (int i = 0; i < walkpath.size(); i++)
      for (int j = i + 1; j < walkpath.size(); j++) {
        int m = walkpath.get(i);
        int n = walkpath.get(j);
        if (!G.containsEdge(m, n)) {
          double distance = Math.abs(socialposition.get(m) - socialposition.get(n));
          double prob = linkprob(distance, (j - i));
          if (random.nextDouble() < prob) {
            G.setEdgeWeight((DefaultWeightedEdge) G.addEdge(m, n), 1);
          }
        } else {
          DefaultWeightedEdge edge = G.getEdge(m, n);
          G.setEdgeWeight(edge, G.getEdgeWeight(edge) + 1);
        }
      }
    return;
  }