コード例 #1
0
 public GeneticAlgorithm(int populationSize, int chromosomeLength, int numberOfGenerations, double crossoverRate, double mutationRate, EvaluationDelegate fitnessFunction, BoundPair[] genesDomain ,  int elitismFactor = 0, SelectionMode Selection = SelectionMode.RouletteWheel, bool PrintLogMode = false)
 {
     this.populationSize = populationSize;
     this.chromosomeLength = chromosomeLength;
     this.numberOfGenerations = numberOfGenerations;
     this.crossoverRate = crossoverRate;
     this.mutationRate = mutationRate;
     this.fitnessFunction = fitnessFunction;
     this.genesDomain = genesDomain;
     this.elitismFactor = elitismFactor;
     this.PrintLogMode = PrintLogMode;
 }
コード例 #2
0
        private void GenerateSequence(ref int x0, ref int a, ref int b, ref int c) // returns also the Optmal PSNR value
        {
            // Defining genes Domains
            BoundPair[] parameterDomain = new BoundPair[4];

            //Domain of x0
            parameterDomain[0] = new BoundPair(0, imageWidth * imageHeight);
            //Domain of a
            parameterDomain[1] = new BoundPair(1, imageWidth * imageHeight);
            //Domain of b
            parameterDomain[2] = new BoundPair(1, imageWidth * imageHeight);
            //Domain of c
            parameterDomain[3] = new BoundPair(1, imageWidth * imageHeight);

            GeneticAlgorithm GA = new GeneticAlgorithm(
                30,                                            // Population Size
                4,                                             // Chromosome Length
                100,                                           // Number of Generations
                0.85,                                          // Crossover Ratio
                0.25,                                          // Mutation Ratio
                new GeneticAlgorithm.EvaluationDelegate(PSNR), // Fitness Function
                parameterDomain,                               // Domain of each Parameter
                1,                                             // Elitism Factor
                GeneticAlgorithm.SelectionMode.RouletteWheel   //Selection Method
                );

            ImageHiding.GA.Organism OptimalSequence = GA.Run(encryptWorker, encryptEvent); // Run the Genetic Algorithm

            //Get the Best Result
            x0 = OptimalSequence.chromosome[0];
            a  = OptimalSequence.chromosome[1];
            b  = OptimalSequence.chromosome[2];
            c  = OptimalSequence.chromosome[3];
            double trivial = PSNR(0, 1, 1, 1);
            double opt     = PSNR(OptimalSequence.chromosome);
            int    x       = 0;
        }
コード例 #3
0
        // returns also the Optmal PSNR value
        private void GenerateSequence(ref int x0, ref int a, ref int b, ref int c)
        {
            // Defining genes Domains
            BoundPair[] parameterDomain = new BoundPair[4];

            //Domain of x0
            parameterDomain[0] = new BoundPair(0, imageWidth * imageHeight);
            //Domain of a
            parameterDomain[1] = new BoundPair(1, imageWidth * imageHeight);
            //Domain of b
            parameterDomain[2] = new BoundPair(1, imageWidth * imageHeight);
            //Domain of c
            parameterDomain[3] = new BoundPair(1, imageWidth * imageHeight);

            GeneticAlgorithm GA = new GeneticAlgorithm(
                30, // Population Size
                4,   // Chromosome Length
                100, // Number of Generations
                0.85, // Crossover Ratio
                0.25, // Mutation Ratio
                new GeneticAlgorithm.EvaluationDelegate(PSNR), // Fitness Function
                parameterDomain, // Domain of each Parameter
                1,  // Elitism Factor
                GeneticAlgorithm.SelectionMode.RouletteWheel  //Selection Method
                );

            ImageHiding.GA.Organism OptimalSequence = GA.Run(encryptWorker,encryptEvent); // Run the Genetic Algorithm

            //Get the Best Result
            x0 = OptimalSequence.chromosome[0];
            a = OptimalSequence.chromosome[1];
            b = OptimalSequence.chromosome[2];
            c = OptimalSequence.chromosome[3];
            double trivial = PSNR(0, 1, 1, 1);
            double opt = PSNR(OptimalSequence.chromosome);
            int x = 0;
        }
コード例 #4
0
        private static void ConstructBoundPairs(MyPolygon poly, List<BoundPair> boundList)
        {
            for (int l = 0; l < poly.LoopCount; ++l)
            {
                int start, current, prev;
                MyPolygon.Vertex vertex;

                start = FindLoopLocalMaximum(poly, l);

                poly.GetVertex(start, out vertex);
                current = start;

                MyPolygon.Vertex otherVertex;
                poly.GetVertex(vertex.Prev, out otherVertex);

                BoundPair bounds = new BoundPair(poly, -1, -1, start, otherVertex.Coord.Y == vertex.Coord.Y);
                bool right = true;

                int comparison, prevComparison;
                comparison = -1;

                do
                {
                    Vector3 prevCoord = vertex.Coord;
                    prev = current;
                    current = vertex.Next;

                    poly.GetVertex(current, out vertex);
                    prevComparison = comparison;
                    comparison = CompareCoords(vertex.Coord, prevCoord);
                    Debug.Assert(comparison != 0, "Duplicate vertex in input polygon!");

                    if (right)
                    {
                        if (comparison > 0)
                        {
                            bounds.Minimum = prev;
                            right = false;
                        }
                    }
                    else
                    {
                        if (comparison < 0)
                        {
                            bounds.Left = prev;
                            Debug.Assert(bounds.IsValid());
                            boundList.Add(bounds);
                            bounds = new BoundPair(poly, -1, -1, prev, prevComparison == 0);
                            right = true;
                        }
                    }
                } while (current != start);

                bounds.Left = current;
                Debug.Assert(right == false);
                Debug.Assert(bounds.IsValid());
                boundList.Add(bounds);
            }
        }