Exemple #1
0
  /** Sets up parameters. */
  public void setup(final EvolutionState state, final Parameter base) {
    if (!(state instanceof EvolutionAgent))
      state.output.fatal("DRMStatistics requires an  EvolutionAgent", null, null);
    EvolutionAgent agent = (EvolutionAgent) state;

    super.setup(state, base);
    frequency = state.parameters.getIntWithDefault(base.push(P_FREQUENCY), null, 1);
    store_best = state.parameters.getBoolean(base.push(P_STORE_BEST), null, true);
    // use_collective = state.parameters.getBoolean(base.push(P_COLLECTIVE),null,true);

    // If we are root, set up the base filename and the logtable
    if (agent.iamroot) {
      // I'm not sure that outputting everything to the current directory is right
      basefilename =
          System.getProperty("user.dir")
              + File.separator
              + state.parameters.getFile(base.push(P_STATISTICS_FILE), null).getName();
      logtable = new Hashtable();
    } else defaultlog = -3; // Maybe can be useful for recognizing it as a non valid log

    creationtime = System.currentTimeMillis();
  }
Exemple #2
0
  /**
   * This one checks that the stats message was received. If not, the message is sent again up to
   * five times. Run time an best individual of run are logged.
   */
  public void finalStatistics(final EvolutionState state, final int result) {
    super.finalStatistics(state, result);

    EvolutionAgent agent = (EvolutionAgent) state;

    StatisticsData data =
        new StatisticsData(
            new Address(agent.getName()),
            state.generation,
            System.currentTimeMillis() - creationtime,
            getBestIndividual(state),
            getBestIndividual(state));

    if (agent.iamroot) // Local logging
    printStatistics(state, data); // Every statistic will go there
    else { // DRM logging
      for (int i = 0; i < 5; i++) { // Try to send final data 5 times
        IRequest request = agent.fireMessage(agent.getRootAddress(), EvolutionAgent.M_STATS, data);
        while (request.getStatus() == IRequest.WAITING) {
          Thread.yield();
          // try{Thread.sleep(1000);}
          // catch(Exception e){state.output.error("Exception: " + e);}
        }
        if (request.getStatus() == IRequest.DONE) {
          break;
        } else {
          state.output.error("There was an error sending final statistics.");
          try {
            Thread.sleep(1000 * i ^ 2);
          } catch (Exception e) {
            state.output.error("Exception: " + e);
          }
        }
      }
    }
  }