示例#1
0
  /** Prints StatisticsData structures to local logs. */
  public void printStatistics(final EvolutionState state, StatisticsData data) {
    int log = -6;
    String sender;

    EvolutionAgent agent = (EvolutionAgent) state;

    sender = data.sender.name;
    if (logtable.containsKey(sender)) log = ((Integer) logtable.get(sender)).intValue();
    else log = addLog(state, sender);
    if (log < 0) {
      if (defaultlog < 0) defaultlog = addLog(state, agent.getName());
      state.output.message(
          "Received a stats message from an unknown sender, will be logged to: "
              + ((Integer) logtable.get(new Integer(defaultlog))).intValue());
      log = defaultlog;
    }
    state.output.println(data.toStringForHumans(), Output.V_NO_GENERAL, log);

    if (store_best && data.finalStats) {
      for (int i = 0; i < data.best_of_run.length; i++)
        storeIndividual(
            state,
            basefilename + data.sender.name.substring(data.sender.name.lastIndexOf(".")) + ".best",
            data.best_of_run[i]);
    }
  }
示例#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);
          }
        }
      }
    }
  }