/// <summary> /// This method is called after a Checkpoint /// is restored from but before the run starts up again. /// You might use this to set up file pointers that were lost, etc. /// </summary> public virtual void ResetFromCheckpoint() { Output.Restart(); // may throw an exception if there's a bad file Exchanger.ReinitializeContacts(this); Evaluator.ReinitializeContacts(this); }
///// <summary> ///// This will be called to create your evolution state; immediately ///// after the constructor is called, ///// the Parameters, random, and output fields will be set ///// for you. The constructor probably won't be called ever if ///// restoring (deserializing) from a Checkpoint. ///// </summary> //public EvolutionState() //{ //} /// <summary> /// Unlike for other Setup() methods, ignore the base; it will always be null. /// </summary> /// <seealso cref="IPrototype.Setup(IEvolutionState,IParameter)"/> public virtual void Setup(IEvolutionState state, IParameter paramBase) { // set up the per-thread data Data = new Hashtable[Random.Length]; for (int i = 0; i < Data.Length; i++) { Data[i] = new Hashtable(); } // we ignore the base, it's worthless anyway for EvolutionState IParameter p = new Parameter(P_CHECKPOINT); Checkpoint = Parameters.GetBoolean(p, null, false); p = new Parameter(P_CHECKPOINTPREFIX); CheckpointPrefix = Parameters.GetString(p, null); if (CheckpointPrefix == null) { // check for the old-style checkpoint prefix parameter var p2 = new Parameter(P_CHECKPOINTPREFIX_OLD); CheckpointPrefix = Parameters.GetString(p2, null); if (CheckpointPrefix == null) { Output.Fatal("No checkpoint prefix specified.", p); // indicate the new style, not old parameter } else { Output.Warning("The parameter \"prefix\" is deprecated. Please use \"checkpoint-prefix\".", p2); } } else { // check for the old-style checkpoint prefix parameter as an acciental duplicate var p2 = new Parameter(P_CHECKPOINTPREFIX_OLD); if (Parameters.GetString(p2, null) != null) { Output.Warning("You have BOTH the deprecated parameter \"prefix\" and its replacement \"checkpoint-prefix\" defined. The replacement will be used, Please remove the \"prefix\" parameter.", p2); } } p = new Parameter(P_CHECKPOINTMODULO); CheckpointModulo = Parameters.GetInt(p, null, 1); if (CheckpointModulo == 0) { Output.Fatal("The Checkpoint modulo must be an integer >0.", p); } p = new Parameter(P_CHECKPOINTDIRECTORY); if (Parameters.ParameterExists(p, null)) { CheckpointDirectory = Parameters.GetDirectory(p); if (CheckpointDirectory == null) { Output.Fatal("The checkpoint directory name is invalid: " + CheckpointDirectory, p); } else if (!Path.IsPathRooted(CheckpointDirectory.FullName)) { Output.Fatal("The checkpoint directory location is not a directory: " + CheckpointDirectory, p); } } else { CheckpointDirectory = null; } p = new Parameter(P_EVALUATIONS); if (Parameters.ParameterExists(p, null)) { NumEvaluations = Parameters.GetInt(p, null, 1); // 0 would be UNDEFINED if (NumEvaluations <= 0) { Output.Fatal("If defined, the number of evaluations must be an integer >= 1", p, null); } } p = new Parameter(P_GENERATIONS); if (Parameters.ParameterExists(p, null)) { NumGenerations = Parameters.GetInt(p, null, 1); // 0 would be UDEFINED if (NumGenerations <= 0) { Output.Fatal("If defined, the number of generations must be an integer >= 1.", p, null); } } if (NumEvaluations != UNDEFINED && NumGenerations != UNDEFINED) // both defined { state.Output.Warning("Both generations and evaluations defined: generations will be ignored and computed from the evaluations."); NumGenerations = UNDEFINED; } else if (NumEvaluations == UNDEFINED && NumGenerations == UNDEFINED) // uh oh, something must be defined { Output.Fatal("Either evaluations or generations must be defined.", new Parameter(P_GENERATIONS), new Parameter(P_EVALUATIONS)); } p = new Parameter(P_QUITONRUNCOMPLETE); QuitOnRunComplete = Parameters.GetBoolean(p, null, false); /* Set up the singletons */ p = new Parameter(P_INITIALIZER); Initializer = (Initializer)(Parameters.GetInstanceForParameter(p, null, typeof(Initializer))); Initializer.Setup(this, p); p = new Parameter(P_FINISHER); Finisher = (IFinisher)(Parameters.GetInstanceForParameter(p, null, typeof(IFinisher))); Finisher.Setup(this, p); p = new Parameter(P_BREEDER); Breeder = (Breeder)(Parameters.GetInstanceForParameter(p, null, typeof(Breeder))); Breeder.Setup(this, p); p = new Parameter(P_EVALUATOR); Evaluator = (IEvaluator)(Parameters.GetInstanceForParameter(p, null, typeof(IEvaluator))); Evaluator.Setup(this, p); p = new Parameter(P_STATISTICS); Statistics = (Statistics)(Parameters.GetInstanceForParameterEq(p, null, typeof(Statistics))); Statistics.Setup(this, p); p = new Parameter(P_EXCHANGER); Exchanger = (Exchanger)(Parameters.GetInstanceForParameter(p, null, typeof(Exchanger))); Exchanger.Setup(this, p); p = new Parameter(P_INNOVATIONNUMBER); InnovationNumber = Parameters.GetLong(p, null, long.MinValue); Generation = 0; }