public override TryGetModelResult TryGetArithmeticModel(IArithmeticSolvingContext context, out IArithmeticModel model) { InitializeCustomSolver(context); this.bestModel = context.InitialModel; ResetExplorationParameters(true); TryGetModelResult result = StartSearch(out model); return(result); }
public override TryGetModelResult TryGetArithmeticModel(IArithmeticSolvingContext context, out IArithmeticModel model) { InitializeCustomSolver(context); this.variableCount = context.Variables.ToArray <IArithmeticVariable>().Length; model = null; TryGetModelResult result = (this.variableCount == 0)? TryGetModelResult.NoModelFound:Evolve(out model); return(result); }
private bool Terminate(out TryGetModelResult result, out IArithmeticModel model) { for (int i = 0; i < this.populationSize; i++) { if (base.context.IsValidModel(this.parentPopulation[i].currentModel)) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "es method found solution after {0} fitness evaluations", base.fitnessEvaluations); base.logManager.LogSuccess(base.fitnessEvaluations); } base.modelBuilder = base.context.CreateArithmeticModelBuilder(this.parentPopulation[i].currentModel); model = base.modelBuilder.ToArithmeticModel(); result = TryGetModelResult.Success; Dispose(); return(true); } } if (base.context.HasTimedOut) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "es method timed out after {0} unsuccessful fitness evaluations", base.fitnessEvaluations); base.logManager.LogFailure(); } result = TryGetModelResult.Timeout; model = null; Dispose(); return(true); } else { result = TryGetModelResult.NoModelFound; model = null; if (base.fitnessEvaluations >= base.fitnessBudget) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "es method failed to find a solution after {0} fitness evaluations", base.fitnessEvaluations); base.logManager.LogFailure(); } Dispose(); return(true); } return(false); } }
private bool Terminate(out TryGetModelResult result, out IArithmeticModel model) { model = base.modelBuilder.ToArithmeticModel(); if (base.context.IsValidModel(model)) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "AVM found solution after {0} fitness evaluations", base.fitnessEvaluations); base.logManager.LogSuccess(base.fitnessEvaluations); } Dispose(); result = TryGetModelResult.Success; return(true); } model.Dispose(); model = null; if (base.context.HasTimedOut) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "AVM timed out after {0} unsuccessful fitness evaluations", base.fitnessEvaluations); base.logManager.LogFailure(); } Dispose(); result = TryGetModelResult.Timeout; return(true); } else if (base.fitnessEvaluations >= base.fitnessBudget) { if (IsLoggingEnabled) { base.context.Host.Log.LogMessage(PexLogCategories.ArithmeticSolver, "AVM failed to find a solution after {0} fitness evaluations", base.fitnessEvaluations); base.logManager.LogFailure(); } Dispose(); result = TryGetModelResult.NoModelFound; return(true); } else { result = TryGetModelResult.NoModelFound; return(false); } }
private TryGetModelResult Evolve(out IArithmeticModel model) { TryGetModelResult result = TryGetModelResult.None; //SafeDebugger.Break(); CreateInitialPopulation(); EvaluateIntermediatePopulation(); for (int i = 0; i < this.populationSize; i++) { this.parentPopulation[i] = this.intermediatePopulation[i].MakeDeepCopy(); } while (!Terminate(out result, out model)) { ClearIntermediatePopulation(); if (this.populationSize > 1 && this.recombination != RecombinationStrategy.None && this.parentPopulation.Length > 1) { ESSolution offspring = null; for (int i = 0; i < this.offspringPopulationSize; i++) { Recombine(ref offspring); if (offspring != null) { Mutate(ref offspring); this.intermediatePopulation.Add(offspring.MakeDeepCopy()); offspring.Dispose(); offspring = null; } } } else { ESSolution offspring = null; int poolIndex = 0; for (int i = 0; i < this.offspringPopulationSize; i++) { if (poolIndex >= this.parentPopulation.Length) { poolIndex = 0; } offspring = this.parentPopulation[poolIndex].MakeDeepCopy(); Mutate(ref offspring); this.intermediatePopulation.Add(offspring.MakeDeepCopy()); offspring.Dispose(); offspring = null; poolIndex++; } } EvaluateIntermediatePopulation(); //selection if (!this.selectFromOffspringOnly) { for (int i = 0; i < this.populationSize; i++) { this.intermediatePopulation.Add(this.parentPopulation[i].MakeDeepCopy()); } } this.intermediatePopulation.Sort(); for (int i = 0; i < this.populationSize && i < this.intermediatePopulation.Count; i++) { this.parentPopulation[i].Dispose(); this.parentPopulation[i] = this.intermediatePopulation[i].MakeDeepCopy(); } } return(result); }