Exemple #1
0
        public static void createNewSolver(int mutationIndex, int crossoverIndex, int selectorIndex, int populationSize, float mutationChance, int timeMS, int selectorSize, float crossoverChance)
        {
            MutationType    mutation  = null;
            CrossoverType   crossover = null;
            SelectionType   selection = null;
            AdjacencyMatrix matrix    = new AdjacencyMatrix(tspXmlFile);

            switch (mutationIndex)
            {
            case 0:
            {
                mutation = new InversionMutation(mutationChance);
                break;
            }

            case 1:
            {
                mutation = new TranspositionMutation(mutationChance);
                break;
            }
            }

            switch (crossoverIndex)
            {
            case 0:
            {
                crossover = new PMXCrossover(crossoverChance);
                break;
            }

            case 1:
            {
                crossover = new OXCrossover(crossoverChance);
                break;
            }
            }

            switch (selectorIndex)
            {
            case 0:
            {
                selection = new TournamentSelection(selectorSize);
                break;
            }

            case 1:
            {
                selection = new RouletteSelection(selectorSize);
                break;
            }
            }
            GeneticSolver solver = null;//add parameters TO DO

            if (mutation != null && selection != null && crossover != null)
            {
                addNewSolver(new GeneticSolver(matrix, mutation, crossover, selection, populationSize, timeMS));
            }
        }
        public GeneticSolver(AdjacencyMatrix matrix, MutationType mutation, CrossoverType crossover, SelectionType selectionType, int populationSize, int MaxTime)
        {
            this.crossover    = crossover;
            this.matrix       = matrix;
            this.mutation     = mutation;
            maxPopulationSize = populationSize;
            selector          = selectionType;
            rnd               = new Random();
            this.MaxTime      = MaxTime;
            results           = new List <Candidate>();
            time              = new Stopwatch();
            bestPerTwoMinutes = new List <Candidate>();
            result            = new Result(this);

            minutes = 0;
        }