public ConcurrentPlanModEngine(Choice2ModAdaptorFactory factory) {
   int threads = MultiThreading.getNumAllowedThreads();
   executor =
       new PlanModExecutor(
           threads,
           threads,
           Integer.MAX_VALUE,
           TimeUnit.SECONDS,
           new LinkedBlockingQueue<Runnable>(),
           new PlanModThreadFactory(factory));
 }
Beispiel #2
0
  public static void main(String[] args) {
    MultiThreading.setNumAllowedThreads(1);
    /*
     * Load config.
     */
    Config config = loadConfig(args[0]);
    /*
     * Load graph.
     */
    Graph graph = loadGraph(config.getParam(MODULENAME, "graphFile"));
    /*
     * Get random seed.
     */
    long randomSeed = config.global().getRandomSeed();
    /*
     * Init random seed generator.
     */
    int numSeeds = Integer.parseInt(config.getParam(MODULENAME, "seeds"));
    VertexFilter<Vertex> seedGenerator = new FixedSizeRandomPartition<Vertex>(numSeeds, randomSeed);
    /*
     * Init response rate generator.
     */
    double responseRate;
    String str = config.getParam(MODULENAME, "responseRate");
    if (str.endsWith("%")) {
      str = str.substring(0, str.length() - 1);
      responseRate = Double.parseDouble(str) / 100.0;
    } else responseRate = Double.parseDouble(str);

    VertexFilter<Vertex> reponseGenerator = new RandomPartition<Vertex>(responseRate, randomSeed);
    /*
     * Init estimators.
     */
    PiEstimator estimator = new DefaultEstimator();
    Map<String, AnalyzerTask> analyzers = loadAnalyzers(graph);
    List<PiEstimator> estimators = new ArrayList<PiEstimator>(1);
    estimators.add(estimator);
    /*
     * Get output directory.
     */
    String output = config.getParam(MODULENAME, "output");
    /*
     * Init sample analyzers.
     */
    String type = config.getParam(MODULENAME, "sampler");
    int dummySeeds = numSeeds;
    SamplerListener listener;
    if ("egocentric".equals(type))
      listener = new IntervalSampleAnalyzer(analyzers, estimators, output);
    else listener = new ConnectionSampleAnalyzer(dummySeeds, analyzers, estimators, output);
    /*
     * Init sampler listener.
     */
    SamplerListenerComposite listeners = new SamplerListenerComposite();
    /*
     * Add analyzers to listener.
     */
    listeners.addComponent(listener);
    /*
     * Init and run sampler.
     */
    if ("snowball".equals(type)) {
      SnowballSampler<Graph, Vertex, Edge> sampler =
          new SnowballSampler<Graph, Vertex, Edge>(randomSeed);
      sampler.setSeedGenerator(seedGenerator);
      sampler.setResponseGenerator(reponseGenerator);
      sampler.setListener(listeners);
      sampler.run(graph);
    } else if ("egocentric".equals(type)) {
      EgoCentricSampler<Graph, Vertex, Edge> sampler = new EgoCentricSampler<Graph, Vertex, Edge>();
      sampler.setListiner(listeners);
      sampler.run(graph, responseRate, numSeeds, new Random(randomSeed));
    } else {
      new RuntimeException("Unknown sampling design.");
    }
  }