protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; var numberOfParentsSolutionsToSelect = Parameters.NumberOfParentsSolutionsToSelect; for (var i = 0; i < offspringPopulationSize; i++) { var parentsPopulation = new Solution[numberOfParentsSolutionsToSelect]; for (var j = 0; j < numberOfParentsSolutionsToSelect; j++) { parentsPopulation[j] = ParentsSelector.Select(BasePopulation); } OffspringPopulation[i] = StdDeviationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = RotationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = ObjectRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); } BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); }
private TreeNode SExprConstructPipeline(EvaluatorBase evaluator, TreeNode [] args) { StringBuilder builder = new StringBuilder(); List <string> elements = new List <string> (); for (int i = 0; i < args.Length; i++) { TreeNode node = evaluator.Evaluate(args[i]); if (!(node is LiteralNodeBase)) { throw new ArgumentException("node must evaluate to a literal"); } string value = node.ToString().Trim(); if (value.Length == 0) { continue; } elements.Add(value); } for (int i = 0; i < elements.Count; i++) { builder.Append(elements[i]); if (i < elements.Count - 1) { builder.Append(" ! "); } } return(new StringLiteral(builder.ToString())); }
protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; for (var i = 0; i < offspringPopulationSize; i++) { OffspringPopulation[i] = ParentsSelector.Select(BasePopulation); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); } BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); }
private TreeNode SExprTestElement(EvaluatorBase evaluator, TreeNode [] args) { if (args.Length != 1) { throw new ArgumentException("gst-test-element accepts one argument"); } TreeNode arg = evaluator.Evaluate(args[0]); if (!(arg is StringLiteral)) { throw new ArgumentException("gst-test-element requires a string argument"); } StringLiteral element_node = (StringLiteral)arg; return(new BooleanLiteral(TestPipeline(element_node.Value))); }
private TreeNode SExprConstructPipelinePart(EvaluatorBase evaluator, TreeNode [] args, bool element) { StringBuilder builder = new StringBuilder(); TreeNode list = new TreeNode(); foreach (TreeNode arg in args) { list.AddChild(evaluator.Evaluate(arg)); } list = list.Flatten(); for (int i = 0; i < list.ChildCount; i++) { TreeNode node = list.Children[i]; string value = node.ToString().Trim(); builder.Append(value); if (i == 0) { if (list.ChildCount > 1) { builder.Append(element ? ' ' : ','); } continue; } else if (i % 2 == 1) { builder.Append('='); } else if (i < list.ChildCount - 1) { builder.Append(element ? ' ' : ','); } } return(new StringLiteral(builder.ToString())); }
protected Solution[] InitializePopulations(EvaluatorBase evaluator, ISeedingProcessor seedingProcessor = null) { var population = PopulationGenerator.GeneratePopulation(Parameters); if (seedingProcessor != null) { Stoper.Restart(); population = seedingProcessor.Seed(population); Stoper.Stop(); Statistics.SeedingTime = Stoper.Elapsed; } foreach (var solution in population) { solution.FitnessScore = evaluator.Evaluate(solution); } for (var i = 0; i < OffspringPopulation.Length; i++) { OffspringPopulation[i] = SolutionsFactory.Create(Parameters); } return(population); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(EvaluatorBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_Evaluate, serviceImpl.Evaluate).Build()); }
private Solution Evolution(EvaluatorBase evaluator) { var bestSolution = BasePopulation.First(); var numberOfGenerationBestSolutionTakenFrom = 0; //if (Parameters.TrackEvolutionSteps) //{ // //EvolutionStepsSimple.Add(BasePopulation.First()); //} var numberOfGenerations = Parameters.NumberOfGenerations; Stoper.Restart(); for (var i = 0; i < numberOfGenerations; i++) { //MutationRuleSupervisor.SaveBestFitness(BasePopulation.First()); if (Parameters.TrackEvolutionSteps) { CurrentEvolutionStep = new EvolutionStep(BasePopulation, OffspringPopulation.Length); } Evolve(evaluator); if (Parameters.TrackEvolutionSteps) { EvolutionSteps.Add(i, CurrentEvolutionStep); } if (bestSolution.FitnessScore < BasePopulation.First().FitnessScore) { bestSolution = BasePopulation.First(); numberOfGenerationBestSolutionTakenFrom = i; } //MutationRuleSupervisor.EnsureRuleFullfillment(BasePopulation); //if (Parameters.TrackEvolutionSteps) // EvolutionStepsSimple.Add(BasePopulation.First()); //Console.WriteLine(BasePopulation.First().FitnessScore); } //Console.WriteLine("###########################################################################"); //Console.WriteLine("###########################################################################"); //Console.WriteLine("###########################################################################"); //Console.WriteLine("Best solution taken from generation " + numberOfGenerationBestSolutionTakenFrom); //Console.WriteLine("###########################################################################"); //Console.Write("Best solution stdDevs = ["); //foreach (var stdDeviationsCoefficient in bestSolution.StdDeviationsCoefficients) //{ // Console.Write(stdDeviationsCoefficient + ", "); //} //Console.WriteLine("]\n"); //Console.WriteLine("###########################################################################"); //Console.Write("Last evolved best solution stdDevs = ["); //foreach (var stdDeviationsCoefficient in BasePopulation.First().StdDeviationsCoefficients) //{ // Console.Write(stdDeviationsCoefficient + ", "); //} //Console.WriteLine("]\n"); //Console.WriteLine("###########################################################################"); //Console.WriteLine("###########################################################################"); //Console.WriteLine("###########################################################################"); Stoper.Stop(); Statistics.NumberOfGenerationBestSolutionTakenFrom = numberOfGenerationBestSolutionTakenFrom; Statistics.TotalEvolutionTime = Stoper.Elapsed; Statistics.MeanSingleGenerationEvolutionTime = TimeSpan.FromTicks(Statistics.TotalEvolutionTime.Ticks / numberOfGenerations); //Statistics.MeanStdDevsMutationTime = TimeSpan.FromTicks(Statistics.MeanStdDevsMutationTime.Ticks / numberOfGenerations); //Statistics.MeanRotationsMutationTime = TimeSpan.FromTicks(Statistics.MeanRotationsMutationTime.Ticks / numberOfGenerations); //Statistics.MeanObjectMutationTime = TimeSpan.FromTicks(Statistics.MeanObjectMutationTime.Ticks / numberOfGenerations); //Statistics.MeanEvaluationTime = TimeSpan.FromTicks(Statistics.MeanEvaluationTime.Ticks / numberOfGenerations); //Statistics.MeanSurvivorsSelectionTime = TimeSpan.FromTicks(Statistics.MeanSurvivorsSelectionTime.Ticks / numberOfGenerations); Statistics.LastFitnessScore = BasePopulation.First().FitnessScore; Statistics.BestFitnessScore = bestSolution.FitnessScore; Stoper.Reset(); //return BasePopulation.First(); return(bestSolution); }
public Solution RunEvolution(EvaluatorBase evaluator) { BasePopulation = InitializePopulations(evaluator); return(Evolution(evaluator)); }
public Solution RunEvolution(EvaluatorBase evaluator, ISeedingProcessor seedingProcessor) { BasePopulation = InitializePopulations(evaluator, seedingProcessor); return(Evolution(evaluator)); }
protected abstract void Evolve(EvaluatorBase evaluator);
private TreeNode SExprConstructCaps(EvaluatorBase evaluator, TreeNode [] args) { return(SExprConstructPipelinePart(evaluator, args, false)); }
private TreeNode SExprConstructElement(EvaluatorBase evaluator, TreeNode [] args) { return(SExprConstructPipelinePart(evaluator, args, true)); }
//HACKS TODO protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; //var stdDevsMutationTime = TimeSpan.Zero; //var rotationsMutationTime = TimeSpan.Zero; //var objectMutationTime = TimeSpan.Zero; //var evaluationTime = TimeSpan.Zero; //var stoper = new Stopwatch(); for (var i = 0; i < offspringPopulationSize; i++) { OffspringPopulation[i] = ParentsSelector.Select(BasePopulation); if (Parameters.TrackEvolutionSteps) { CurrentMutation = new MutationStep(ParentsSelector.LastSelectedParentIndex, OffspringPopulation[i]); } //stoper.Restart(); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //stdDevsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //rotationsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //objectMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); //stoper.Stop(); //evaluationTime += stoper.Elapsed; if (Parameters.TrackEvolutionSteps) { CurrentMutation.Offspring = OffspringPopulation[i].DeepCopyByExpressionTree(); CurrentEvolutionStep.Mutations.Add(CurrentMutation); } } //stoper.Restart(); BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); //stoper.Stop(); //Statistics.MeanSurvivorsSelectionTime += stoper.Elapsed; //Statistics.MeanStdDevsMutationTime += TimeSpan.FromTicks(stdDevsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanRotationsMutationTime += TimeSpan.FromTicks(rotationsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanObjectMutationTime += TimeSpan.FromTicks(objectMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanEvaluationTime += TimeSpan.FromTicks(evaluationTime.Ticks / offspringPopulationSize); if (Parameters.TrackEvolutionSteps) { CurrentEvolutionStep.NewPopulation = BasePopulation.DeepCopyByExpressionTree(); } }
private IQueryable <T> ApplySpecificacion(ISpecificationBase <T> spec) { return(EvaluatorBase <T> .GetQuery(_dbContext.Set <T>().AsNoTracking(), spec)); }
public SeedingProcessor(EvaluatorBase evaluator, ConstraintsBuilderBase constraintsBuilder, IList <Point> positivePoints) { _evaluator = evaluator; _constraintsBuilder = constraintsBuilder; _positivePoints = positivePoints.ToArray(); }