Пример #1
0
        public List <EligibleHomeSite> getQualifiedSites()
        {
            RandomNumbers           rn              = RandomNumbers.getInstance();
            double                  luckyNumber     = rn.getUniformRandomNum();
            List <EligibleHomeSite> qualifyingSites = new List <EligibleHomeSite>();

            foreach (EligibleHomeSite ehs in this.mySites)
            {
                if (luckyNumber >= ehs.Rank)
                {
                    qualifyingSites.Add(ehs);
                }
            }
            return(qualifyingSites);
        }
Пример #2
0
 //end of updateBehavioralModifiers
 public Animal()
 {
     this.MapManager      = MapManager.GetUniqueInstance();
     this.rn              = RandomNumbers.getInstance();
     this.Heading         = rn.getUniformRandomNum() * 2 * Math.PI;
     this.mPath           = new IPointList();
     this.mMyVisitedSites = new EligibleHomeSites();
     this.mIsDead         = false;
     this.IsAsleep        = false;
     this.timeStep        = -1;
     this.durationID      = 0;
     this.hadCloseCall    = false;
     this.goingHome       = false;
     this.foundHome       = false;
 }
Пример #3
0
        private IPolygon buildHomeRangePolygon(Animal inAnimal, double stretchFactor)
        {
            const int        numberOfPoints = 30;
            IPointCollection boundaryPoints = new PolygonClass();
            IPointCollection myPoints       = new MultipointClass();

            double[]      anglesList = new double[numberOfPoints];
            RandomNumbers rn         = RandomNumbers.getInstance();
            IGeometry     geom       = null;
            double        angle      = 0;
            double        radius     = 0;
            IPoint        tempPoint;
            object        missing = Type.Missing;
            IPolygon      returnPoly;


            try
            {
                geom = (IGeometry)boundaryPoints;

                mLog.Debug("inside buildHomeRangePolygon for animal " + inAnimal.IdNum.ToString());
                for (int i = 0; i < numberOfPoints; i++)
                {
                    anglesList[i] = (rn.getUniformRandomNum() * Math.PI * 2);
                }
                System.Array.Sort(anglesList);
                //go backwards to get clockwise polygon for external ring
                for (int i = numberOfPoints - 1; i >= 0; i--)
                {
                    tempPoint = new PointClass();
                    angle     = anglesList[i];
                    //radius is slightly larger than needed for home range to compensate for not being a circle
                    radius      = Math.Sqrt(1000000 * inAnimal.HomeRangeCriteria.Area / Math.PI) * rn.getPositiveNormalRandomNum(1.2, .1) * stretchFactor;
                    tempPoint.X = inAnimal.HomeRangeCenter.X + radius * Math.Cos(angle);
                    tempPoint.Y = inAnimal.HomeRangeCenter.Y + radius * Math.Sin(angle);
                    boundaryPoints.AddPoint(tempPoint, ref missing, ref missing);
                }
            }
            catch (Exception ex)
            {
                eLog.Debug(ex);
            }
            returnPoly = boundaryPoints as PolygonClass;
            returnPoly.Close();
            mLog.Debug("leaving buildHomeRangePolygon");
            return(returnPoly);
        }
Пример #4
0
 public BeamMeHomeScottyMover() : base()
 {
     rn = RandomNumbers.getInstance();
 }
