Пример #1
0
        private AbstractMutationStrategy YMutationStrategy(Grid2DDomain domain)
        {
            double range      = (domain.Max.Y - domain.Min.Y) / 2.0; // Half model width
            double resolution = 1.0;

            return(PowerLawMutationStrategy.Create(range, resolution));
        }
Пример #2
0
        private AbstractMutationStrategy MaxHeaveMutationStrategy(Grid2DDomain domain)
        {
            double range      = MaxMaxHeave(domain) / 2.0;
            double resolution = 1.0f;

            return(PowerLawMutationStrategy.Create(range, resolution));
        }
Пример #3
0
        private AbstractMutationStrategy DetachDepthMutationStrategy(Grid2DDomain domain)
        {
            double range      = MaxDetachDepth(domain) / 2.0;
            double resolution = 1.0;

            return(PowerLawMutationStrategy.Create(range, resolution));
        }
Пример #4
0
 public static SinuousFaultGene Create(Grid2DDomain domain, double x0, double y0, double phi0,
                                       double x1, double y1, double phi1,
                                       double maxHeave, double detachDepth, double dip)
 {
     Debug.Assert(dip > 0.0 && dip <= 90.0);
     return(new SinuousFaultGene(domain, x0, y0, phi0, x1, y1, phi1, maxHeave, detachDepth, dip));
 }
Пример #5
0
        private AbstractMutationStrategy RhoMutationStrategy(Grid2DDomain domain)
        {
            double r = (domain.Max - domain.Min).Magnitude / 2.0; // Half model diagonal
            double k = 9.0;                                       // ~ 1 metre

            return(PowerLawMutationStrategy.Create(r, k));
        }
Пример #6
0
 private LinearFaultGene(Grid2DDomain domain, double rho, double theta, double faultThrow) :
     base(domain, System.Enum.GetValues(typeof(DimIndex)).Length)
 {
     Dimensions[(int)DimIndex.Rho]   = new Dimension(rho, RhoMutationStrategy(domain), RhoRangeStrategy(domain));
     Dimensions[(int)DimIndex.Theta] = new Dimension(theta, ThetaMutationStrategy(domain), ThetaRangeStrategy(domain));
     Dimensions[(int)DimIndex.Throw] = new Dimension(faultThrow, ThrowMutationStrategy(domain), ThrowRangeStrategy(domain));
 }
Пример #7
0
 public Gene(Grid2DDomain domain, int size)
 {
     Debug.Assert(domain != null);
     this.domain       = domain;
     dimensions        = new Dimension[size];
     dimensionsIndexer = new DimensionIndexer(this);
 }
Пример #8
0
        private AbstractMutationStrategy DipMutationStrategy(Grid2DDomain domain)
        {
            // Should have ~1° resolution
            double range      = (maxFaultDip - minFaultDip) / 2.0;
            double resolution = 1.0;

            return(PowerLawMutationStrategy.Create(range, resolution));
        }
Пример #9
0
        public static LinearFaultGene Create(Grid2DDomain domain, double x, double y, double strike, double faultThrow)
        {
            Debug.Assert(strike >= 0.0 && strike < 360.0);

            double theta = 360.0 - strike;
            double rho   = x * Math.Cos(theta) + y * Math.Sin(theta);

            return(new LinearFaultGene(domain, rho, theta, faultThrow));
        }
Пример #10
0
        public Grid2DPhenotype(Grid2DDomain domain) :
            base(domain)
        {
            Point2D  origin   = domain.Min;
            Vector2D diagonal = domain.Max - domain.Min;
            Vector2D spacing  = new Vector2D(diagonal.DeltaX / domain.SizeI, diagonal.DeltaY / domain.SizeJ);

            this.grid = new RegularGrid2D(origin, spacing, domain.SizeI, domain.SizeJ, 0.0);
        }
Пример #11
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));
        }
