Beispiel #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);
        }
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
        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);
        }