コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }