示例#1
0
        /// <summary>
        /// Reconstitutes the given tree into a new one (balances it)
        /// </summary>
        /// <param name="OldTree"></param>
        public Company_KDTree(Company_KDTree OldTree)
        {
            List <Company> CompanyList = new List <Company>();

            OldTree.GetAllCompanies(ref CompanyList);
            Company[] CompanyArray = CompanyList.ToArray();

            SplitDimensionIndex = 0;
            if (CompanyArray.Length > 2)
            {
                SortByDimension(ref CompanyArray, SplitDimensionIndex);
                int MedianIndex = CompanyArray.Length / 2;
                SplitPosition = CompanyArray[MedianIndex].Location[SplitDimensionIndex];
                Company[] LowerList = new Company[MedianIndex + 1];
                Company[] UpperList = new Company[CompanyArray.Length - MedianIndex - 1];
                Array.Copy(CompanyArray, 0, LowerList, 0, LowerList.Length);
                Array.Copy(CompanyArray, MedianIndex + 1, UpperList, 0, UpperList.Length);
                LessEqualNode = new Company_KDTree(SplitDimensionIndex, LowerList);
                GreaterNode   = new Company_KDTree(SplitDimensionIndex, UpperList);
            }
            else
            {
                Constituents = CompanyArray;
                isLeafNode   = true;
            }
        }
        /// <summary>
        /// Reconstitutes the given tree into a new one (balances it)
        /// </summary>
        /// <param name="OldTree"></param>
        public Company_KDTree(Company_KDTree OldTree)
        {
            List<Company> CompanyList = new List<Company>();
            OldTree.GetAllCompanies(ref CompanyList);
            Company[] CompanyArray = CompanyList.ToArray();

            SplitDimensionIndex = 0;
            if (CompanyArray.Length > 2)
            {
                SortByDimension(ref CompanyArray, SplitDimensionIndex);
                int MedianIndex = CompanyArray.Length / 2;
                SplitPosition = CompanyArray[MedianIndex].Location[SplitDimensionIndex];
                Company[] LowerList = new Company[MedianIndex + 1];
                Company[] UpperList = new Company[CompanyArray.Length - MedianIndex - 1];
                Array.Copy(CompanyArray, 0, LowerList, 0, LowerList.Length);
                Array.Copy(CompanyArray, MedianIndex + 1, UpperList, 0, UpperList.Length);
                LessEqualNode = new Company_KDTree(SplitDimensionIndex, LowerList);
                GreaterNode = new Company_KDTree(SplitDimensionIndex, UpperList);
            }
            else
            {
                Constituents = CompanyArray;
                isLeafNode = true;
            }
        }
示例#3
0
 public Manager()
 {
     for (int i = 0; i < 100; i++)
     {
         People.Add(new Person(GetRandomLocation()));
     }
     Businesses = new Company_KDTree(-1, new Company[0]);
     Statistics = new DataAggregator();
 }
示例#4
0
 public Manager()
 {
     for (int i = 0; i < 100; i++)
     {
         People.Add(new Person(GetRandomLocation()));
     }
     Businesses = new Company_KDTree(-1, new Company[0]);
     Statistics = new DataAggregator();
 }
示例#5
0
        public void Update(Object notUsed)
        {
            while (true)
            {
                if (Queue > 0)
                {
                    while (PauseRequest)
                    {
                        IsPaused = true;
                        Thread.Sleep(100);
                    }
                    IsPaused = false;

                    CurrentTurn++;

                    double AverageAge = 0.0;
                    for (int i = 0; i < People.Count; i++)
                    {
                        People[i].Update();
                        AverageAge += People[i].Age;
                    }
                    if (People.Count > 0)
                    {
                        AverageAge /= People.Count;
                        AverageAge = 1.0 + 0.01 * Math.Abs(AverageAge - 30);
                        FractionalPeople += People.Count * (Math.Pow(Math.E, 0.00025 / AverageAge) - 1.0);
                        while (FractionalPeople > 1.0)
                        {
                            FractionalPeople--;
                            People.Add(new Person(GetRandomLocation()));
                        }
                    }
                    Businesses = new Company_KDTree(Businesses);

                    Statistics.UpdateData();

                    Queue--;
                }
                else
                {
                    IsPaused = true;
                    Thread.Sleep(250);
                    //Queue += 10;
                }
            }
        }
