Ejemplo n.º 1
0
        private void upDateTemporalModifiers(HourlyModifier inHM, DailyModifier inDM)
        {
            try
            {
                //Author: Bob Cummings added the temporal values.  we were modify too much.
                mLog.Debug("inside setting the temporal adjustmenst");
                mLog.Debug("current temporal move turosity is " + mTemporalMoveTurtosity.ToString());
                mLog.Debug("gender modifier is " + this.GenderModifier.MoveTurtosity.ToString());
                mLog.Debug("current hourly modifier is " + inHM.MoveTurtosity.ToString());
                mLog.Debug("current daily modifier is " + inDM.MoveTurtosity);
                mTemporalChanceOfEating    = this.GenderModifier.CaptureFood * inHM.CaptureFood * inDM.CaptureFood;
                mTemporalRiskValue         = this.GenderModifier.PredationRisk * inHM.PredationRisk * inDM.PredationRisk;
                mTemporalMoveSpeed         = this.GenderModifier.MoveSpeed * inHM.MoveSpeed * inDM.MoveSpeed;
                mTemporalMoveTurtosity     = this.GenderModifier.MoveTurtosity * inHM.MoveTurtosity * inDM.MoveTurtosity;
                mTemporalEnergyUsed        = this.GenderModifier.EnergyUsed * inHM.EnergyUsed * inDM.EnergyUsed;
                mTemporalPerceptonDistance = this.GenderModifier.PerceptonModifier * inHM.PerceptonModifier * inDM.PerceptonModifier;
                mLog.Debug("so now the current temporal move turosity is " + mTemporalMoveTurtosity.ToString());
            }
            catch (System.Exception ex)
            {
#if (DEBUG)
                System.Windows.Forms.MessageBox.Show(ex.Message);
#endif
                eLog.Debug(ex);
            }
        }
Ejemplo n.º 2
0
        /********************************************************************************
         *  Function name   : initializeYearlySimulation
         *  Description     :
         *  Return type     : void
         * *******************************************************************************/
        private void initializeYearlySimulation()
        {
            // int numOrginalDispersers = 0;
            mLog.Debug("inside initialize yearly simulation");
            this.myHourlyModifiers.reset();
            this.currHourMod   = this.myHourlyModifiers.getNext();
            this.nextStartHour = this.myHourlyModifiers.NextStartHour;
            this.myDailyModifiers.reset();
            this.myDailyModifiers.advanceOneYear();
            this.currDailyMod = this.myDailyModifiers.getNext();
            this.nextDayStart = this.myDailyModifiers.NextStartDate;
            //09/09/2007 moved winter kill before changing maps
            //09/12/2009 changed to passing the social map so any residents that die, their area will be avaialable again.
            this.mAnimalManager.winterKillResidents(this.MapManager.SocialMap, this.currTime.Year);
            //the old mMapManager out put path include last years YEAR so we need to strip it off and replace it with this years YEAR
            this.mMapManager.OutMapPath = this.mMapManager.OutMapPath.Remove(this.mMapManager.OutMapPath.LastIndexOf("\\"), 5);
            this.mMapManager.OutMapPath = this.mMapManager.OutMapPath + "\\" + this.currTime.Year.ToString();

            //reset the maps start dates for this year
            this.MapManager.addYearToMaps();

            //now deal with the animals.
            //Author: Bob Cummings Saturday, October 13, 2007
            this.mAnimalManager.removeRemaingDispersers();

            //had an issue with breeding before switchout the maps so moved it to happen after
            this.MapManager.setUpNewYearsMaps(this.currTime, this.mAnimalManager);

            int numNewAnimals = this.mAnimalManager.breedFemales(this.currTime);

            //this.mAnimalManager.setSleepTime(this.currTime);
            this.mMapManager.makeNewDisperserAnimalMaps(numNewAnimals);
            mLog.Debug("done initializing yearly simulation");
        }
Ejemplo n.º 3
0
 public override void doTimeStep(HourlyModifier inHM, DailyModifier inDM, DateTime currTime, bool doTextOutput, ref string status)
 {
     Check.Require(mMyAttributes != null, "Resident Attributes have not been set");
     Check.Require(this.IdNum >= 0, "Resident ID was not set");
     mLog.Debug("inside time step for resident number " + this.IdNum.ToString());
     die(ref status, currTime);
 }
