/// <summary> /// Initializes a new instance of the <see cref="AutoConfigFitness"/> class. /// </summary> /// <param name="targetFitness">The target fitness.</param> /// <param name="targetChromosome">The target chromosome.</param> public AutoConfigFitness(IFitness targetFitness, IChromosome targetChromosome) { m_targetFitness = targetFitness; m_targetChromosome = targetChromosome; PopulationMinSize = 100; PopulationMaxSize = 100; Termination = new TimeEvolvingTermination(TimeSpan.FromSeconds(30)); TaskExecutor = new LinearTaskExecutor(); }
public void Start_Task_TaskRan() { var pipeline = ""; var target = new LinearTaskExecutor(); target.Add(() => pipeline += "1"); target.Add(() => pipeline += "2"); target.Add(() => pipeline += "3"); Assert.IsTrue(target.Start()); Assert.AreEqual("123", pipeline); }
public void Start_TakeMoreThanTimeout_False() { var pipeline = ""; var target = new LinearTaskExecutor (); target.Add (() => pipeline += "1"); target.Add (() => { pipeline += "2"; Thread.Sleep(100); }); target.Add (() => pipeline += "3"); target.Timeout = TimeSpan.FromMilliseconds(50); Assert.IsFalse(target.Start ()); Assert.AreEqual ("12", pipeline); }
public void Stop_ManyTasks_True() { var pipeline = ""; var target = new LinearTaskExecutor(); target.Add(() => pipeline += "1"); target.Add(() => { pipeline += "2"; Thread.Sleep(1000); }); target.Add(() => pipeline += "3"); Parallel.Invoke( () => Assert.IsTrue(target.Start()), () => { Thread.Sleep(5); target.Stop(); }); }
/// <summary> /// Initializes a new instance of the <see cref="GeneticSharp.Domain.GeneticAlgorithm"/> class. /// </summary> /// <param name="population">The chromosomes population.</param> /// <param name="fitness">The fitness evaluation function.</param> /// <param name="selection">The selection operator.</param> /// <param name="crossover">The crossover operator.</param> /// <param name="mutation">The mutation operator.</param> public GeneticAlgorithm( Population population, IFitness fitness, ISelection selection, ICrossover crossover, IMutation mutation) { ExceptionHelper.ThrowIfNull("Population", population); ExceptionHelper.ThrowIfNull("fitness", fitness); ExceptionHelper.ThrowIfNull("selection", selection); ExceptionHelper.ThrowIfNull("crossover", crossover); ExceptionHelper.ThrowIfNull("mutation", mutation); Population = population; Fitness = fitness; Selection = selection; Crossover = crossover; Mutation = mutation; Reinsertion = new ElitistReinsertion(); Termination = new GenerationNumberTermination(1); CrossoverProbability = DefaultCrossoverProbability; MutationProbability = DefaultMutationProbability; TimeEvolving = TimeSpan.Zero; State = GeneticAlgorithmState.NotStarted; TaskExecutor = new LinearTaskExecutor(); }