Пример #1
0
        private void Load_ODTIME_BTN_Click(object sender, EventArgs e)
        {
            MessageBox.Show("选择交通时间文件,文件需按id排序!");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "csv文件|*.csv|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStream   fs = new FileStream(openFileDialog.FileName, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                OD_TIME_TEXT.Text = Path.GetFileNameWithoutExtension(openFileDialog.FileName);

                string             line;
                Population_netWork temp = new Population_netWork();
                int id    = 0;
                int count = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    count++;
                    temp.grid_id = id;
                    string[] _array;
                    _array = line.Split(',');
                    int temp_id       = int.Parse(_array[0]);
                    int temp_duration = 0;
                    if (_array[1] != "None")
                    {
                        temp_duration = int.Parse(_array[1]);
                    }
                    else
                    {
                        temp_duration = int.MaxValue;
                    }
                    temp.durationList_toHospital.Add(temp_duration);
                    if (count % Facility_num == 0)
                    {
                        temp.grid_id         = Population_list[id].ID;
                        temp.grid_population = Population_list[id++].Population;
                        int min = int.MaxValue;
                        for (int j = 0; j < temp.durationList_toHospital.Count; j++)
                        {
                            if (temp.durationList_toHospital[j] <= min)
                            {
                                min = temp.durationList_toHospital[j];
                            }
                        }
                        temp.closet_travelTime = min;
                        grid_List.Add(temp);
                        temp = new Population_netWork();
                    }
                }
            }
        }
Пример #2
0
        private void Calculate_closetfacility()
        {
            //Facility_num = int.Parse(Facility_number.Text);
            MessageBox.Show("选择交通时间文件,文件需按id排序!");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "csv文件|*.csv|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStream   fs = new FileStream(openFileDialog.FileName, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                OD_TIME_TEXT.Text = Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                string             line;
                int                flag  = 1;
                int                id    = 0;
                Population_netWork temp  = new Population_netWork();
                int                count = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    try
                    {
                        count++;
                        temp.grid_id = id;
                        string[] _array;
                        _array = line.Split(',');
                        int temp_id       = int.Parse(_array[0]);
                        int temp_duration = 0;
                        if (_array[1] != "None")
                        {
                            temp_duration = int.Parse(_array[1]);
                        }
                        else
                        {
                            temp_duration = int.MaxValue;
                        }
                        temp.durationList_toHospital.Add(temp_duration);
                        if (count % Facility_num == 0)
                        {
                            temp.grid_id         = Population_list[id].ID;
                            temp.grid_population = Population_list[id++].Population;
                            //temp.durationList_toHospital.Sort();
                            int min = int.MaxValue;
                            for (int j = 0; j < temp.durationList_toHospital.Count; j++)
                            {
                                if (temp.durationList_toHospital[j] <= min)
                                {
                                    min = temp.durationList_toHospital[j];
                                }
                            }
                            temp.closet_travelTime = min;
                            grid_List.Add(temp);
                            temp = new Population_netWork();
                        }
                    }
                    catch
                    {
                        //int temp_duration = int.MaxValue;
                    }
                }
                sr.Close();
                fs.Close();
                double sum_ClosetTime = 0;
                for (int kk = 0; kk < grid_List.Count; kk++)
                {
                    sum_ClosetTime += grid_List[kk].closet_travelTime;
                }
                sum_ClosetTime /= grid_List.Count;
                if (flag_Thresold == 1)
                {
                    grid_List.Sort(new ClosetComparer());
                    int Population_threshold = int.Parse(Population_threshold_Textbox.Text) * Sum_population / 100;
                    int popu_count           = 0;
                    for (int i = 0; i < grid_List.Count; i++)
                    {
                        popu_count += grid_List[i].grid_population;
                        if (popu_count >= Population_threshold)
                        {
                            MessageBox.Show("根据最邻近方法计算时间阈值为:" + grid_List[i].closet_travelTime.ToString() + "秒,\r\n接下来进行各个格子的可达性得分计算,点击确定按钮.");
                            time_threshold = grid_List[i].closet_travelTime;
                            break;
                        }
                    }
                }
                else if (flag_Thresold == 2)
                {
                    time_threshold = int.Parse(Population_threshold_Textbox.Text) * 60;
                }
            }
        }