Ejemplo n.º 4
0
        public void doTimeStep(HourlyModifier inHM, DailyModifier inDM, DateTime currTime, bool DoTextOutPut, Map currSocialMap)
        {
            //List<Animal> liveAnimals = this.getAllLiveAnimals();
            Animal a;
            string status = "";

            try
            {
                mLog.Debug("inside animal manager do time step with modifiers");
                // foreach (Animal a in myAnimals)
                for (int i = 0; i < myAnimals.Count; i++)
                {
                    a = this.myAnimals[i];
                    mLog.Debug("");
                    mLog.Debug("animal id = " + a.IdNum.ToString());
                    mLog.Debug("animal is type " + a.GetType().ToString());


                    a.doTimeStep(inHM, inDM, currTime, DoTextOutPut, ref status);
                    //check to see if they died if they did remove them from the list
                    if (a.IsDead)
                    {
                        if (a.GetType().ToString().Equals("SEARCH.Resident", StringComparison.CurrentCultureIgnoreCase))
                        {
                            this.AdjustMapForDeadAnimal(currSocialMap, a);
                        }

                        this.changeToDeadAnimal(a);
                    }
                    //check to see if they are changing from disperser to resident

                    if (status == "resident")
                    {
                        mLog.Debug("switching " + a.IdNum.ToString() + " to a resident");
                        Resident r = new Resident();
                        r.Sex               = a.Sex;
                        r.IdNum             = a.IdNum;
                        r.TextFileWriter    = a.TextFileWriter;
                        r.HomeRangeCenter   = a.HomeRangeCenter;
                        r.HomeRangeCriteria = a.HomeRangeCriteria;
                        r.MyAttributes      = this.ResidentAttributes;
                        r.IdNumOrig         = a.IdNum.ToString();
                        this.myAnimals.RemoveAt(i);
                        this.myAnimals.Insert(i, r);
                        status = "";
                        //Sunday, November z08, 2009
                        //update reference to current social map.
                        currSocialMap = MapManager.GetUniqueInstance().SocialMap;
                    }
                }
            }


            catch (System.Exception ex)
            {
                eLog.Debug(ex);
            }
        }
Ejemplo n.º 5
0
 /********************************************************************************
  *  Function name   : initializeSimulation
  *  Description     :
  *  Return type     : void
  * *******************************************************************************/
 private void initializeSimulation()
 {
     this.currHourMod = (HourlyModifier)this.myHourlyModifiers.GetByIndex(0);
     this.myHourlyModifiers.reset();
     this.currHourMod   = this.myHourlyModifiers.getNext();
     this.nextStartHour = this.myHourlyModifiers.NextStartHour;
     this.myDailyModifiers.reset();
     this.currDailyMod = this.myDailyModifiers.getFirst();
     this.nextDayStart = this.myDailyModifiers.NextStartDate;
     // this should get us the number of steps per hour * 24 = numSteps per day * days per season = steps/year * numSeasons = steps/simulation
     this.mNumTotalTimeSteps = (this.mElapsedTimeBetweenTimeStep / 60) * 24 * this.NumDaysSeason * this.NumSeasons;
     this.currTimeStep       = 0;
 }
Ejemplo n.º 6
0
 /********************************************************************************
  *  Function name   : addHourlyModifier
  *  Description     :
  *  Return type     : void
  *  Argument        : HourlyModifier inHm
  * *******************************************************************************/
 public void addHourlyModifier(HourlyModifier inHm)
 {
     try
     {
         mLog.Debug("inside sim manager adding an hourly modifier current Count is " +
                    myHourlyModifiers.Count.ToString());
         myHourlyModifiers.Add(inHm.StartTime, inHm);
         mLog.Debug("now the Count is " + myHourlyModifiers.Count.ToString());
     }
     catch (System.Exception ex)
     {
         eLog.Debug(ex);
     }
 }