示例#6
0
        public void Update(Object notUsed)
        {
            while (true)
            {
                if (Queue > 0)
                {
                    while (PauseRequest)
                    {
                        IsPaused = true;
                        Thread.Sleep(100);
                    }
                    IsPaused = false;

                    CurrentTurn++;

                    double AverageAge = 0.0;
                    for (int i = 0; i < People.Count; i++)
                    {
                        People[i].Update();
                        AverageAge += People[i].Age;
                    }
                    if (People.Count > 0)
                    {
                        AverageAge       /= People.Count;
                        AverageAge        = 1.0 + 0.01 * Math.Abs(AverageAge - 30);
                        FractionalPeople += People.Count * (Math.Pow(Math.E, 0.00025 / AverageAge) - 1.0);
                        while (FractionalPeople > 1.0)
                        {
                            FractionalPeople--;
                            People.Add(new Person(GetRandomLocation()));
                        }
                    }
                    Businesses = new Company_KDTree(Businesses);

                    Statistics.UpdateData();

                    Queue--;
                }
                else
                {
                    IsPaused = true;
                    Thread.Sleep(250);
                    //Queue += 10;
                }
            }
        }
示例#7
0
 /// <summary>
 /// Organizes Companies by X Y Z coordinates
 /// More efficient to recreate a tree rather than update it
 /// </summary>
 /// <param name="ParentSplitDimensionIndex">Outside of this constructor, inputs should be -1</param>
 /// <param name="UnitList">Should be converted from a List</param>
 public Company_KDTree(int ParentSplitDimensionIndex, Company[] CompanyList)
 {
     SplitDimensionIndex = (ParentSplitDimensionIndex + 1) % 3;
     if (CompanyList.Length > 2)
     {
         SortByDimension(ref CompanyList, SplitDimensionIndex);
         int MedianIndex = CompanyList.Length / 2;
         SplitPosition = CompanyList[MedianIndex].Location[SplitDimensionIndex];
         Company[] LowerList = new Company[MedianIndex + 1];
         Company[] UpperList = new Company[CompanyList.Length - MedianIndex - 1];
         Array.Copy(CompanyList, 0, LowerList, 0, LowerList.Length);
         Array.Copy(CompanyList, MedianIndex + 1, UpperList, 0, UpperList.Length);
         LessEqualNode = new Company_KDTree(SplitDimensionIndex, LowerList);
         GreaterNode   = new Company_KDTree(SplitDimensionIndex, UpperList);
     }
     else
     {
         Constituents = CompanyList;
         isLeafNode   = true;
     }
 }
 /// <summary>
 /// Organizes Companies by X Y Z coordinates
 /// More efficient to recreate a tree rather than update it
 /// </summary>
 /// <param name="ParentSplitDimensionIndex">Outside of this constructor, inputs should be -1</param>
 /// <param name="UnitList">Should be converted from a List</param>
 public Company_KDTree(int ParentSplitDimensionIndex, Company[] CompanyList)
 {
     SplitDimensionIndex = (ParentSplitDimensionIndex + 1) % 3;
     if (CompanyList.Length > 2)
     {
         SortByDimension(ref CompanyList, SplitDimensionIndex);
         int MedianIndex = CompanyList.Length / 2;
         SplitPosition = CompanyList[MedianIndex].Location[SplitDimensionIndex];
         Company[] LowerList = new Company[MedianIndex + 1];
         Company[] UpperList = new Company[CompanyList.Length - MedianIndex - 1];
         Array.Copy(CompanyList, 0, LowerList, 0, LowerList.Length);
         Array.Copy(CompanyList, MedianIndex + 1, UpperList, 0, UpperList.Length);
         LessEqualNode = new Company_KDTree(SplitDimensionIndex, LowerList);
         GreaterNode = new Company_KDTree(SplitDimensionIndex, UpperList);
     }
     else
     {
         Constituents = CompanyList;
         isLeafNode = true;
     }
 }