/// <summary> /// Creates a new instance of a evolutionary algoritm based on survival of the fittest. /// Requires a DNA which implements a fitness function /// </summary> /// <param name="population_size">Count of individuals per generation</param> /// <param name="mode">Is maximization or minimization the goal</param> /// <param name="mutation">Probability that mutations happen. More than 0.05 seens to be a bad choice</param> /// <param name="best_can_reproduce">propability that parents can recombine their genes</param> /// <param name="elitism_modifier">Multiplied with log_2(population_size), determines how many individuals may reproduce. Actually meant to be less than 1. But beeing greater than 1 could effect speed positivly</param> /// <exception cref="ArgumentOutOfRangeException">There must be at least 10 individuals in the population_size, less makes no sense and will also cause errors</exception> /// <exception cref="ArgumentException">There are less than 3 / not enough parents, because _reproducable_count is smaller than 3 which is a minimum defined by the developer</exception> public GeneticAlgoritm(int population_size, OptimizationTarget mode, double mutation, double best_can_reproduce = 0.9, double elitism_modifier = 1) { if (population_size < 10) { throw new ArgumentOutOfRangeException($"{nameof(population_size)} must be greater than 9"); } for (int i = 0; i < population_size; i++) { _population.Add(new T()); } _mode = mode; _reproducable_count = (int)((elitism_modifier * Math.Log(population_size, 2)) % population_size); _reproducable_quotient = 1 / _reproducable_count; // used for selection, cannot divide by zero so need to multiply with quotient _best_can_reproduce = best_can_reproduce; _mutation = mutation; if (mode == OptimizationTarget.MAXIMIZATION) { _best_fitness = double.MinValue; } else { _best_fitness = double.MaxValue; } if (_reproducable_count < 3) { throw new ArgumentException($"{nameof(_reproducable_count)} may not be smaller than 3"); } }
public Population(FunctionBase optimizationFunction, int maxPopulationCount, int dimensions, OptimizationTarget optimizationTarget = OptimizationTarget.Minimum) { OptimizationFunction = optimizationFunction; MaxPopulationCount = maxPopulationCount; Dimensions = dimensions; OptimizationTarget = optimizationTarget; CreateNewPopulation(); }
public Population(FunctionBase optimizationFunction, IAlgorithm algorithm, int dimensions, OptimizationTarget optimizationTarget = OptimizationTarget.Minimum) { OptimizationFunction = optimizationFunction; Algorithm = algorithm; MaxPopulationCount = algorithm.MaxPopulation; Dimensions = dimensions; OptimizationTarget = optimizationTarget; CreateNewPopulation(); }
/// <summary> /// Constructor. /// </summary> protected Configuration() { this.SolutionFilePath = ""; this.OutputFilePath = ""; this.ProjectName = ""; this.Timeout = 0; this.PauseOnAssertionFailure = false; this.InteroperationEnabled = true; this.CompilationTarget = CompilationTarget.Execution; this.OptimizationTarget = OptimizationTarget.Release; this.CustomCompilerPassAssemblyPaths = new HashSet <string>(); this.AnalyzeDataFlow = false; this.AnalyzeDataRaces = false; this.DoStateTransitionAnalysis = false; this.ShowControlFlowInformation = false; this.ShowDataFlowInformation = false; this.ShowFullDataFlowInformation = false; this.AssemblyToBeAnalyzed = ""; this.TestMethodName = ""; this.ScheduleFile = ""; this.SchedulingStrategy = SchedulingStrategy.Random; this.SchedulingIterations = 1; this.RandomSchedulingSeed = null; this.PerformFullExploration = false; this.MaxFairSchedulingSteps = 0; this.MaxUnfairSchedulingSteps = 0; this.UserExplicitlySetMaxFairSchedulingSteps = false; this.ParallelBugFindingTasks = 1; this.TestingSchedulerProcessId = -1; this.TestingProcessId = -1; this.ConsiderDepthBoundHitAsBug = false; this.PrioritySwitchBound = 0; this.DelayBound = 0; this.CoinFlipBound = 0; this.SafetyPrefixBound = 0; this.AttachDebugger = false; this.ScheduleIntraMachineConcurrency = false; this.LivenessTemperatureThreshold = 0; this.CacheProgramState = false; this.EnableCycleReplayingStrategy = false; this.BoundOperations = false; this.DynamicEventQueuePrioritization = false; this.EnableDataRaceDetection = false; this.ReportCodeCoverage = false; this.ContainerId = 0; this.NumberOfContainers = 1; this.RemoteApplicationFilePath = ""; this.Verbose = 1; this.ShowWarnings = false; this.EnableDebugging = false; this.EnableProfiling = false; this.KeepTemporaryFiles = false; this.RedirectTestConsoleOutput = true; this.PrintTrace = false; this.SuppressTrace = false; this.ThrowInternalExceptions = false; }
/// <summary> /// Constructor. /// </summary> protected Configuration() { this.SolutionFilePath = string.Empty; this.OutputFilePath = string.Empty; this.ProjectName = string.Empty; this.Timeout = 0; this.CompilationTarget = CompilationTarget.Execution; this.OptimizationTarget = OptimizationTarget.Release; this.CustomCompilerPassAssemblyPaths = new HashSet <string>(); this.AnalyzeDataFlow = false; this.AnalyzeDataRaces = false; this.DoStateTransitionAnalysis = false; this.ShowControlFlowInformation = false; this.ShowDataFlowInformation = false; this.ShowFullDataFlowInformation = false; this.RewriteCSharpVersion = new Version(); this.RuntimeGeneration = 0; this.AssemblyToBeAnalyzed = string.Empty; this.TestingRuntimeAssembly = string.Empty; this.TestMethodName = string.Empty; this.SchedulingStrategy = SchedulingStrategy.Random; this.ReductionStrategy = ReductionStrategy.None; this.SchedulingIterations = 1; this.RandomSchedulingSeed = null; this.IncrementalSchedulingSeed = false; this.PerformFullExploration = false; this.MaxFairSchedulingSteps = 0; this.MaxUnfairSchedulingSteps = 0; this.UserExplicitlySetMaxFairSchedulingSteps = false; this.ParallelBugFindingTasks = 1; this.RunAsParallelBugFindingTask = false; this.TestingSchedulerEndPoint = Guid.NewGuid().ToString(); this.TestingSchedulerProcessId = -1; this.TestingProcessId = 0; this.ConsiderDepthBoundHitAsBug = false; this.PrioritySwitchBound = 0; this.DelayBound = 0; this.CoinFlipBound = 0; this.SafetyPrefixBound = 0; this.EnableLivenessChecking = true; this.LivenessTemperatureThreshold = 0; this.EnableCycleDetection = false; this.EnableUserDefinedStateHashing = false; this.EnableMonitorsInProduction = false; this.EnableNoApiCallAfterTransitionStmtAssertion = true; this.AttachDebugger = false; this.ScheduleFile = string.Empty; this.ScheduleTrace = string.Empty; this.EnableDataRaceDetection = false; this.ReportCodeCoverage = false; this.ReportActivityCoverage = false; this.DebugActivityCoverage = false; this.ContainerId = 0; this.NumberOfContainers = 1; this.RemoteApplicationFilePath = string.Empty; this.Verbose = 1; this.ShowWarnings = false; this.EnableDebugging = false; this.EnableProfiling = false; this.KeepTemporaryFiles = false; this.EnableColoredConsoleOutput = false; this.ThrowInternalExceptions = false; this.DisableEnvironmentExit = true; }
public PopulationBuilder WithOptimizationTarget(OptimizationTarget optimizationTarget) { _optimizationTarget = optimizationTarget; return(this); }
/// <summary> /// Constructor. /// </summary> protected Configuration() { this.SolutionFilePath = ""; this.OutputFilePath = ""; this.ProjectName = ""; this.Timeout = 0; this.PauseOnAssertionFailure = false; this.InteroperationEnabled = true; this.CompilationTarget = CompilationTarget.Execution; this.OptimizationTarget = OptimizationTarget.Release; this.CustomCompilerPassAssemblyPaths = new HashSet<string>(); this.AnalyzeDataFlow = false; this.AnalyzeDataRaces = false; this.DoStateTransitionAnalysis = false; this.ShowControlFlowInformation = false; this.ShowDataFlowInformation = false; this.ShowFullDataFlowInformation = false; this.AssemblyToBeAnalyzed = ""; this.ScheduleFile = ""; this.SchedulingStrategy = SchedulingStrategy.Random; this.SchedulingIterations = 1; this.RandomSchedulingSeed = null; this.PerformFullExploration = false; this.MaxSchedulingSteps = 0; this.ParallelBugFindingTasks = 1; this.TestingSchedulerProcessId = -1; this.TestingProcessId = -1; this.ConsiderDepthBoundHitAsBug = false; this.PrioritySwitchBound = 0; this.DelayBound = 0; this.CoinFlipBound = 0; this.SafetyPrefixBound = 0; this.AttachDebugger = false; this.ScheduleIntraMachineConcurrency = false; this.LivenessTemperatureThreshold = 0; this.CacheProgramState = false; this.EnableCycleReplayingStrategy = false; this.BoundOperations = false; this.DynamicEventQueuePrioritization = false; this.EnableDataRaceDetection = false; this.EnableVisualization = false; this.ContainerId = 0; this.NumberOfContainers = 1; this.RemoteApplicationFilePath = ""; this.Verbose = 1; this.ShowWarnings = false; this.EnableDebugging = false; this.EnableProfiling = false; this.KeepTemporaryFiles = false; this.RedirectTestConsoleOutput = true; this.PrintTrace = false; this.SuppressTrace = false; this.ThrowInternalExceptions = false; }