Beispiel #1
0
        private static void stats()
        {
            if (!sdpInteractive.finishedForward)
            {
                sdpInteractive.importBirthDecisionsFromFile();
                // ask for forward iteration output file(s) - NFxxxx and Rxxxx
                sdpInteractive.importPopulationFromFile();
                sdpInteractive.importPopulationGrowth();
            }

            Console.WriteLine("-- calculating stats");
            sdpInteractive.calcStats();
            Console.WriteLine("-- calculated stats");

            Console.WriteLine("-- writing stats to disk");
            sdpInteractive.outputStats();
            Console.WriteLine("-- stats written to disk");
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args">Array of four mortality parameters (n, l, m, h)</param>
        /// <param name="logToFile">If false, program only outputs to Console. If true, program outputs to file rather than Console</param>
        private static void batchMode(string[] args)
        {
            // Get mortality parameters
            MortalityParam mortMaternal, mortSiblingComp, mortSiblingHelp, mortChildInfluence, mortMotherInfluence;

            StreamWriter sw = null;

            // run backwards and forwards using passed mortality params (no user input required)
            // population name
            string population = args[0];

            //
            mortMaternal    = parseArgs(args[1]);
            mortSiblingComp = parseArgs(args[2]);
            mortSiblingHelp = parseArgs(args[3]);
            // Siler params
            double silerA1 = double.Parse(args[4]);
            double silerB1 = double.Parse(args[5]);
            double silerA2 = double.Parse(args[6]);
            double silerA3 = double.Parse(args[7]);
            double silerB3 = double.Parse(args[8]);

            string births    = "";
            string popMatrix = "";
            string rFile     = "";

            if (args.Length == 10)
            {
                births = args[9];
            }
            else if (args.Length >= 11)
            {
                births    = args[9];
                popMatrix = args[10];
                rFile     = args[11];
            }

            // Return a string of mortality parameter values (e.g. medium, low, medium, high returns "MLMH")
            string sp1 = Enum.GetName(typeof(MortalityParam), mortMaternal).Substring(0, 1);
            string sp2 = Enum.GetName(typeof(MortalityParam), mortSiblingComp).Substring(0, 1);
            string sp3 = Enum.GetName(typeof(MortalityParam), mortSiblingHelp).Substring(0, 1);
            string p   = population + "-" + sp1 + sp2 + sp3; // +sp4 + sp5;

            // set up log file
            string logFilename = "Log-" + p + ".log";

            Console.WriteLine("(Running in batch mode)");
            Console.WriteLine();

            // create and initialise model
            Console.WriteLine("-- initialising model");
            BirthIntervals sdp = new BirthIntervals();

            Console.WriteLine("-- model initialised");

            // set parameters of model
            sdp.population          = population;
            sdp.childbirthMortality = mortMaternal;
            sdp.siblingCompetition  = mortSiblingComp;
            sdp.siblingHelp         = mortSiblingHelp;

            // set Siler params
            sdp.silerA1 = silerA1;
            sdp.silerB1 = silerB1;
            sdp.silerA2 = silerA2;
            sdp.silerA3 = silerA3;
            sdp.silerB3 = silerB3;

            Console.WriteLine(PrintParams(mortMaternal, mortSiblingComp, mortSiblingHelp));

            if (args.Length < 10)
            {
                // calculate optimal birth intervals
                Console.WriteLine("-- beginning backward iteration");
                sdp.runBackward();
                Console.WriteLine("-- backward iteration finished");

                // output birth decisions and fitness here
                Console.WriteLine("-- writing birth decisions to disk");
                sdp.outputBirthDecisions();
                sdp.outputGrowthRate();
                Console.WriteLine("-- birth decisions written to disk");

                Console.WriteLine("-- beginning forward iteration");
                sdp.runForward();
                Console.WriteLine("-- forward iteration finished");

                Console.WriteLine("-- writing population data to disk");
                sdp.outputGrowthRate();
                Console.WriteLine("-- population data written to disk");
            }
            if (args.Length == 10)
            {
                Console.WriteLine("-- importing births from {0}", births);
                sdp.importBirthDecisionsFromFile(births);
                Console.WriteLine("-- birth decisions imported");

                Console.WriteLine("-- beginning forward iteration");
                sdp.runForward();
                Console.WriteLine("-- forward iteration finished");

                Console.WriteLine("-- writing population data to disk");
                sdp.outputGrowthRate();
                Console.WriteLine("-- population data written to disk");
            }
            else if (args.Length >= 11)
            {
                Console.WriteLine("-- importing births from {0}", births);
                sdp.importBirthDecisionsFromFile(births);
                Console.WriteLine("-- birth decisions imported");

                Console.WriteLine("-- importing population matrix from {0}", popMatrix);
                sdp.importPopulationFromFile(popMatrix);
                Console.WriteLine("-- population matrix imported");

                Console.WriteLine("-- importing population growth rate from {0}", rFile);
                sdp.importPopulationGrowth(rFile);
                Console.WriteLine("-- population growth rate imported");

                Console.WriteLine("-- importing population matrix from {0}", popMatrix);
                sdp.importPopulationFromFile(popMatrix);
                Console.WriteLine("-- population matrix imported");
            }

            Console.WriteLine("-- calculating stats");
            sdp.calcStats();
            Console.WriteLine("-- calculated stats");

            Console.WriteLine("-- writing stats data to disk");
            sdp.outputStats();
            Console.WriteLine("-- stats data written to disk");
        }