Пример #12
0
 private SinuousFaultGene(Grid2DDomain domain, double x0, double y0, double phi0,
                          double x1, double y1, double phi1,
                          double maxHeave, double detachDepth, double dip) :
     base(domain, System.Enum.GetValues(typeof(DimIndex)).Length)
 {
     Dimensions[(int)DimIndex.X0]          = new Dimension(x0, XMutationStrategy(domain), XRangeStrategy(domain));
     Dimensions[(int)DimIndex.Y0]          = new Dimension(y0, YMutationStrategy(domain), YRangeStrategy(domain));
     Dimensions[(int)DimIndex.Phi0]        = new Dimension(phi0, PhiMutationStrategy(domain), PhiRangeStrategy(domain));
     Dimensions[(int)DimIndex.X1]          = new Dimension(x1, XMutationStrategy(domain), XRangeStrategy(domain));
     Dimensions[(int)DimIndex.Y1]          = new Dimension(y1, YMutationStrategy(domain), YRangeStrategy(domain));
     Dimensions[(int)DimIndex.Phi1]        = new Dimension(phi1, PhiMutationStrategy(domain), PhiRangeStrategy(domain));
     Dimensions[(int)DimIndex.DetachDepth] = new Dimension(detachDepth, DetachDepthMutationStrategy(domain), DetachDepthRangeStrategy(domain));
     Dimensions[(int)DimIndex.MaxHeave]    = new Dimension(maxHeave, MaxHeaveMutationStrategy(domain), MaxHeaveRangeStrategy(domain));
     Dimensions[(int)DimIndex.Dip]         = new Dimension(dip, DipMutationStrategy(domain), DipRangeStrategy(domain));
 }
Пример #13
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));
        }
Пример #14
0
        private AbstractRangeStrategy RhoRangeStrategy(Grid2DDomain domain)
        {
            double diagonal = (domain.Max - domain.Min).Magnitude;

            return(ClipRangeStrategy.Create(-diagonal, diagonal));
        }
Пример #15
0
 private static double MinMaxHeave(Grid2DDomain domain)
 {
     return(25.0);    // metres
 }
Пример #16
0
 private AbstractMutationStrategy ThetaMutationStrategy(Grid2DDomain domain)
 {
     // Half-circle range, with 1° resolution
     return(PowerLawMutationStrategy.Create(180.0, 7.49f));
 }
Пример #17
0
 private AbstractRangeStrategy DipRangeStrategy(Grid2DDomain domain)
 {
     return(ReflectRangeStrategy.Create(minFaultDip, maxFaultDip));
 }
Пример #18
0
 private AbstractRangeStrategy ThetaRangeStrategy(Grid2DDomain domain)
 {
     return(ModalRangeStrategy.Create(0.0, 360.0));
 }
Пример #19
0
 private AbstractRangeStrategy MaxHeaveRangeStrategy(Grid2DDomain domain)
 {
     return(ClipRangeStrategy.Create(MinMaxHeave(domain), MaxMaxHeave(domain)));
 }
Пример #20
0
 private AbstractMutationStrategy ThrowMutationStrategy(Grid2DDomain domain)
 {
     return(PowerLawMutationStrategy.Create(50.0, 9.0));
 }
Пример #21
0
 private AbstractRangeStrategy DetachDepthRangeStrategy(Grid2DDomain domain)
 {
     return(ClipRangeStrategy.Create(MinDetachDepth(domain), MaxDetachDepth(domain)));
 }
Пример #22
0
 private AbstractMutationStrategy PhiMutationStrategy(Grid2DDomain domain)
 {
     return(PowerLawMutationStrategy.Create(tipTangentAngle, 1.0));    // 1° resolution
 }
Пример #23
0
 private AbstractRangeStrategy PhiRangeStrategy(Grid2DDomain domain)
 {
     return(ModalRangeStrategy.Create(-tipTangentAngle, tipTangentAngle));
 }
Пример #24
0
        private AbstractRangeStrategy YRangeStrategy(Grid2DDomain domain)
        {
            double border = Border(domain);

            return(ClipRangeStrategy.Create(domain.Min.Y - border, domain.Max.Y + border));
        }
Пример #25
0
 private AbstractRangeStrategy ThrowRangeStrategy(Grid2DDomain domain)
 {
     return(ClipRangeStrategy.Create(0.0, 200.0));
 }
Пример #26
0
        private static double Border(Grid2DDomain domain)
        {
            double diagonal = (domain.Max - domain.Min).Magnitude;

            return(diagonal * borderProportion);
        }
Пример #27
0
 private static double MinDetachDepth(Grid2DDomain domain)
 {
     return(1000.0);    // metres - Must be greater than 0.0
 }
Пример #28
0
 private static double MaxDetachDepth(Grid2DDomain domain)
 {
     // TODO: Should have 3D bounds on domain
     return(Border(domain) / 2.0);
 }
Пример #29
0
 private static double MaxMaxHeave(Grid2DDomain domain)
 {
     return(MaxDetachDepth(domain) / 20.0);    // Reduced by factor of ten
 }
Пример #30
0
        static int Main(string[] args)
        {
            // Get a URI from the command line argument
            Uri uri;

            try
            {
                uri = new Uri(args[0]);
            }
            catch (UriFormatException)
            {
                string absPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + args[0];
                try
                {
                    uri = new Uri(absPath);
                }
                catch (UriFormatException)
                {
                    return(1);
                }
            }

            ReportLogger.Instance.Create("report.xml");
            ReportLogger.Instance.Writer.WriteStartDocument();
            ReportLogger.Instance.Writer.WriteStartElement("GeodysseyRun");

            Stopwatch overallWatch = new Stopwatch();

            overallWatch.Start();
            //Console.WriteLine("Start!");
            int initialMinimumGenomeLength = 50;
            int initialMaximumGenomeLength = 100;
            int initialPopulationSize      = 1000;
            int finalPopulationSize        = 100;
            int numberOfGenerations        = 100;

            double populationPowerBase = Math.Pow((double)finalPopulationSize / (double)initialPopulationSize, 1.0 / numberOfGenerations);

            int totalNumberOfIndividuals = 0;

            // Determine how many individuals will be produced in this run
            for (int i = 0; i < numberOfGenerations; ++i)
            {
                int inc = (int)Math.Round(initialPopulationSize * Math.Pow(populationPowerBase, i + 1));
                //Console.WriteLine(inc);
                totalNumberOfIndividuals += inc;
            }
            Console.WriteLine("Total Number of Individuals = {0}", totalNumberOfIndividuals);
            Console.WriteLine("Mean Invididuals per Generation = {0}", totalNumberOfIndividuals / numberOfGenerations);

            // Load a target grid
            //RegularGrid2D targetGrid;
            //using (StreamReader reader = File.OpenText("target.grd"))
            //{
            //    targetGrid = RegularGrid2D.Create(reader);
            //}

            GeodysseyModel model = new GeodysseyModel();

            LoaderController.Instance.Open(uri, model);
            IRegularGrid2D targetGrid = model[0]; // The first grid

            Debug.Assert(targetGrid != null);
            Grid2DDomain domain = new Grid2DDomain(targetGrid);

            Stopwatch  stopWatch  = new Stopwatch();
            Population population = new Population(domain, initialPopulationSize, initialMinimumGenomeLength, initialMaximumGenomeLength);

            for (int i = 0; i < numberOfGenerations; ++i)
            {
                stopWatch.Reset();
                stopWatch.Start();
                population.ComputeFitnesses();
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;
                ReportLogger.Instance.Writer.WriteStartElement("Generation");
                ReportLogger.Instance.Writer.WriteStartAttribute("number");
                ReportLogger.Instance.Writer.WriteValue(i + 1);
                ReportLogger.Instance.Writer.WriteEndAttribute();
                ReportLogger.Instance.Writer.WriteStartAttribute("elapsedTime");
                ReportLogger.Instance.Writer.WriteValue(ts);
                ReportLogger.Instance.Writer.WriteEndAttribute();
                RecordBest(targetGrid, population, i, domain);
                population.LogSummaryStatistics();
                ReportLogger.Instance.Writer.WriteEndElement();
                Console.WriteLine("Generation {0} of {1} with size {2} in {3}) ", i + 1, numberOfGenerations, population.Count, ts);
                int nextGenerationSize = (int)Math.Round(initialPopulationSize * Math.Pow(populationPowerBase, i + 1));
                population.Evolve(nextGenerationSize);
            }
            population.ComputeFitnesses();
            RecordBest(targetGrid, population, numberOfGenerations, domain);
            Console.WriteLine("Generation {0} of {1} with size {2}) ", numberOfGenerations, numberOfGenerations, population.Count);
            overallWatch.Stop();
            Console.WriteLine("Running time : {0}", overallWatch.Elapsed);
            ReportLogger.Instance.Writer.WriteEndElement();
            ReportLogger.Instance.Writer.WriteEndDocument();
            ReportLogger.Instance.Close();
            Console.ReadKey();
            return(0);
        }