private List <String> GreedyKnapsack(int?seed, bool penalized, EffectType type) { List <String> results = new List <String>(); var evaluations = GenerateProblems(); foreach (var evaluation in evaluations) { ((CBinaryKnapsackEvaluation)evaluation).bSetPenalized(penalized); IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); OnePointCrossover crossover = new OnePointCrossover(0.5, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); TournamentSelection selection = new TournamentSelection(2, seed); KnapsackGA ga = new KnapsackGA(((CBinaryKnapsackEvaluation)evaluation), stopCondition, generator, selection, crossover, mutation, 50, type, seed); ga.Run(); results.Add(FormatSave(ga)); ReportOptimizationResult(ga.Result, debug: true); } return(results); }
private static void Lab73(int?seed = null) { string filename = "lab73_order3.txt"; IEvaluation <bool> evaluation = new CBinaryStandardDeceptiveConcatenationEvaluation(3, 100); RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(evaluation.dMaxValue, 30); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); OnePointCrossover crossover = new OnePointCrossover(0.5, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); TournamentSelection selection = new TournamentSelection(2, seed); GAwithDSM ga = new GAwithDSM(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); SaveDSMs(ga.dsms, filename); filename = "lab73_order10.txt"; evaluation = new CBinaryBimodalDeceptiveConcatenationEvaluation(10, 100); stopCondition = new RunningTimeStopCondition(evaluation.dMaxValue, 30); generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); crossover = new OnePointCrossover(0.5, seed); mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); selection = new TournamentSelection(2, seed); ga = new GAwithDSM(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); SaveDSMs(ga.dsms, filename); }
public MutatedIslandGA(IEvaluation <bool> evaluation, AStopCondition stopCondition, AGenerator <bool> generator, ASelection selection, ACrossover crossover, IMutation <bool> mutation, int populationSize) : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize) { var moreMutation = new BinaryBitFlipMutation(1, evaluation); int mutatedPop = populationSize / 10 % 2 == 1 ? populationSize / 10 - 1 : populationSize / 10; mutatedPop = mutatedPop == 0 ? 2 : mutatedPop; mutantIsland = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, moreMutation, mutatedPop); mutantIsland.Initialize(); }
private static void Lab4BinaryGA(IEvaluation <bool> evaluation, ASelection selection, ACrossover crossover, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); GeneticAlgorithm <bool> ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); ReportOptimizationResult(ga.Result); }
private static void Lab4BinaryMutatedGA(IEvaluation <bool> evaluation, ASelection selection, ACrossover crossover, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(0, evaluation, seed); MutatedIslandGA miga = new MutatedIslandGA(evaluation, stopCondition, generator, selection, crossover, mutation, 20); miga.Run(); ReportOptimizationResult(miga.Result); }
private String Lab4BinaryGA(IEvaluation <bool> evaluation, ASelection selection, ACrossover crossover, double pMut, int popSize, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(pMut, evaluation, seed); GeneticAlgorithm <bool> ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 20); ga.Run(); return(FormatSave(ga)); //ReportOptimizationResult(ga.Result); }
private String Lab4BinaryGaMutationCrossover(IEvaluation <bool> evaluation, double pMut, double pCro, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 500); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(pMut, evaluation, seed); OnePointCrossover crossover = new OnePointCrossover(pCro, seed); TournamentSelection selection = new TournamentSelection(5, seed); GeneticAlgorithm <bool> ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); return(FormatSave(ga)); }
private String Lab6BinaryGA(IEvaluation <bool> evaluation, ASelection selection, ACrossover crossover, double pMut, int popSize, Dictionary <String, int> problemStallCounter, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(pMut, evaluation, seed); GAStallDetection <bool> ga = new GAStallDetection <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, popSize, 20); ga.Run(); //Console.WriteLine(evaluation.GetType().Name + " : " + ga.countStalling); DictionaryCounterUpdate(problemStallCounter, evaluation.GetType().Name, ga.countStalling); //ReportOptimizationResult(ga.Result); return(FormatSave(ga)); }
private static void Lab5(int?seed) { CBinaryKnapsackEvaluation evaluation = new CBinaryKnapsackEvaluation(EBinaryKnapsackInstance.knapPI_1_100_1000_1); IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); OnePointCrossover crossover = new OnePointCrossover(0.5, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); TournamentSelection selection = new TournamentSelection(2, seed); GeneticAlgorithm <bool> ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); ReportOptimizationResult(ga.Result); }
private static void Lab8BiObjectiveBinaryGA(IEvaluation <bool, Tuple <double, double> > evaluation, int?seed) { RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(5); DefaultDominationComparer dominationComparer = new DefaultDominationComparer(); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); OnePointCrossover crossover = new OnePointCrossover(0.5, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); SampleBiObjectiveSelection selection = new SampleBiObjectiveSelection(dominationComparer, seed); BiObjective.GeneticAlgorithm <bool> ga = new BiObjective.GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 100, seed); ga.Run(); ReportBiObjectiveOptimizationResult(ga.Result); }
static void Main(string[] args) { var random = new Random(); // Generate a list of products with random weights and prices var products = new List <Product>(); for (var i = 0; i < 50; i++) { products.Add(new Product(random.Next(100) + 1, random.Next(100) + 1)); } var maxWeight = 200; var populationFactory = new BasicBinaryPopulationFactory(products.Count, false); // Terminate if the highest fitness score remains the same after X generations var termination = new StalenessTermination <BitArray>(5); var fitnessEvaluator = new KnapsackFitnessEvaluator(maxWeight, products.AsReadOnly()); var crossover = new BinarySinglePointCrossover(); // Preserve the best chromosome for the next generation var preservationSelection = new BestFitnessSelection <BitArray>(1); // Use the top 30 chromosomes to create children for the next generation var parentSelection = new BestFitnessSelection <BitArray>(30); // Each gene has a 1% chance to mutate. Each mutation is a bit flip var mutation = new BinaryBitFlipMutation(0.01); var geneticAlgorithm = new GeneticAlgorithm <BitArray>(populationFactory, termination, fitnessEvaluator, preservationSelection, parentSelection, crossover, mutation, 200); // Let the "breeding" begin var geneticAlgorithmResult = geneticAlgorithm.Start(); var bestChromosome = geneticAlgorithmResult.Selection.First(); Console.WriteLine(); Console.WriteLine($"Max score using genetic algorithm: {bestChromosome.FitnessScore}"); Console.WriteLine($"Max score using dynamic programming: {CalculateMaximumValue(products.ToArray(), maxWeight)}"); }
private String Lab6BinaryIslandModel(IEvaluation <bool> evaluation, ASelection selection, ACrossover crossover, double pMut, int popSize, int islandCount, PopulationChoosingMethod method, int maxNCD, int?seed) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 100); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(pMut, evaluation, seed); APopulationCrossover <bool> populationCrossover = new ParametrizedPopulationCrossover <bool>(crossover, .5, method); IslandModel im = new IslandModel(evaluation, stopCondition, generator, selection, crossover, mutation, popSize, islandCount, maxNCD, populationCrossover); GAStallDetection <bool> ga = new GAStallDetection <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 20, 5); ga.Run(); ReportOptimizationResult(ga.Result); return(FormatSave(ga)); }
private List <String> AG(int seed, IEvaluation <bool>[] problems, ACrossover crossover) { List <String> results = new List <String>(); foreach (var evaluation in problems) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 1000); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); TournamentSelection selection = new TournamentSelection(2, seed); GeneticAlgorithm <bool> ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, 50); ga.Run(); results.Add(FormatSave(ga)); } return(results); }
private List <String> AGDsmWithCrossover(int seed, IEvaluation <bool>[] problems) { List <String> results = new List <String>(); foreach (var evaluation in problems) { IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, 1000); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); TournamentSelection selection = new TournamentSelection(2, seed); GAWithDSM dsmGAWithCross = new GAWithDSM(evaluation, stopCondition, generator, selection, mutation, 50, 0.5, 0.5); dsmGAWithCross.Run(); results.Add(FormatSave(dsmGAWithCross)); } return(results); }
private static Experiment <bool> PrepareExperiment7(int evaluationType, int algorithm, int variables, int selectionMethod, int crossoverMethod, double crossoverProb, double mutationProb, int populationSize, int?seed = null) { IEvaluation <bool> evaluation; Dictionary <string, string> info = new Dictionary <string, string>(); switch (evaluationType) { case 0: evaluation = new CBinaryStandardDeceptiveConcatenationEvaluation(3, variables); info["problem"] = "order3standard"; break; case 1: evaluation = new CBinaryBimodalDeceptiveConcatenationEvaluation(10, variables); info["problem"] = "order10bimodal"; break; case 2: evaluation = new ShuffledStandardDeceptiveConcatenationEvaluation(3, variables); info["problem"] = "order3shuffled"; break; case 3: evaluation = new ShuffledBimodalDeceptiveConcatenationEvaluation(10, variables); info["problem"] = "order10shuffled"; break; default: throw new ArgumentOutOfRangeException(); } info["variables"] = variables.ToString(); RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(evaluation.dMaxValue, 30); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); ASelection selection; switch (selectionMethod) { case 0: selection = new RouletteWheelSelection(seed); info["selection_method"] = "roulette"; break; case 1: selection = new TournamentSelection(2, seed); info["selection_method"] = "tournament"; break; default: throw new ArgumentOutOfRangeException(); } ACrossover crossover; info["crossover_prob"] = crossoverProb.ToString(); switch (crossoverMethod) { case 0: crossover = new OnePointCrossover(crossoverProb, seed); info["crossover_method"] = "OnePoint"; break; case 1: crossover = new UniformCrossover(crossoverProb, seed); info["crossover_method"] = "uniform"; break; case 2: crossover = new DSMCrossover(crossoverProb, seed); info["crossover_method"] = "withDSM"; break; default: throw new ArgumentOutOfRangeException(); } mutationProb = mutationProb / evaluation.iSize; info["mutation_prob"] = mutationProb.ToString(); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(mutationProb, evaluation, seed); info["population"] = populationSize.ToString(); GeneticAlgorithm <bool> ga; switch (algorithm) { case 0: ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "GA"; break; case 1: ga = new GAwithDSM(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, 10); info["algorithm"] = "GAwithDSM"; break; default: throw new ArgumentOutOfRangeException(); } Experiment <bool> experiment = new Experiment <bool>(ga, info, ExperimentFinished); return(experiment); }
private static Experiment <bool, Tuple <double, double>, BiObjective.OptimizationResult <bool> > PrepareExperiment9(int method, int evaluationType, int selectionMethod, double mutationProb, int populationSize, int?seed = null) { IEvaluation <bool, Tuple <double, double> > evaluation; Dictionary <string, string> info = new Dictionary <string, string>(); DefaultDominationComparer dominationComparer = new DefaultDominationComparer(); switch (evaluationType) { case 0: evaluation = new CBinaryZeroMaxOneMaxEvaluation(100); info["problem"] = "ZeroMaxOneMax"; break; case 1: evaluation = new CBinaryTrapInvTrapEvaluation(5, 100); info["problem"] = "Trap5InvTrap5"; break; case 2: evaluation = new CBinaryLOTZEvaluation(10); info["problem"] = "LOTZ"; break; case 3: evaluation = new CBinaryMOMaxCutEvaluation(EBinaryBiObjectiveMaxCutInstance.maxcut_instance_100); info["problem"] = "MaxCut"; break; case 4: evaluation = new CBinaryMOKnapsackEvaluation(EBinaryBiObjectiveKnapsackInstance.knapsack_100); info["problem"] = "MOKnapsack"; break; default: throw new ArgumentOutOfRangeException(); } info["variables"] = evaluation.iSize.ToString(); RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(30); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); OnePointCrossover crossover = new OnePointCrossover(0.5, seed); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(1.0 / evaluation.iSize, evaluation, seed); ASelection <Tuple <double, double> > selection; switch (selectionMethod) { case 0: selection = new SampleBiObjectiveSelection(dominationComparer, seed); info["selection_method"] = "Sample"; break; case 1: selection = new NSGA2Selection(10, evaluation.tMaxValue, dominationComparer, true, seed); info["selection_method"] = "NSGA2"; break; default: throw new ArgumentOutOfRangeException(); } mutationProb = mutationProb / evaluation.iSize; info["mutation_prob"] = mutationProb.ToString(); info["population"] = populationSize.ToString(); BiObjective.GeneticAlgorithm <bool> ga; switch (method) { case 0: ga = new BiObjective.GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, seed); info["method"] = "GA"; break; case 1: ga = new BiObjective.ClusteringGeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, populationSize / 10, seed); info["method"] = "ClusteringGA"; break; case 2: ga = new BiObjective.ClusteringGeneticAlgorithm2 <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, populationSize / 10, seed); info["method"] = "ClusteringGA2"; break; default: throw new ArgumentOutOfRangeException(); } Experiment <bool, Tuple <double, double>, BiObjective.OptimizationResult <bool> > experiment = new Experiment <bool, Tuple <double, double>, BiObjective.OptimizationResult <bool> >(ga, info, ExperimentFinished); return(experiment); }
private static Experiment <bool> PrepareExperiment6(int evaluationType, int algorithm, int selectionMethod, int crossoverMethod, double crossoverProb, double mutationProb, int populationSize, int?seed = null) { IEvaluation <bool> evaluation; Dictionary <string, string> info = new Dictionary <string, string>(); switch (evaluationType) { case 0: evaluation = new CBinaryMax3SatEvaluation(100); info["problem"] = "Max3Sat"; info["variables"] = "100"; break; case 1: evaluation = new CBinaryIsingSpinGlassEvaluation(100); info["problem"] = "ISG"; info["variables"] = "100"; break; case 2: evaluation = new CBinaryNKLandscapesEvaluation(100); info["problem"] = "NKLandscapes"; info["variables"] = "100"; break; case 3: evaluation = new CBinaryStandardDeceptiveConcatenationEvaluation(3, 10); info["problem"] = "Deceptive"; info["variables"] = "10"; break; case 4: evaluation = new CBinaryStandardDeceptiveConcatenationEvaluation(3, 50); info["problem"] = "Deceptive"; info["variables"] = "50"; break; case 5: evaluation = new CBinaryStandardDeceptiveConcatenationEvaluation(3, 100); info["problem"] = "Deceptive"; info["variables"] = "100"; break; default: throw new ArgumentOutOfRangeException(); } RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(evaluation.dMaxValue, 30); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); ASelection selection; switch (selectionMethod) { case 0: selection = new RouletteWheelSelection(seed); info["selection_method"] = "roulette"; break; case 1: selection = new TournamentSelection(2, seed); info["selection_method"] = "tournament"; break; default: throw new ArgumentOutOfRangeException(); } ACrossover crossover; info["crossover_prob"] = crossoverProb.ToString(); switch (crossoverMethod) { case 0: crossover = new OnePointCrossover(crossoverProb, seed); info["crossover_method"] = "OnePoint"; break; case 1: crossover = new UniformCrossover(crossoverProb, seed); info["crossover_method"] = "uniform"; break; default: throw new ArgumentOutOfRangeException(); } mutationProb = mutationProb / evaluation.iSize; info["mutation_prob"] = mutationProb.ToString(); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(mutationProb, evaluation, seed); info["population"] = populationSize.ToString(); GeneticAlgorithm <bool> ga; switch (algorithm) { case 0: ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "GA"; break; case 1: ga = new ResettingGA <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, 10, seed); info["algorithm"] = "resetting"; break; default: throw new ArgumentOutOfRangeException(); } Experiment <bool> experiment = new Experiment <bool>(ga, info, ExperimentFinished); return(experiment); }
private static Experiment <bool> PrepareExperiment5(int evaluationType, int instance, int algorithm, int selectionMethod, int crossoverMethod, double crossoverProb, double mutationProb, int populationSize, int?seed = null) { CBinaryKnapsackEvaluation evaluation; Dictionary <string, string> info = new Dictionary <string, string>(); List <string> instances = new List <string> { "f1_l_d_kp_10_269", "f2_l_d_kp_20_878", "f3_l_d_kp_4_20", "f4_l_d_kp_4_11", "f5_l_d_kp_15_375", "f6_l_d_kp_10_60", "f7_l_d_kp_7_50", "f8_l_d_kp_23_10000", "f9_l_d_kp_5_80", "f10_l_d_kp_20_879", "knapPI_1_100_1000_1", "knapPI_1_200_1000_1", "knapPI_1_500_1000_1", "knapPI_1_1000_1000_1", "knapPI_1_2000_1000_1", "knapPI_1_5000_1000_1", "knapPI_1_10000_1000_1", "knapPI_2_100_1000_1", "knapPI_2_200_1000_1", "knapPI_2_500_1000_1", "knapPI_2_1000_1000_1", "knapPI_2_2000_1000_1", "knapPI_2_5000_1000_1", "knapPI_2_10000_1000_1", "knapPI_3_100_1000_1", "knapPI_3_200_1000_1", "knapPI_3_500_1000_1", "knapPI_3_1000_1000_1", "knapPI_3_2000_1000_1", "knapPI_3_5000_1000_1", "knapPI_3_10000_1000_1" }; info["instance"] = instances[instance]; switch (evaluationType) { case 0: evaluation = new CBinaryKnapsackEvaluation((EBinaryKnapsackInstance)instance); info["evaluation"] = "base"; break; case 1: evaluation = new CheckingBinaryKnapsackEvaluation((EBinaryKnapsackInstance)instance); info["evaluation"] = "checking"; break; case 2: evaluation = new NegativeBinaryKnapsackEvaluation((EBinaryKnapsackInstance)instance); info["evaluation"] = "negative"; break; case 3: evaluation = new PenalizingBinaryKnapsackEvaluation((EBinaryKnapsackInstance)instance); info["evaluation"] = "penalizing"; break; default: throw new ArgumentOutOfRangeException(); } RunningTimeStopCondition stopCondition = new RunningTimeStopCondition(evaluation.dMaxValue, 30); BinaryRandomGenerator generator = new BinaryRandomGenerator(evaluation.pcConstraint, seed); ASelection selection; switch (selectionMethod) { case 0: selection = new RouletteWheelSelection(seed); info["selection_method"] = "roulette"; break; case 1: selection = new TournamentSelection(2, seed); info["selection_method"] = "tournament"; break; default: throw new ArgumentOutOfRangeException(); } ACrossover crossover; info["crossover_prob"] = crossoverProb.ToString(); switch (crossoverMethod) { case 0: crossover = new OnePointCrossover(crossoverProb, seed); info["crossover_method"] = "OnePoint"; break; case 1: crossover = new UniformCrossover(crossoverProb, seed); info["crossover_method"] = "uniform"; break; default: throw new ArgumentOutOfRangeException(); } mutationProb = mutationProb / evaluation.iSize; info["mutation_prob"] = mutationProb.ToString(); BinaryBitFlipMutation mutation = new BinaryBitFlipMutation(mutationProb, evaluation, seed); info["population"] = populationSize.ToString(); GeneticAlgorithm <bool> ga; switch (algorithm) { case 0: ga = new GeneticAlgorithm <bool>(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "GA"; break; case 1: ga = new KnapsackGeneticAlgorithm(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "Checking"; break; case 2: ga = new LamarckGeneticAlgorithm(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "Lamarck"; break; case 3: ga = new BaldwinGeneticAlgorithm(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize); info["algorithm"] = "Baldwin"; break; default: throw new ArgumentOutOfRangeException(); } Experiment <bool> experiment = new Experiment <bool>(ga, info, ExperimentFinished); return(experiment); }