Inheritance: IDistParameters
コード例 #1
0
ファイル: Agent.cs プロジェクト: VSchuster/Extension-Base-BDA
        //---------------------------------------------------------------------
        /// <summary>
        /// Objects and Lists must be initialized.
        /// </summary>
        public Agent(int sppCount, int ecoCount, int distCount)
        {
            SppParameters      = new ISppParameters[sppCount];
            EcoParameters      = new IEcoParameters[ecoCount];
            DistParameters     = new IDistParameters[distCount];
            negSppList         = new List <ISpecies>();
            dispersalNeighbors = new List <RelativeLocation>();
            resourceNeighbors  = new List <RelativeLocationWeighted>();
            severity           = PlugIn.ModelCore.Landscape.NewSiteVar <byte>();
            outbreakZone       = PlugIn.ModelCore.Landscape.NewSiteVar <Zone>();

            for (int i = 0; i < sppCount; i++)
            {
                SppParameters[i] = new SppParameters();
            }
            for (int i = 0; i < ecoCount; i++)
            {
                EcoParameters[i] = new EcoParameters();
            }
            for (int i = 0; i < distCount; i++)
            {
                DistParameters[i] = new DistParameters();
            }
        }
コード例 #2
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Objects and Lists must be initialized.
        /// </summary>
        public Agent(int sppCount, int ecoCount, int distCount)
        {
            SppParameters = new ISppParameters[sppCount];
            EcoParameters = new IEcoParameters[ecoCount];
            DistParameters = new IDistParameters[distCount];
            negSppList = new List<ISpecies>();
            dispersalNeighbors = new List<RelativeLocation>();
            resourceNeighbors = new List<RelativeLocationWeighted>();
            severity       = PlugIn.ModelCore.Landscape.NewSiteVar<byte>();
            outbreakZone   = PlugIn.ModelCore.Landscape.NewSiteVar<Zone>();

            for (int i = 0; i < sppCount; i++)
                SppParameters[i] = new SppParameters();
            for (int i = 0; i < ecoCount; i++)
                EcoParameters[i] = new EcoParameters();
            for (int i = 0; i < distCount; i++)
                DistParameters[i] = new DistParameters();
        }
