Ejemplo n.º 1
0
        public static LinearFaultGene CreateRandom(Grid2DDomain domain)
        {
            double x          = Rng.ContinuousUniform(domain.Min.X, domain.Max.X);
            double y          = Rng.ContinuousUniform(domain.Min.Y, domain.Max.Y);
            double strike     = Rng.ContinuousUniform(0.0, 360.0);
            double faultThrow = Rng.ContinuousUniform(0.0, 50.0);

            return(Create(domain, x, y, strike, faultThrow));
        }
        public double NextDouble()
        {
            // Choose a uniform random offset along the rouletteWheel
            double offset = Rng.ContinuousUniformZeroToN(rouletteWheel[rouletteWheel.Count - 1]);
            // Determine which class-interval we are in
            int index; // Contains the index into the rouletteWheel of the containing class

            Algorithms.BinarySearch <double>(rouletteWheel, offset, out index);
            // Choose a uniformally distributed value from within the class
            double classLower = histogram.LowerBoundary(index);
            double classUpper = histogram.UpperBoundary(index);

            return(Rng.ContinuousUniform(classLower, classUpper));
        }
Ejemplo n.º 3
0
        //public static SinuousFaultGene CreateRandom(Grid2DDomain domain)
        //{
        //    double border   = Border(domain);
        //    double x0   = Rng.ContinuousUniform(domain.Min.X - border, domain.Max.X + border);
        //    double y0   = Rng.ContinuousUniform(domain.Min.Y - border, domain.Max.Y + border);
        //    double phi0 = Rng.ContinuousUniform(-tipTangentAngle, +tipTangentAngle);
        //    double x1   = Rng.ContinuousUniform(domain.Min.X - border, domain.Max.X + border);
        //    double y1   = Rng.ContinuousUniform(domain.Min.Y - border, domain.Max.Y + border);
        //    double phi1 = Rng.ContinuousUniform(-tipTangentAngle, +tipTangentAngle);
        //    double detachDepth = Rng.ContinuousUniform(MinDetachDepth(domain), MaxDetachDepth(domain));
        //    double maxHeave    = Rng.ContinuousUniform(MinMaxHeave(domain), MaxMaxHeave(domain), false);
        //    double dip         = Rng.ContinuousUniform(minFaultDip, maxFaultDip);
        //    return Create(domain, x0, y0, phi0, x1, y1, phi1, maxHeave, detachDepth, dip);
        //}

        public static SinuousFaultGene CreateRandom(Grid2DDomain domain)
        {
            // Select a point to be on the centre of a straight line
            // joining the fault tips
            double  border = Border(domain);
            Point2D centre = new Point2D(Rng.ContinuousUniform(domain.Min.X - border, domain.Max.X + border),
                                         Rng.ContinuousUniform(domain.Min.Y - border, domain.Max.Y + border));

            // Select a fault orientation - select a dip azimuth from the
            // distribution, and convert it into a fault strike.
            double dipAzimuth = domain.RandomHistogramDipAzimuth();
            // Fault strike should be 90° anti-clockwise of surface dip
            double faultStrike = dipAzimuth - Math.PI / 2.0;

            // Select a fault length from the domain length scale distribution
            double faultLength = Rng.ContinuousUniformZeroToN((domain.Max - domain.Min).Magnitude);

            Vector2D halfCentreLine = new Vector2D(Math.Cos(faultStrike) * faultLength / 2.0,
                                                   Math.Sin(faultStrike) * faultLength / 2.0);

            Point2D p0 = centre - halfCentreLine;
            Point2D p1 = centre + halfCentreLine;

            double phi0 = Rng.ContinuousUniform(-tipTangentAngle, +tipTangentAngle);
            double phi1 = Rng.ContinuousUniform(-tipTangentAngle, +tipTangentAngle);

            double detachDepth = Rng.ContinuousUniform(MinDetachDepth(domain), MaxDetachDepth(domain));

            double maxFaultHeave   = faultLength / minFaultDisplacementLengthRatio;
            double lowerFaultHeave = MinMaxHeave(domain);
            double upperFaultHeave = Math.Max(Math.Min(maxFaultHeave, detachDepth / 2.0) / 10.0, lowerFaultHeave);
            double maxHeave        = Rng.ContinuousUniform(lowerFaultHeave, upperFaultHeave, false);
            double dip             = Rng.ContinuousUniform(minFaultDip, maxFaultDip);

            return(Create(domain, p0.X, p0.Y, phi0, p1.X, p1.Y, phi1, maxHeave, detachDepth, dip));
        }
Ejemplo n.º 4
0
        private void ParetoStochasticUniversal(int newPopulationSize)
        {
            List <Individual> newMembers = new List <Individual>(newPopulationSize);

            // breedRanking stores a cumulative list of member.ParetoRank
            List <int> breedRanking = new List <int>(members.Count);

            Debug.Assert(members[0].ParetoRank != 0);
            breedRanking.Add(members[0].ParetoRank);
            for (int i = 1; i < members.Count; ++i)
            {
                Debug.Assert(members[i].ParetoRank != 0);
                breedRanking.Add(breedRanking[i - 1] + members[i].ParetoRank);
            }

            int breedingSubPopulationSize = (int)Math.Floor(newPopulationSize * breedingProportion);

            //Console.WriteLine("breedingSubPopulationSize = {0}", breedingSubPopulationSize);
            if (breedingSubPopulationSize > 0)
            {
                // Determine how far we jump down the breedRanking each time we select
                double selectorIncrement = (double)breedRanking[breedRanking.Count - 1] / (double)breedingSubPopulationSize;
                // Choose a random phase offset
                double            phase    = Rng.ContinuousUniform(double.Epsilon, selectorIncrement, false);
                double            selector = phase;
                List <Individual> breedingSubPopulation = new List <Individual>();
                int i = 0;
                while (i < members.Count)
                {
                    if (selector < breedRanking[i])
                    {
                        breedingSubPopulation.Add(members[i]);
                        selector += selectorIncrement;
                    }
                    else
                    {
                        ++i;
                    }
                }
                Debug.Assert(breedingSubPopulation.Count == breedingSubPopulationSize);

                Algorithms.RandomShuffleInPlace(breedingSubPopulation);
                int p_end = (breedingSubPopulation.Count % 2) == 1 ? ((breedingSubPopulation.Count / 2) + 1) : (breedingSubPopulation.Count / 2);
                for (int p = 0, q = breedingSubPopulation.Count - 1;
                     p < p_end; ++p, --q)
                {
                    Pair <Individual, Individual> children = Individual.Crossover(breedingSubPopulation[p], breedingSubPopulation[q]);
                    newMembers.Add(children.First);
                    newMembers.Add(children.Second);
                }
            }

            //Console.WriteLine("newMembers.Count = {0}", newMembers.Count);

            // Make up numbers in the newMembers generation by taking the best
            // remaining individuals from the previous generation
            IEnumerator <Individual> r = members.GetEnumerator();

            while (newMembers.Count < newPopulationSize)
            {
                r.MoveNext();
                newMembers.Add(r.Current);
            }

            members = newMembers;

            //foreach (Individual individual in members)
            //{
            //    Console.Write(individual.Id);
            //    Console.Write(' ');
            //}
            //Console.WriteLine();
        }