Esempio n. 1
0
        public Route[] Select(IEnumerable <Route> population, int selectionSize, IStepFunction step)
        {
            Route[] selection = new Route[selectionSize];


            for (int i = 0; i < selectionSize; i++) //For each Round
            {
                List <Route> workingPopulation = new List <Route>(population);
                Route?       bestCandidate     = null;

                for (int j = 0; j < k; j++)
                {
                    Route candidate = workingPopulation[random.Next(workingPopulation.Count)];
                    workingPopulation.Remove(candidate);

                    bestCandidate = bestCandidate == null ? candidate : step.CostP(new Route[] { candidate, bestCandidate });
                }



                if (bestCandidate == null)
                {
                    throw new Exception();
                }

                selection[i] = bestCandidate;
            }


            return(selection);
        }
 public LocalSearch(IInitalise initalise, INeighbourhood neighbourhood, IStepFunction step, TerminateStrategy terminate, string name = "Local Search")
 {
     this.initalisationStrategy = initalise;
     this.neighbourhood         = neighbourhood;
     this.step = step;
     this.terminateStrategy = terminate;
     this.name = name;
 }
Esempio n. 3
0
 public Evolution(IInitalise initalise, ISelectionStrategy selectionStrategy, ICrossover crossoverStratergy, ISwap swap, TerminateStrategy terminate, IStepFunction stepFunction, uint populationSize, float eliteism, float mutationRate, string name = "Evolution Search")
 {
     this.InitalisationStrategy = initalise;
     this.selectionStrategy     = selectionStrategy;
     this.crossoverStratergy    = crossoverStratergy;
     this.step = stepFunction;
     this.swap = swap;
     this.terminateStrategy = terminate;
     this.name         = name;
     this.eliteism     = eliteism;
     this.mutationRate = mutationRate;
     population        = new Route[populationSize];
 }
 internal ExhaustiveSearch(IStepFunction step)
 {
     this.step = step;
 }