Esempio n. 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]);
    }
  }
Esempio n. 2
0
  /** Creates a new log and updates the logtable. */
  public int addLog(final EvolutionState state, final String owner) {
    File file = openFile(state, basefilename + owner.substring(owner.lastIndexOf(".")) + ".stat");

    try {
      int log =
          state.output.addLog(
              file,
              Output.V_NO_GENERAL - 1,
              false,
              !state.parameters.getBoolean(new Parameter(P_COMPRESS), null, false),
              state.parameters.getBoolean(new Parameter(P_COMPRESS), null, false));
      logtable.put(owner, new Integer(log));
      return log;
    } catch (IOException i) {
      state.output.fatal(
          "An IOException occurred while trying to create the log " + file + ":\n" + i);
    }
    return -4;
  }