Ejemplo n.º 7
0
        /********************************************************************************
         *  Function name   : checkTemporalModifiers
         *  Description     :
         *  Return type     : void
         * *******************************************************************************/
        private void checkTemporalModifiers()
        {
            mLog.Debug("inside checkTemporalModifiers ");
            mLog.Debug("nextStartHour is " + nextStartHour.ToString());
            mLog.Debug("currTime.Hour is " + currTime.Hour.ToString());

            if (nextStartHour == this.currTime.Hour && this.currTime.Minute == 0)
            {
                mLog.Debug("must be time to change hourly modifier ");
                currHourMod        = this.myHourlyModifiers.getNext();
                this.nextStartHour = this.myHourlyModifiers.NextStartHour;
                mLog.Debug("so now the modifier start time is " + currHourMod.StartTime.ToString());
                mLog.Debug("and the next start time is " + this.nextStartHour.ToString());
            }
            if (this.nextDayStart.CompareTo(this.currTime) == 0)
            {
                currDailyMod      = this.myDailyModifiers.getNext();
                this.nextDayStart = this.myDailyModifiers.NextStartDate;
            }
            this.MapManager.changeMaps(this.currTime, this.mAnimalManager);
        }
Ejemplo n.º 8
0
        public virtual void doTimeStep(HourlyModifier inHM, DailyModifier inDM, DateTime currTime, bool doTextOutput, ref string status)
        {
            double percentTimeStep     = 0;
            double tempPercentTimeStep = 0;
            //added Sunday, May 04, 2008
            double previousPercentTimeStep = 0;
            //added temp for holding the old locations for doing text output
            double tempX = 0;
            double tempY = 0;
            //TODO talk to Pat about stuck on the way home?
            int  timesStuck        = 0;
            bool timeToLookForHome = false;


            try
            {
                //this.timeStepPath++;
                #region
                mLog.Debug("");
                mLog.Debug("inside Animal Do Time Step for " + myIdNum.ToString() +
                           " the time is " + currTime.ToShortDateString() + " " + currTime.ToShortTimeString());
                mLog.Debug("percent time step is " + percentTimeStep.ToString());
                mLog.Debug("is dead = " + this.mIsDead.ToString());
                mLog.Debug("do text output is " + doTextOutput.ToString());
                #endregion
                // if(this.IdNum == 14 | this.IdNum == 15) System.Windows.Forms.MessageBox.Show("animal 14");
                this.updateMyLocationValues();
                upDateTemporalModifiers(inHM, inDM);
                this.upDateMyValues();
                while (percentTimeStep < 1 && !this.mIsDead)
                {
                    //if(this.Location.X == 0) System.Windows.Forms.MessageBox.Show("No Location");

                    this.timeStep++;

                    //store off the original location

                    tempX = this.myLocation.X;
                    tempY = this.myLocation.Y;
                    // fw.writeLine("tempX = " + tempX.ToString());
                    // fw.writeLine("tempY = " + tempY.ToString());
                    // fw.writeLine("calling update behavioral modifier");


                    move(ref percentTimeStep); mLog.Debug("move returned  " + percentTimeStep.ToString());
                    mLog.Debug("previousPercentTimeStep is " + previousPercentTimeStep.ToString());
                    mLog.Debug("tempPercentTimeStep is " + tempPercentTimeStep.ToString());

                    //Saturday, March 15, 2008 added checking to see if his is dead from wandering off the map
                    if (!this.IsDead)
                    {
                        //Saturday, September 22, 2007 10:03:58 AM Author: Bob Cummings
                        //Added tempPercentTimeStep for accurate percentage on second and subsequent moves in same timestep
                        //so temp should equal 1 - current percent - last times current percent to get this times current percent
                        //Sunday, May 04, 2008 4:14:38 PM Author: Bob Cummings
                        //For some reason I had tempPercentTimeStep = 1 - percentTimeStep - tempPercentTimeStep
                        //But the percent time step is accumlative and the temp% is individual
                        //so added a another temp variable to keep track of accumalting percentTimeSteps

                        //Monday, June 09, 2008
                        tempPercentTimeStep      = percentTimeStep - previousPercentTimeStep;
                        previousPercentTimeStep += tempPercentTimeStep;
                        mLog.Debug("previousPercentTimeStep is " + previousPercentTimeStep.ToString());
                        mLog.Debug("tempPercentTimeStep is " + tempPercentTimeStep.ToString());
                        mLog.Debug("total percent time step is " + percentTimeStep.ToString());

                        //Thursday, February 21, 2008 Moved after move to capture the percent of the step taken
                        //Wednesday, March 05, 2008 moved after calculating the the temp percent to accurately capture the value.
                        if (doTextOutput)
                        {
                            mTextFileWriter.addLine(this.createTextOutput(currTime, tempPercentTimeStep, tempX, tempY));
                        }

                        // do these for every time time step full or partial
                        loseEnergy(tempPercentTimeStep);
                        eat(tempPercentTimeStep);
                        die(tempPercentTimeStep);
                        this.updateBehavioralModifiers();
                        // only do these if going to take another partial step
                        if (percentTimeStep < 1)
                        {
                            this.updateMyLocationValues();
                            this.upDateMyValues();
                        }
                    }
                }
                //Saturday, March 15, 2008 added checking to see if his is dead from wandering off the map
                if (!this.IsDead)
                {
                    if (this.IsAsleep == false)
                    {
                        mLog.Debug("ok now see if it is time to look for a home yet");
                        //Author: Bob Cummings Friday, October 05, 2007
                        //moved this to inside if statement to stop looking for a home
                        //while asleep.
                        timeToLookForHome = this.mHomeRangeTrigger.timeToLookForHome(this);
                    }

                    if (timeToLookForHome && !this.goingHome && this.MyVisitedSites.SiteCount > 0)
                    {
                        mLog.Debug("yes it is time to look for a home calling find home");

                        if (findHome())
                        {
                            this.mTextFileWriter.addLine("I have found a home and I am going to it");
                            mLog.Debug("back in doTimeStep and we found a home to set the mover to directed mover");
                            mLog.Debug("and set the boolean variable goingHome = true");
                            this.mMover    = new DirectedMover();
                            this.goingHome = true;
                        }//if we do not find a home we keep wandering around and check again.
                    }

                    if (this.goingHome)
                    {
                        double distToHome;
                        mLog.Debug("ok we are headed home now check the distace between here and there");
                        distToHome = this.MapManager.getDistance(this.Location, this.HomeRangeCenter);
                        mLog.Debug("we still have to go " + distToHome.ToString());
                        mLog.Debug("I can see " + this.mPerceptionDist.ToString());
                        if (distToHome < this.mPerceptionDist)
                        {
                            mLog.Debug("now building the home range");
                            // only change to resident if we were able to build the home range
                            if (this.MapManager.BuildHomeRange(this))
                            {
                                mLog.Debug("found a home");
                                mLog.Debug("ok we are home now setting the location = home range center");
                                mLog.Debug("the new X should = " + this.HomeRangeCenter.X.ToString());
                                mLog.Debug("the new Y should = " + this.HomeRangeCenter.Y.ToString());
                                this.Location = this.HomeRangeCenter as PointClass;
                                mLog.Debug("the new X = " + this.Location.X.ToString());
                                mLog.Debug("the new Y = " + this.Location.Y.ToString());
                                this.foundHome = true;
                                status         = "resident";
                                if (doTextOutput)
                                {
                                    this.mTextFileWriter.addLine("Found Home at " + this.myLocation.X.ToString() + " and " + this.myLocation.Y.ToString());
                                }
                                // System.Windows.Forms.MessageBox.Show(this.IdNum.ToString() + " found a home kill the application and look at at the input social map ");
                            }
                            else
                            {
                                //evidently can not build a site here.
                                goingHome = false;
                                myMover   = RandomWCMover.getRandomWCMover();
                                MyVisitedSites.RemoveSite(this.HomeRangeCenter);
                            }
                        }
                    }

                    //No sense doing if we are home.
                    if (foundHome == false)
                    {
                        //Saturday, February 23, 2008 Move to before taking a step
                        //Tuesday, July 15, 2008 move back to end of step
                        if (this.IsAsleep == false)
                        {
                            this.mMyVisitedSites.addSite(new EligibleHomeSite(this.mCaptureFood, this.mPredationRisk, this.myLocation.X, this.myLocation.Y));
                        }

                        if (this.goingHome && this.IsAsleep == false)
                        {
                            timesStuck++;
                            if (timesStuck > 20)
                            {
                                this.IsDead = true;
                                mTextFileWriter.addLine("Stuck on the way home for 20 times so died");
                                //get out of the loop
                                percentTimeStep = 1.5;
                            }
                        }
                    }
                }
                changeActiveState(currTime);
            }
            catch (System.Exception ex)
            {
                eLog.Debug(ex);
            }
        }
Ejemplo n.º 9
0
 public override void  doTimeStep(HourlyModifier inHM, DailyModifier inDM, DateTime currTime, bool doTextOutput, ref string status)
 {
     //removed logging per alex
     //BC 08/08/2013
     //mLog.Debug("dead disperser number " + this.IdNum.ToString() + " is not takeing a timestep");
 }