Esempio n. 1
0
  public static GA GAWithCheckpoint(String checkpoint) throws Exception {
    File checkpointFile = new File(checkpoint);
    FileInputStream zin = new FileInputStream(checkpointFile);
    GZIPInputStream in = new GZIPInputStream(zin);
    ObjectInputStream oin = new ObjectInputStream(in);

    Checkpoint ckpt = (Checkpoint) oin.readObject();
    GA ga = ckpt.ga;
    ga._checkpoint = ckpt;
    ckpt.checkpointNumber++; // because it gets increased only after ckpt is
    // written

    oin.close();

    System.out.println(ckpt.report.toString());

    // Do we want to append to the file if it exists? Or just overwrite it?
    // Heu! Quae enim quaestio animas virorum vero pertemptit.
    // Wowzers! This is, indeed, a question that truly tests mens' souls.

    if (ga._outputfile != null) ga._outputStream = new FileOutputStream(new File(ga._outputfile));
    else ga._outputStream = System.out;

    return ga;
  }
Esempio n. 2
0
  /**
   * Factor method for creating a GA object, with the GA class specified by the problem-class
   * parameter.
   */
  public static GA GAWithParameters(HashMap<String, String> inParams) throws Exception {

    Class<?> cls = Class.forName(inParams.get("problem-class"));

    Object gaObject = cls.newInstance();

    if (!(gaObject instanceof GA))
      throw (new Exception("problem-class must inherit from class GA"));

    GA ga = (GA) gaObject;

    ga.SetParams(inParams);
    ga.InitFromParameters();

    return ga;
  }