Esempio n. 1
0
 public AnimalManager()
 {
     mLog.Debug("getting the modifiers");
     mMaleModifier     = MaleModifier.GetUniqueInstance();
     mFemaleModifier   = FemaleModifier.GetUniqueInstance();
     mAnimalAttributes = new AnimalAtributes();
     mRiskySearchMod   = new RiskySearchModifier();
     mRiskyForageMod   = new RiskyForageModifier();
     mSafeForageMod    = new SafeForageModifier();
     mSafeSearchMod    = new SafeSearchModifier();
     mLog.Debug("now making the mover object");
     mMover         = RandomWCMover.getRandomWCMover();
     this.myAnimals = new List <Animal>();
     currNumAnimals = 0;
 }
Esempio n. 2
0
        //end of calcWakeTime
        private void changeActiveState(DateTime currTime)
        {
            mLog.Debug("inside change active state");
            if (this.IsAsleep == true)
            {
                mLog.Debug("must be asleep");
                mLog.Debug("Waketime is " + this.WakeupTime.Date.ToShortDateString() + " " + this.WakeupTime.TimeOfDay.ToString());

                mLog.Debug("curr time is " + currTime.Date.ToShortDateString() + " " + currTime.TimeOfDay.ToString());
                if ((this.WakeupTime.Date < currTime.Date) || (this.WakeupTime.Date <= currTime.Date && this.WakeupTime.TimeOfDay <= currTime.TimeOfDay))
                {
                    this.IsAsleep = false;
                    mLog.Debug("time to wake up, I am going home = " + this.goingHome.ToString());
                    //Sunday, February 24, 2008
                    //had issues when going home, would stop to sleep and then
                    //forget he was going home
                    if (this.goingHome)
                    {
                        this.myMover = new DirectedMover();
                    }
                    else
                    {
                        this.myMover = RandomWCMover.getRandomWCMover();
                    }
                    mLog.Debug("my new mover is a type of " + this.myMover.GetType().ToString());
                    calcSleepTime();
                }
            }
            else
            {
                mLog.Debug("must be awake");
                mLog.Debug("Sleep time is " + this.SleepTime.Date.ToShortDateString() + " " + this.SleepTime.TimeOfDay.ToString());
                mLog.Debug("curr time is " + currTime.Date.ToShortDateString() + " " + currTime.TimeOfDay.ToString());
                if ((this.SleepTime.Date < currTime.Date) || (this.SleepTime.Date <= currTime.Date && this.SleepTime.TimeOfDay <= currTime.TimeOfDay))
                {
                    this.IsAsleep = true;
                    this.myMover  = SleepMover.getSleepMover();
                    mLog.Debug("time to go to sleep");
                    calcWakeTime();
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
 public DirectedMover()
 {
     myMover = RandomWCMover.getRandomWCMover();
 }