/**
   * Creates a new graph with the specified number of vertices that are connected with constant
   * probability.
   *
   * @param numVertices the number of vertices.
   * @param p the edge probability
   * @param randomSeed a random seed
   * @return a new random graph.
   */
  public G generate(int numVertices, double p, long randomSeed) {
    G g = builder.createGraph();

    for (int i = 0; i < numVertices; i++) builder.addVertex(g);

    return generate(g, p, randomSeed);
  }
Example #2
0
  public static void main(String args[]) throws IOException {
    GraphBuilder builder = new GraphBuilder();

    ArrayList<String> alterTables = new ArrayList<String>();
    alterTables.add("/Users/jillenberger/Work/socialnets/data/ivt2009/11-2011/raw/alters1.txt");
    alterTables.add("/Users/jillenberger/Work/socialnets/data/ivt2009/11-2011/raw/alters2.txt");

    ArrayList<String> egoTables = new ArrayList<String>();
    //		egoTables.add("/Users/jillenberger/Work/socialnets/data/ivt2009/01-2011/egos1.txt");
    //		egoTables.add("/Users/jillenberger/Work/socialnets/data/ivt2009/09-2010/egos2.txt");

    ArrayList<String> sqlDumps = new ArrayList<String>();
    sqlDumps.add("/Users/jillenberger/Work/socialnets/data/ivt2009/11-2011/raw/snowball.csv");

    SampledGraphProjection<SocialSparseGraph, SocialSparseVertex, SocialSparseEdge> graph =
        builder.buildGraph(alterTables, egoTables, sqlDumps);
    SampledGraphProjMLWriter writer = new SampledGraphProjMLWriter(new SocialSparseGraphMLWriter());
    //		writer.write(graph,
    // "/Users/jillenberger/Work/socialnets/data/ivt2009/11-2011/graph/graph.graphml");
    //		writer.write(graph,
    // "/Users/jillenberger/Work/socialnets/data/ivt2009/09-2010/graph/sociogram/graph.graphml");
  }
Example #3
0
  public G generate(int N, int k, double p) {
    G graph = ringLatticeGenerator.generate(N, k);

    Set<Edge> edges = new HashSet<Edge>();
    for (Edge edge : graph.getEdges()) {
      if (random.nextDouble() < p) {
        edges.add(edge);
      }
    }

    List<V> vertices = new ArrayList<V>(graph.getVertices().size());
    vertices.addAll((Collection<? extends V>) graph.getVertices());

    int doubleEdges = 0;

    for (Edge edge : edges) {
      V source;

      if (random.nextBoolean()) {
        source = (V) edge.getVertices().getFirst();
      } else {
        source = (V) edge.getVertices().getSecond();
      }

      builder.removeEdge(graph, (E) edge);
      V target = null;
      while (target == null) {
        target = vertices.get(random.nextInt(vertices.size()));
        if (source == target) target = null;
      }

      if (builder.addEdge(graph, source, target) == null) doubleEdges++;
    }

    logger.debug(String.format("Rejected %1$s double edges.", doubleEdges));

    return graph;
  }
  @SuppressWarnings("unchecked")
  private G enumerate(G graph, double p, long randomSeed) {
    LinkedList<V> pending = new LinkedList<V>();
    pending.addAll((Collection<? extends V>) graph.getVertices());

    Random random = new Random(randomSeed);
    V v1;
    while ((v1 = pending.poll()) != null) {
      for (V v2 : pending) {
        if (random.nextDouble() <= p) {
          builder.addEdge(graph, v1, v2);
        }
      }
    }

    return graph;
  }
  @SuppressWarnings("unchecked")
  private G randomDraw(G graph, double p, long randomSeed) {
    long n = graph.getVertices().size();
    long M = n * (n - 1) / 2;
    int m = (int) (p * M);

    Random random = new Random(randomSeed);
    List<V> vertices = new ArrayList<V>((Collection<? extends V>) graph.getVertices());
    ProgressLogger.init(m, 1, 5);
    for (int i = 0; i < m; i++) {
      E edge = null;
      while (edge == null) {
        V vi = vertices.get(random.nextInt((int) n));
        V vj = vertices.get(random.nextInt((int) n));
        edge = builder.addEdge(graph, vi, vj);
      }
      ProgressLogger.step();
      //			if(i % 10000 == 0)
      //				logger.info(String.format("Created %1$s of %2$s edges.", i+1, m));
    }
    ProgressLogger.termiante();
    return graph;
  }