Пример #5
0
        }//end of constructor

        #endregion

        #region public Methods
        // methods


        public virtual void move(ref double percentTimeStep, Animal inA)
        {
            IPoint        there = null;
            IPoint        here  = null;
            crossOverInfo co;

            try
            {
                mLog.Debug(" inside move method with animal passed in " + inA.IdNum.ToString());
                //get specs
                //get terrain modifiers from polygon
                double stepLen = inA.MoveSpeed * (1 - percentTimeStep); //determine step length
                double turt    = inA.MoveTurtosity;                     //determine turtosity
                double angle   = this.getTurnAngle(turt);               //determine turn angle

                mLog.Debug("step length is " + stepLen.ToString());
                mLog.Debug("turt is " + turt.ToString());
                mLog.Debug("angle is " + angle.ToString());
                mLog.Debug("Heading is " + inA.Heading.ToString());
                mLog.Debug("start location is X = " + inA.Location.X.ToString() + " Y= " + inA.Location.Y.ToString());
                mLog.Debug("now calling step");
                here = inA.Location;//get current location
                if (percentTimeStep > 0)
                {
                    angle = 0; //keep original heading if partial time step
                }

                //move
                there = step(stepLen, angle, here, inA.Heading);//get new location
                mLog.Debug("after step heading is " + inA.Heading.ToString());

                inA.Heading = (inA.Heading + angle);//set new heading
                mLog.Debug("new heading is " + inA.Heading.ToString());
                mLog.Debug("the current location is x = " + inA.Location.X.ToString() + " y = " + inA.Location.Y.ToString());
                mLog.Debug("the new  location is x = " + there.X.ToString() + " y = " + there.Y.ToString());
                mLog.Debug("now make sure the end point is on the map");
                if (myMapManager.isPointOnMoveMap(there))
                {
                    #region
                    co = this.myMapManager.getCrossOverInfo(here, there);//get crossover info

                    mLog.Debug("cross over info");
                    mLog.Debug("did we cross over any polyons = " + co.ChangedPolys.ToString());
                    mLog.Debug("CurrPolyValue = " + co.CurrPolyValue.ToString());
                    mLog.Debug("NewPolyValue = " + co.NewPolyValue.ToString());
                    mLog.Debug("Distance = " + co.Distance.ToString());
                    mLog.Debug(" X = " + co.Point.X.ToString() + " Y = " + co.Point.Y.ToString());
                    mLog.Debug("George is on the map = " + co.OnTheMap.ToString());

                    //check if this pushed us into a new polygon
                    //Wednesday, August 23, 2006 changed from length = length OR polyValue = polyValue
                    //length = length AND polyValue = polyValue
                    if (co.ChangedPolys == false)
                    //went the full distance stayed inside the same polygon the whole time
                    {
                        inA.Location    = there;
                        percentTimeStep = 1;
                    }
                    else //new poly, move to border,decide if you want to go or not, set percentTimeStep
                    {
                        double     likeHere       = 0.0;
                        double     likeThere      = 0.0;
                        double     distToBorder   = 0.0;
                        double     crossoverRatio = 0.0;
                        PointClass borderCrossing = null;


                        mLog.Debug("different polygon so now lets get to it");
                        mLog.Debug("calling mapmanager get cross over inFo");


                        //move to border
                        borderCrossing = co.Point;       //get point on border
                        inA.Location   = borderCrossing; //move to border

                        //decide if you want to go or not
                        likeHere       = co.CurrPolyValue;     //get the field that represents an animal's affinity for the current polygon
                        likeThere      = co.NewPolyValue;      //get the field that represents an animal's affinity for the new polygon
                        crossoverRatio = likeThere / likeHere; //calculate the ratio
                        //compare the ratio to a uniform random [0-1]
                        RandomNumbers rn = RandomNumbers.getInstance();

                        if (crossoverRatio > rn.getUniformRandomNum())//crossover
                        {
                            mLog.Debug("I am going to cross over");
                            //change poly to new poly
                            //Wednesday, July 02, 2008
                            //inA.MoveIndex = this.myMapManager.getCurrMovePolygon(co.NewPolyPoint);
                            //if we are going to cross over then give him a nudge into the new polygon
                            inA.Location.PutCoords(co.NewPolyPoint.X, co.NewPolyPoint.Y);
                        }
                        else //go back
                        {
                            mLog.Debug("I am not going to cross over");
                            inA.Heading = inA.Heading + Math.PI; //turn around
                            //Now move back into the orginal polygon
                            Mover.stepForward(ref inA);
                        }

                        //set percentTimeStep
                        distToBorder     = co.Distance;                                      //get dist from start to border crossing
                        percentTimeStep += (1 - percentTimeStep) * (distToBorder / stepLen); //Update percentTimeStep
                        percentTimeStep  = Math.Round(percentTimeStep, 2);                   //round to avoid taking steps < .01 time step
                    }
                }
                #endregion
                else
                {
                    //Wandered off the rest of the world
                    inA.IsDead = true;
                    inA.TextFileWriter.addLine("Animal has left the map");
                    percentTimeStep = 1;
                    return;
                }
                mLog.Debug("percent time step is " + percentTimeStep.ToString());
                mLog.Debug("now the heading value is " + inA.Heading.ToString());
                inA.updateMemory();
            }//end of try
            catch (System.Exception ex)
            {
                eLog.Debug(ex);
            } //end of catch
        }     //end of move
Пример #6
0
 public RandomWCMover() : base()
 {
     rn = RandomNumbers.getInstance();
 }
Пример #7
0
 private RandomWCMover() : base()
 {
     rn = RandomNumbers.getInstance();
 }