Exemplo n.º 1
0
 //compute similartiy of flow[x,y] and flow[y,x] and write it to a file.
 public void analyseSimilarity(Data data)
 {
     Encoding encode = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
     Stream s = File.OpenWrite("dds.txt");
     using (StreamWriter sr = new StreamWriter(s, encode))
     {
         for (int i = 0; i < Data.Node.size(); i++)
         {
             for (int j = i + 1; j < Data.Node.size(); j++)
             {
                 double similarity;
                 if (data.get(i, j) < data.get(j, i))
                 {
                     similarity = (double)data.get(i, j) / (double)data.get(j, i);
                 }
                 else
                 {
                     similarity = (double)data.get(j, i) / (double)data.get(i, j);
                 }
                 sr.WriteLine(data.nodeLineGet(i) + "\t" + data.nodeLineGet(j) + "\t" + similarity);
             }
         }
     }
     s.Close();
 }
Exemplo n.º 2
0
 //get degree of congestion by adding weights of edges connecting each node
 public void analyseCongestion(Data data)
 {
     Encoding encode = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
     Stream s = File.OpenWrite("conjestion.txt");
     using (StreamWriter sr = new StreamWriter(s, encode))
     {
         for (int i = 0; i < Data.Node.size(); i++)
         {
             int sum = 0;
             for (int j = i+1; j < Data.Node.size(); j++)
             {
                 sum += data.flow[i, j];
             }
             sr.WriteLine(data.nodeLineGet(i) + "\t" + sum);
         }
     }
     s.Close();
 }
Exemplo n.º 3
0
 //constructor
 public Algorithm(Data OD)
 {
     //data initialize
     this.OD = new Data(OD);
     numberOfNode = Data.Node.size();
     //flow initialize
     localFlow = new List<List<int>>();
     for (int i = 0; i < Data.Node.size(); i++)
     {
         List<int> tempList = new List<int>();
         for (int j = 0; j < Data.Node.size(); j++)
         {
             tempList.Add(OD.flow[i, j]);
         }
         this.localFlow.Add(tempList);
     }
     //lineIndex initialize
     lineIndex = new List<int>();
     for (int i = 0; i < Data.Node.size(); i++)
     {
         this.lineIndex.Add(i);
     }
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 //copy constructor
 public Data(Data data)
 {
     for (int i = 0; i < Node.size(); i++)
     {
         for (int j = 0; j < Node.size(); j++)
         {
             this.flow[i, j] = data.flow[i, j];
         }
     }
     this.counter = data.counter;
 }
Exemplo n.º 6
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;
        }