Ejemplo 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;
  }
Ejemplo 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;
  }
Ejemplo n.º 3
0
 /**
  * Runs the GA if the time since the last application of the GA is greater than the threshold.
  *
  * @param tStamp is the actual time
  * @param envState is the environment state.
  */
 public void runGA(int tStamp, double[] envState) {
   if ((double) tStamp - getAverageClTime() >= Config.theta_GA && macroClSum > 0) {
     setTimeOfClassifiers(tStamp);
     ga.runGA(envState, this, tStamp);
   }
 } // end runGA