private AssignmentTwoResultList <GraphGenome> GeneticLocalSearch(INeighborhood <GraphGenome> neighborhood)
        {
            AssignmentTwoResultList <GraphGenome> results = new AssignmentTwoResultList <GraphGenome>("$GLS_{" + neighborhood.Name + "}$");

            GraphGenome graph = new GraphGenome(500);

            graph.CreateGraph("Graph500.txt");

            GraphGenome optimum = null;

            for (int i = 0; i < ExperimentAmount; ++i)
            {
                AssignmentTwoResults <GraphGenome> res = new AssignmentTwoResults <GraphGenome>();
                int population_size = 50;
                int data_size       = 500;

                LocalSearch <GraphGenome> local_search =
                    new LocalSearch <GraphGenome>(data_size,
                                                  neighborhood,
                                                  new GraphComparer <GraphGenome>(), main_random_source);

                LocalSearchProcreator <GraphGenome> lsp = new LocalSearchProcreator <GraphGenome>(
                    new UniformSymmetricCrossover <GraphGenome>(main_random_source),
                    local_search,
                    main_random_source,
                    res);

                GeneticAlgorithm <GraphGenome> ga = new GeneticAlgorithm <GraphGenome>(
                    data_size,
                    lsp,
                    new DefaultSelector <GraphGenome>(
                        new GraphComparer <GraphGenome>()),
                    new LocalSearchPopulationGenerator <GraphGenome>(main_random_source, local_search),
                    new Goal(100, 0),
                    main_random_source,
                    "GLS");

                InnerResult ir = ga.start(population_size, OptimaAmount / (population_size / 2));
                // Eventueel nog een keer uitvoeren om tot 2500 optima te komen.
                while (res.Count < OptimaAmount)
                {
                    ir = ga.start(population_size, OptimaAmount / (population_size / 2));
                }

                // Als we er teveel hebben gekregen door de GLS run meerdere keren uit te voeren,
                // pak enkel hoeveel we nodig hebben.
                res = res.TakeFirstN(OptimaAmount);
                results.Add(res);

                if (optimum == null || res.BestResult.Optimum.Fitness < optimum.Fitness)
                {
                    optimum = new GraphGenome(res.BestResult.Optimum.Data, res.BestResult.Optimum.Fitness);
                }
            }



            // We maken iedere keer population_size / 2 optima.
            // We willen OptimaAmount optima. Dus we gaan OptimaAmount / (population_size / 2) generaties uitvoeren.

            //IteratedLocalSearch();

            optimum.ToImage(String.Format("results/GLS[{0}]-{1}.bmp", neighborhood.Name, optimum.Fitness), 3000, 3000);

            return(results);
        }
        private AssignmentTwoResultList <GraphGenome> IteratedLocalSearch(INeighborhood <GraphGenome> neighborhood, bool silent = false)
        {
            LocalSearch <GraphGenome> local_search =
                new LocalSearch <GraphGenome>(500,
                                              neighborhood,
                                              new GraphComparer <GraphGenome>(), main_random_source);
            IMutation <GraphGenome> pertubation = new ILSPertubation <GraphGenome>(main_random_source);

            GraphGenome graph = new GraphGenome(500);

            graph.CreateGraph("Graph500.txt");

            GraphGenome optimum = null;

            List <long> elapsedMilisecondsList = new List <long>();

            AssignmentTwoResultList <GraphGenome> results = new AssignmentTwoResultList <GraphGenome>("$ILS_{" + neighborhood.Name + "}$");

            for (int i = 0; i < ExperimentAmount; ++i)
            {
                AssignmentTwoResults <GraphGenome> res = new AssignmentTwoResults <GraphGenome>();
                for (int j = 0; j < OptimaAmount; j++)
                {
                    if (optimum == null)
                    {
                        graph = new GraphGenome(500);
                        graph.Generate(ref main_random_source);
                    }
                    else
                    {
                        graph = pertubation.Mutate(optimum);
                    }

                    Stopwatch   sw            = Stopwatch.StartNew();
                    GraphGenome inner_optimum = local_search.Search(graph);
                    sw.Stop();
                    elapsedMilisecondsList.Add(sw.ElapsedMilliseconds);

                    res.Add(inner_optimum, sw.ElapsedTicks);

                    if (!silent)
                    {
                        Console.WriteLine("Found {0} in {1} ticks or {2}ms. ({3}/{4})", inner_optimum.Fitness, sw.ElapsedTicks,
                                          sw.ElapsedMilliseconds, j, OptimaAmount);
                    }

                    if (optimum == null || optimum.Fitness >= inner_optimum.Fitness)
                    {
                        optimum = inner_optimum;
                    }

                    optimum.FunctionEvaluations = 0;
                }
                results.Add(res);
            }
            //Console.WriteLine("Best solution found: {0} in an average of {1} ms", optimum.Fitness, cpu_ticks.Average());
            Console.WriteLine("Best solution found: {0} in an average of {1} ms", optimum.Fitness, elapsedMilisecondsList.Sum() / OptimaAmount);
            //Console.WriteLine("Total time: {0} sec", sw.ElapsedMilliseconds / 1000f);

            optimum.ToImage(String.Format("results/ILS[{0}]-{1}.bmp", neighborhood.Name, optimum.Fitness), 3000, 3000);

            //Console.ReadLine();
            return(results);
        }