示例#1
0
  /*
   * Constructor.
   * Takes a specified seed - derived from the MASON Mersenne Twister.
   *
   * Specifying the seed is important:
   * although java will seed experiments based on the internal clock,
   * when running batch experiments on a cluster it is possible that
   * two machines will start with the same seed. When gathering data
   * to form distributions representing experiments, it is critical
   * that we do not run simulations with the same seed, they skew the
   * distributions.
   */
  public CBSimulation(long seed, String[] args) {
    super(new MersenneTwisterFast(seed), new Schedule());
    cbsim = this;
    startTime = System.currentTimeMillis();

    // System.out.println("Invoking constructor for simulation object: " + cbsim);

    // open parameter files specified for reading
    try {
      cbsim.xmlFileLocation = args[0];
      cbsim.runFilePath = args[1];
    } catch (Exception e) {
      System.out.println(
          "Parameter file not specified - default values will be used for this input...");
      cbsim.xmlFileLocation = defaultXmlFileLocation;
      cbsim.runFilePath = defaultRunFilePath;
    }

    // set up the ArrayLists that will store information about the cistromes used in the simulation
    names = new ArrayList<String>();
    sources = new ArrayList<String>();
    branchingRates = new ArrayList<Integer>();
    numsInitialReds = new ArrayList<Integer>();

    int position = xmlFileLocation.lastIndexOf("/");
    paramCopyName = xmlFileLocation.substring(position + 1);
  }
示例#2
0
  public static void main(String[] args) {

    // System.out.println("In main() on CBSimulation class");

    // we're not using the GUI if we enter via this method...
    useGUI = false;

    /*
     * this starts the run off
     *
     * the parameters for the simulation will ultimately be read from the parameter file
     */
    try {
      String[] tokens = args[1].split("/");
      batchSize = Long.parseLong(tokens[0]);
      batchNumber = Long.parseLong(tokens[1]);
      jobNumber = Long.parseLong(tokens[2]);
    } catch (Exception e) {
      batchSize = defaultBatchSize;
      batchNumber = defaultBatchNumber;
      jobNumber = defaultJobNumber;
    }

    // System.out.println("Batch size is " + batchSize);
    // System.out.println("Maximum batch size is " + maxBatchSize);
    // System.out.println("Batch number is " + batchNumber);
    // System.out.println("Maximum batch number is " + maxBatchNumber);
    // System.out.println("Job number is " + jobNumber);

    seed = (batchSize * maxBatchSize * 10000000);
    seed += (batchNumber * maxBatchNumber * 10000);
    seed += jobNumber;

    // System.out.println("Random number seed used " + seed);
    CBSimulation cbsim = new CBSimulation(seed, args);

    cbsim.start();

    long steps;
    double time;

    do {

      if (!cbsim.schedule.step(cbsim)) // performs the step, and if return is false, stops looping.
      break;

      steps = cbsim.schedule.getSteps(); // How many steps have been performed?
      time = cbsim.schedule.getTime(); // retrieve the current time in the simulation.

      // System.out.println(cbsim + " currently at step: " + steps);

      final long timeNow = System.currentTimeMillis();

      if (timeNow - startTime >= (timeOut * 3600000)) break;

    } while (steps <= (simulationSteps + 4)); // stopping condition.

    cbsim.finish();
  }