public PolicyBased_RHE_Agent( PD_AI_Macro_Agent_Base generator_agent, PD_AI_Macro_Agent_Base mutator_agent, List <PD_GameStateEvaluator> game_state_evaluators, P_RHE_Replacement_Rule replacement_rule, int genome_length, int num_generations, double initial_MutationRate, double final_MutationRate, int num_evaluation_repetitions ) { Generator_Agent = generator_agent; Mutator_Agent = mutator_agent; Game_State_Evaluators = game_state_evaluators; Replacement_Rule = replacement_rule; Genome_Length = genome_length; Num_Generations = num_generations; Initial_MutationRate = initial_MutationRate; Final_MutationRate = final_MutationRate; Mutation_Rate = initial_MutationRate; Num_Evaluation_Repetitions = num_evaluation_repetitions; Num_Successful_Mutations_ThisTime = 0; Num_Successful_Mutations_Different_FirstAction_ThisTime = 0; }
public PolicyBased_RHE_Agent( PD_AI_Macro_Agent_Base generator_agent, PD_AI_Macro_Agent_Base mutator_agent, List <PD_GameStateEvaluator> gameStateEvaluators, P_RHE_Replacement_Rule replacement_rule, int genome_length, int num_generations, double mutation_rate, int num_evaluation_repetitions ) : this( generator_agent, mutator_agent, gameStateEvaluators, replacement_rule, genome_length, num_generations, mutation_rate, mutation_rate, num_evaluation_repetitions ) { }
public bool IsBetterThan( RH_Individual other, P_RHE_Replacement_Rule replacementRule ) { if (this.EvaluationScores.Count != other.EvaluationScores.Count) { throw new System.Exception("not equal number of evaluations"); } switch (replacementRule) { case P_RHE_Replacement_Rule.Average_Better: double thisIndividual_average = 0; foreach (var score in EvaluationScores) { thisIndividual_average += score; } thisIndividual_average /= EvaluationScores.Count; double otherIndividual_average = 0; foreach (var score in other.EvaluationScores) { otherIndividual_average += score; } otherIndividual_average /= other.EvaluationScores.Count; if (thisIndividual_average > otherIndividual_average) { return(true); } return(false); case P_RHE_Replacement_Rule.All_Better: // all scores of this individual need to be better // than all scores of the other individual. // => // if any score of the other individual is equal to or better // than any score of this individual, return false for (int i = 0; i < EvaluationScores.Count; i++) { if (other.EvaluationScores[i] >= EvaluationScores[i]) { return(false); } } // otherwise, return true return(true); case P_RHE_Replacement_Rule.All_Equal_Or_Better: // all scores of this individual need to be equal to or better // than all scores of the other individual. // => // if any score of the other individual is better // than any score of this individual, return false for (int i = 0; i < EvaluationScores.Count; i++) { if (other.EvaluationScores[i] > EvaluationScores[i]) { return(false); } } // otherwise, return true return(true); case P_RHE_Replacement_Rule.One_Better__Rest_Equal_Or_Better: // one score of this individual needs to be better than a score of the other individual. // The rest need to be equal to or better than the other's // => // check if there is one better bool oneBetter = false; for (int i = 0; i < EvaluationScores.Count; i++) { if (EvaluationScores[i] > other.EvaluationScores[i]) { oneBetter = true; } } // if none better, then false if (oneBetter == false) { return(false); } // check if all scores of this individual // are equal to or better than // all scores of the other individual else { // if any score of the other individual // is better than any score of this individual // then return false for (int i = 0; i < EvaluationScores.Count; i++) { if (other.EvaluationScores[i] > EvaluationScores[i]) { return(false); } } } return(true); case P_RHE_Replacement_Rule.One_Better__Rest_Whatever: // one score of this individual needs to be better than a score of the other individual. // The rest can be whatever. // => // check if there is one better for (int i = 0; i < EvaluationScores.Count; i++) { if (EvaluationScores[i] > other.EvaluationScores[i]) { return(true); } } return(false); } for (int i = 0; i < EvaluationScores.Count; i++) { // if other is better than me, then false. // if other is equal to me, then false. if (other.EvaluationScores[i] >= EvaluationScores[i]) { return(false); } } return(true); }