예제 #1
0
        public MainWindow()
        {
            InitializeComponent();
            this.Title = "Data Structure";
            ZoomControl.SetViewFinderVisibility(zoomctrl, Visibility.Visible);
            zoomctrl.ZoomToFill();

            DataAnalyzer analysis = new DataAnalyzer();

            //// Data file I/O test code
            Data[] data = new Data[9];
            string txt = @"OD_201301.txt";
            char[] buf = txt.ToCharArray();
            /*
            for (int x = 0; x < 9; x++)
            {
                string buf2 = new string(buf);
                data[x] = new Data();
                data[x].make(buf2);
                buf[8]++;
            }*/

            string buf2 = new string(buf);
            data[0] = new Data();
            data[0].make(buf2);
            buf[8]++;

            //DataAnalyzer analyse = new DataAnalyzer();
            //analyse.analyseSimilarity(data[0]);

            data[0].getUndirected();
            analysis.analyseCongestion(data[0]);

            /*
            Algorithm algo = new Algorithm(data[0]);
            for (int i = 0; i < 50; i++)
            {
                List<int> partition = algo.GetMinCut();
                algo.deleteNode(partition);
                List<String> names = new List<String>();
                for (int j = 0; j < partition.Count; j++)
                {
                    names.Add(Data.Node.lineGet(partition[j]));
                }
                //write result to a file
                Encoding encode = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
                //Stream s = File.OpenWrite("partition_result_1.txt");
                using (FileStream fs = new FileStream("partition_result_1.txt", FileMode.Append, FileAccess.Write))
                using (StreamWriter sr = new StreamWriter(fs, encode))
                {
                    for (int k = 0; k < names.Count; k++)
                    {
                        sr.Write(names[k]+" ");
                    }
                    sr.WriteLine("");
                    sr.Close();
                }
                int debug = 1;
            }
            //List<int> partition_2 = algo.GetMinCut();
            */
            DataReader stationReader = new DataReader("2line.txt");
            stations = stationReader.getStationNode();

            connections = new List<DataEdge>(3000);
            for(int source=0; source<stations.Count; source++){
                for(int destination=source; destination< stations.Count; destination++){
                    int weight = data[0].get(source, destination);
                    if(weight>10000){
                        connections.Add(new DataEdge(stations.ElementAt(source), stations.ElementAt(destination), 1));
                    }
                }
            }

            GraphArea_Setup();
            Area.GenerateGraph(true, true);
            zoomctrl.TranslateX = stations.Last<DataVertex>().location.longitude;
            zoomctrl.TranslateY = stations.Last<DataVertex>().location.latitude;
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();
            this.Title = "Data Structure";
            ZoomControl.SetViewFinderVisibility(zoomctrl, Visibility.Visible);
            zoomctrl.ZoomToFill();

            DataAnalyzer analysis = new DataAnalyzer();

            //// Data file I/O test code
            Data[] data = new Data[9];
            string txt  = @"OD_201301.txt";

            char[] buf = txt.ToCharArray();

            /*
             * for (int x = 0; x < 9; x++)
             * {
             *  string buf2 = new string(buf);
             *  data[x] = new Data();
             *  data[x].make(buf2);
             *  buf[8]++;
             * }*/

            string buf2 = new string(buf);

            data[0] = new Data();
            data[0].make(buf2);
            buf[8]++;

            //DataAnalyzer analyse = new DataAnalyzer();
            //analyse.analyseSimilarity(data[0]);

            data[0].getUndirected();
            analysis.analyseCongestion(data[0]);

            /*
             * Algorithm algo = new Algorithm(data[0]);
             * for (int i = 0; i < 50; i++)
             * {
             *  List<int> partition = algo.GetMinCut();
             *  algo.deleteNode(partition);
             *  List<String> names = new List<String>();
             *  for (int j = 0; j < partition.Count; j++)
             *  {
             *      names.Add(Data.Node.lineGet(partition[j]));
             *  }
             *  //write result to a file
             *  Encoding encode = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
             *  //Stream s = File.OpenWrite("partition_result_1.txt");
             *  using (FileStream fs = new FileStream("partition_result_1.txt", FileMode.Append, FileAccess.Write))
             *  using (StreamWriter sr = new StreamWriter(fs, encode))
             *  {
             *      for (int k = 0; k < names.Count; k++)
             *      {
             *          sr.Write(names[k]+" ");
             *      }
             *      sr.WriteLine("");
             *      sr.Close();
             *  }
             *  int debug = 1;
             * }
             * //List<int> partition_2 = algo.GetMinCut();
             */
            DataReader stationReader = new DataReader("2line.txt");

            stations = stationReader.getStationNode();

            connections = new List <DataEdge>(3000);
            for (int source = 0; source < stations.Count; source++)
            {
                for (int destination = source; destination < stations.Count; destination++)
                {
                    int weight = data[0].get(source, destination);
                    if (weight > 10000)
                    {
                        connections.Add(new DataEdge(stations.ElementAt(source), stations.ElementAt(destination), 1));
                    }
                }
            }

            GraphArea_Setup();
            Area.GenerateGraph(true, true);
            zoomctrl.TranslateX = stations.Last <DataVertex>().location.longitude;
            zoomctrl.TranslateY = stations.Last <DataVertex>().location.latitude;
        }