コード例 #3
0
        //---------------------------------------------------------------------

        protected override IAgent Parse()
        {
            //PlugIn.ModelCore.UI.WriteLine("Parsing 1; sppCnt={0}", Model.Species.Count);
            Agent agentParameters = new Agent(PlugIn.ModelCore.Species.Count, PlugIn.ModelCore.Ecoregions.Count, (int)DisturbanceType.Null);   //The last disturb Type is Null

            InputVar <string> agentName = new InputVar <string>("BDAAgentName");

            ReadVar(agentName);
            agentParameters.AgentName = agentName.Value;

            InputVar <int> bdpc = new InputVar <int>("BDPCalibrator");

            ReadVar(bdpc);
            agentParameters.BDPCalibrator = bdpc.Value;

            InputVar <SRDmode> srd = new InputVar <SRDmode>("SRDMode");

            ReadVar(srd);
            agentParameters.SRDmode = srd.Value;

            InputVar <int> tSLE = new InputVar <int>("TimeSinceLastEpidemic");

            ReadVar(tSLE);
            agentParameters.TimeSinceLastEpidemic = tSLE.Value;

            InputVar <TemporalType> tt = new InputVar <TemporalType>("TemporalType");

            ReadVar(tt);
            agentParameters.TempType = tt.Value;

            InputVar <RandomFunction> rf = new InputVar <RandomFunction>("RandomFunction");

            ReadVar(rf);
            agentParameters.RandFunc = rf.Value;

            InputVar <double> rp1 = new InputVar <double>("RandomParameter1");

            ReadVar(rp1);
            agentParameters.RandomParameter1 = rp1.Value;

            InputVar <double> rp2 = new InputVar <double>("RandomParameter2");

            ReadVar(rp2);
            agentParameters.RandomParameter2 = rp2.Value;

            InputVar <int> minROS = new InputVar <int>("MinROS");

            ReadVar(minROS);
            agentParameters.MinROS = minROS.Value;

            InputVar <int> maxROS = new InputVar <int>("MaxROS");

            ReadVar(maxROS);
            agentParameters.MaxROS = maxROS.Value;

            InputVar <bool> d = new InputVar <bool>("Dispersal");

            ReadVar(d);
            agentParameters.Dispersal = d.Value;

            InputVar <int> dr = new InputVar <int>("DispersalRate");

            ReadVar(dr);
            agentParameters.DispersalRate = dr.Value;

            InputVar <double> et = new InputVar <double>("EpidemicThresh");

            ReadVar(et);
            agentParameters.EpidemicThresh = et.Value;

            InputVar <int> ien = new InputVar <int>("InitialEpicenterNum");

            ReadVar(ien);
            agentParameters.EpicenterNum = ien.Value;

            InputVar <double> oec = new InputVar <double>("OutbreakEpicenterCoeff");

            ReadVar(oec);
            agentParameters.OutbreakEpicenterCoeff = oec.Value;

            InputVar <bool> se = new InputVar <bool>("SeedEpicenter");

            ReadVar(se);
            agentParameters.SeedEpicenter = se.Value;

            InputVar <double> sec = new InputVar <double>("SeedEpicenterCoeff");

            ReadVar(sec);
            agentParameters.SeedEpicenterCoeff = sec.Value;

            InputVar <DispersalTemplate> dispt = new InputVar <DispersalTemplate>("DispersalTemplate");

            ReadVar(dispt);
            agentParameters.DispersalTemp = dispt.Value;

            InputVar <bool> nf = new InputVar <bool>("NeighborFlag");

            ReadVar(nf);
            agentParameters.NeighborFlag = nf.Value;

            InputVar <NeighborSpeed> nspeed = new InputVar <NeighborSpeed>("NeighborSpeedUp");

            ReadVar(nspeed);
            agentParameters.NeighborSpeedUp = nspeed.Value;

            InputVar <int> nr = new InputVar <int>("NeighborRadius");

            ReadVar(nr);
            agentParameters.NeighborRadius = nr.Value;

            InputVar <NeighborShape> ns = new InputVar <NeighborShape>("NeighborShape");

            ReadVar(ns);
            agentParameters.ShapeOfNeighbor = ns.Value;

            InputVar <double> nw = new InputVar <double>("NeighborWeight");

            ReadVar(nw);
            agentParameters.NeighborWeight = nw.Value;

            //--------- Read In Ecoreigon Table ---------------------------------------
            PlugIn.ModelCore.UI.WriteLine("Begin parsing ECOREGION table.");

            InputVar <string> ecoName     = new InputVar <string>("Ecoregion Name");
            InputVar <double> ecoModifier = new InputVar <double>("Ecoregion Modifier");

            Dictionary <string, int> lineNumbers = new Dictionary <string, int>();
            const string             DistParms   = "DisturbanceModifiers";

            while (!AtEndOfInput && CurrentName != DistParms)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(ecoName, currentLine);
                IEcoregion ecoregion = EcoregionsDataset[ecoName.Value.Actual];
                if (ecoregion == null)
                {
                    throw new InputValueException(ecoName.Value.String,
                                                  "{0} is not an ecoregion name.",
                                                  ecoName.Value.String);
                }
                int lineNumber;
                if (lineNumbers.TryGetValue(ecoregion.Name, out lineNumber))
                {
                    throw new InputValueException(ecoName.Value.String,
                                                  "The ecoregion {0} was previously used on line {1}",
                                                  ecoName.Value.String, lineNumber);
                }
                else
                {
                    lineNumbers[ecoregion.Name] = LineNumber;
                }

                IEcoParameters ecoParms = new EcoParameters();
                agentParameters.EcoParameters[ecoregion.Index] = ecoParms;

                ReadValue(ecoModifier, currentLine);
                ecoParms.EcoModifier = ecoModifier.Value;

                CheckNoDataAfter("the " + ecoModifier.Name + " column",
                                 currentLine);
                GetNextLine();
            }

            //--------- Read In Disturbance Modifier Table -------------------------------
            PlugIn.ModelCore.UI.WriteLine("Begin parsing DISTURBANCE table.");

            ReadName(DistParms);

            InputVar <DisturbanceType> distType     = new InputVar <DisturbanceType>("Disturbance Type");
            InputVar <int>             duration     = new InputVar <int>("Duration");
            InputVar <double>          distModifier = new InputVar <double>("Disturbance Modifier");

            lineNumbers = new Dictionary <string, int>();
            const string SppParms = "BDASpeciesParameters";

            while (!AtEndOfInput && CurrentName != SppParms)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(distType, currentLine);
                int dt = (int)distType.Value.Actual;

                IDistParameters distParms = new DistParameters();
                agentParameters.DistParameters[dt] = distParms;

                ReadValue(duration, currentLine);
                distParms.Duration = duration.Value;

                ReadValue(distModifier, currentLine);
                distParms.DistModifier = distModifier.Value;

                CheckNoDataAfter("the " + distModifier.Name + " column",
                                 currentLine);
                GetNextLine();
            }
            //--------- Read In Species Table ---------------------------------------
            PlugIn.ModelCore.UI.WriteLine("Begin parsing SPECIES table.");

            ReadName(SppParms);

            //const string FireCurves = "FireCurveTable";
            InputVar <string> sppName           = new InputVar <string>("Species");
            InputVar <int>    minorHostAge      = new InputVar <int>("Minor Host Age");
            InputVar <int>    secondaryHostAge  = new InputVar <int>("Second Host Age");
            InputVar <int>    primaryHostAge    = new InputVar <int>("Primary Host Age");
            InputVar <int>    resistantHostAge  = new InputVar <int>("Resistant Host Age");
            InputVar <int>    tolerantHostAge   = new InputVar <int>("Tolerant Host Age");
            InputVar <int>    vulnerableHostAge = new InputVar <int>("Vulnerable Host Age");
            InputVar <bool>   cfsConifer        = new InputVar <bool>("CFS Conifer type:  yes/no");

            const string NegSpp = "IgnoredSpecies";

            while ((!AtEndOfInput) && (CurrentName != NegSpp))
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(sppName, currentLine);
                ISpecies species = SpeciesDataset[sppName.Value.Actual];
                if (species == null)
                {
                    throw new InputValueException(sppName.Value.String,
                                                  "{0} is not a species name.",
                                                  sppName.Value.String);
                }
                int lineNumber;
                if (lineNumbers.TryGetValue(species.Name, out lineNumber))
                {
                    throw new InputValueException(sppName.Value.String,
                                                  "The species {0} was previously used on line {1}",
                                                  sppName.Value.String, lineNumber);
                }
                else
                {
                    lineNumbers[species.Name] = LineNumber;
                }

                ISppParameters sppParms = new SppParameters();
                agentParameters.SppParameters[species.Index] = sppParms;

                ReadValue(minorHostAge, currentLine);
                sppParms.MinorHostAge = minorHostAge.Value;

                ReadValue(secondaryHostAge, currentLine);
                sppParms.SecondaryHostAge = secondaryHostAge.Value;

                ReadValue(primaryHostAge, currentLine);
                sppParms.PrimaryHostAge = primaryHostAge.Value;

                ReadValue(resistantHostAge, currentLine);
                sppParms.ResistantHostAge = resistantHostAge.Value;

                ReadValue(tolerantHostAge, currentLine);
                sppParms.TolerantHostAge = tolerantHostAge.Value;

                ReadValue(vulnerableHostAge, currentLine);
                sppParms.VulnerableHostAge = vulnerableHostAge.Value;

                ReadValue(cfsConifer, currentLine);
                sppParms.CFSConifer = cfsConifer.Value;

                CheckNoDataAfter("the " + cfsConifer.Name + " column",
                                 currentLine);


                GetNextLine();
            }

            //--------- Read In Ignored Species List ---------------------------------------

            List <ISpecies> negSppList = new List <ISpecies>();

            if (!AtEndOfInput)
            {
                ReadName(NegSpp);
                InputVar <string> negSppName = new InputVar <string>("Ignored Spp Name");

                while (!AtEndOfInput)
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(negSppName, currentLine);
                    ISpecies species = SpeciesDataset[negSppName.Value.Actual];
                    if (species == null)
                    {
                        throw new InputValueException(negSppName.Value.String,
                                                      "{0} is not a species name.",
                                                      negSppName.Value.String);
                    }
                    int lineNumber;
                    if (lineNumbers.TryGetValue(species.Name, out lineNumber))
                    {
                        PlugIn.ModelCore.UI.WriteLine("WARNING: The species {0} was previously used on line {1}.  Being listed in the IgnoredSpecies list will override any settings in the Host table.", negSppName.Value.String, lineNumber);
                    }
                    else
                    {
                        lineNumbers[species.Name] = LineNumber;
                    }

                    negSppList.Add(species);

                    GetNextLine();
                }
            }
            agentParameters.NegSppList = negSppList;


            return(agentParameters); //.GetComplete();
        }