示例#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();
  }
示例#2
0
  /** Logs standard statistics information. Posts it to the root agent if required. */
  public void postEvaluationStatistics(final EvolutionState state) {
    super.postEvaluationStatistics(state);

    if (frequency == 0) return; // Frequency == 0 means that we want only final stats
    if (state.generation % frequency != 0) return;

    EvolutionAgent agent = (EvolutionAgent) state;

    StatisticsData data =
        new StatisticsData(
            new Address(agent.getName()), state.generation, getBestIndividual(state));

    if (agent.iamroot) // Local logging
    printStatistics(state, data);
    else { // DRM logging
      /*if(use_collective){
      	data.put("type", EvolutionAgent.STATS_MESSAGE);
      	agent.setContribution(data);
      }else*/
      agent.fireMessage(agent.getRootAddress(), EvolutionAgent.M_STATS, data);
    }
  }
示例#3
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);
          }
        }
      }
    }
  }
示例#4
0
 public void postInitializationStatistics(final EvolutionState state) {
   super.postInitializationStatistics(state);
 }