Example #1
0
        public static CityData GetCityData(float X, float Y)
        {
            CityData item   = null;
            bool     result = false;

            for (int j = 0; j < ClusterCount; j++)
            {
                foreach (System.Collections.DictionaryEntry obj in CityDataObjects[j])
                {
                    item = (CityData)obj.Value;
                    if (item.X == X && item.Y == Y)
                    {
                        result = true;
                    }
                }
                if (result)
                {
                    break;
                }
            }
            return(item);
        }
Example #2
0
        public static void SetUpMap(string MapFile, int NumofClusters)
        {
            try
            {
                MapFilename = MapFile;
                CityList.Clear();
                ClusterCount     = NumofClusters;
                CityDataObjects  = new Hashtable[NumofClusters];
                ClusteredObjects = new ArrayList[NumofClusters];


                for (int x = 0; x < NumofClusters; x++)
                {
                    ClusteredObjects[x] = new ArrayList();
                }


                float    AveCityPerCluster = 0;
                string[] items;
                string   data = "";

                System.IO.StreamReader sr = new System.IO.StreamReader(MapFile);
                data = sr.ReadLine();//skip first row, header row
                data = sr.ReadLine();

                while (data != null)
                {
                    CityList.Add(data);
                    data = sr.ReadLine();
                }
                AveCityPerCluster = (float)CityList.Count / (float)NumofClusters;
                int m = CityList.Count % NumofClusters;
                //Ensure all cities distributed between the number of clusters for K-Means computation later
                AveCityPerCluster  = (float)Math.Round(AveCityPerCluster, 0);
                AveCityPerCluster += m;

                int j = 0;
                int i = 1;

                CityDataObjects[j] = new Hashtable();

                foreach (string item in CityList)
                {
                    if (i <= AveCityPerCluster)
                    {
                        items = item.Split(',');
                        CityData city = new CityData(items[0], float.Parse(items[1]), float.Parse(items[2]), float.Parse(items[3]));
                        //Console.WriteLine(i.ToString() + " - " +city.CityName);
                        CityDataObjects[j].Add(items[0], city);
                        i += 1;
                    }
                    else
                    {
                        j    += 1; i = 1; CityDataObjects[j] = new Hashtable();
                        items = item.Split(',');
                        CityData city = new CityData(items[0], float.Parse(items[1]), float.Parse(items[2]), float.Parse(items[3]));
                        //Console.WriteLine(i.ToString() + " - " + city.CityName);
                        CityDataObjects[j].Add(items[0], city);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            //
        }