예제 #1
0
        //Загрузка остановок
        private void PTSLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
            openFileDialog1.Filter           = "PTS data (*.xml.PTS)|*.xml.PTS";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ButtonOff(PTSSearch);
                using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
                    while (!sr.EndOfStream)
                    {
                        Dictionary <long, List <PublicTransport> > PTS = new Dictionary <long, List <PublicTransport> >();
                        string[] data_all = sr.ReadLine().Split(new char[] { '<', '>' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var data in data_all)
                        {
                            if (data.Contains("avarage_time"))
                            {
                                long transport_number = Convert.ToInt64(data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]);
                                if (!PTS.ContainsKey(transport_number))
                                {
                                    PTS.Add(transport_number, new List <PublicTransport>());
                                }
                                PTS[transport_number].Add(new PublicTransport(data));
                            }
                        }
                        //тест
                        if (pictureBox_navmap.Image != null)
                        {
                            Color[] colors = new Color[PTS.Keys.Count];
                            int     size   = 12;
                            for (int i = 0; i < colors.Length; i++)
                            {
                                colors[i] = Color.FromArgb(255, new Random().Next(0, 255),
                                                           new Random().Next(0, 255), new Random().Next(0, 255));
                                size--;
                                List <long> points = new List <long>();
                                foreach (var pts in PTS[PTS.Keys.ToArray()[i]])
                                {
                                    points.Add(pts.point_id);
                                }
                                map.FlagThePoint(colors[i], size, points.ToArray());
                                pictureBox_navmap.Image = map.temp_map;
                            }
                        }
                        //тест окончен
                        foreach (var pts_transp in PTS)
                        {
                            PublicTransport[] pts = new PublicTransport[pts_transp.Value.Count];
                            foreach (var item in pts_transp.Value)
                            {
                                pts[item.count_stop - 1] = item;
                            }

                            for (int i = 0; i < pts.Length - 1; i++)
                            {
                                long id = pts[i].point_id;
                                if (!path.ContainsKey(id))
                                {
                                    path.Add(id, new List <PublicTransportPath>());
                                }
                                else
                                {
                                    PublicTransportPath[] temp = new PublicTransportPath[path[id].Count];
                                    path[id].CopyTo(temp);
                                    foreach (var item in temp)
                                    {
                                        if (pts[i].point_id == item.parent_tp)
                                        {
                                            PublicTransportPath temp_path = new PublicTransportPath(item.parent_tp, pts[i], item.transport_id_sour);
                                            if (!path[id].Contains(temp_path))
                                            {
                                                path[id].Add(temp_path);
                                            }
                                            PublicTransportPath temp_path_2 = new PublicTransportPath(pts[i], item.parent_tp, item.transport_id_sour);
                                            if (!path[id].Contains(temp_path_2))
                                            {
                                                path[id].Add(temp_path_2);
                                            }
                                        }
                                    }
                                }
                                path[id].Add(new PublicTransportPath(pts[i], pts[i + 1]));
                                if (i > 0)
                                {
                                    path[id].Add(new PublicTransportPath(pts[i], pts[i - 1]));
                                }
                            }
                            long id_ = pts[pts.Length - 1].point_id;
                            if (!path.ContainsKey(id_))
                            {
                                path.Add(id_, new List <PublicTransportPath>());
                            }
                            else
                            {
                                List <PublicTransportPath> temp = new List <PublicTransportPath>();
                                foreach (var item in path[id_])
                                {
                                    temp.Add(item);
                                }
                                foreach (var item in temp)
                                {
                                    path[id_].Add(new PublicTransportPath(item.parent_tp, pts[pts.Length - 1]));
                                }
                            }
                            path[id_].Add(new PublicTransportPath(pts[pts.Length - 1]));
                        }
                    }
                ButtonOn(PTSSearch);
            }
        }
예제 #2
0
        private void PTSSearch_Click(object sender, EventArgs e)
        {
            //Путь к остановкам
            map.Drop();
            double min             = double.MaxValue;
            long   closestLandmark = -1;

            foreach (var landmarks in tree.Landmarks.Keys)
            {
                double dist_h = tree.A[start].calculationCost(tree.A[landmarks].parametrs);
                if (dist_h < min)
                {
                    closestLandmark = landmarks;
                    min             = dist_h;
                }
            }
            bool altused;

            tree.A.Refresh_Search();
            List <long> path_1 = tree.GetWay(closestLandmark, start, out altused);

            min             = double.MaxValue;
            closestLandmark = -1;
            foreach (var landmarks in tree.Landmarks.Keys)
            {
                double dist_h = tree.A[end].calculationCost(tree.A[landmarks].parametrs);
                if (dist_h < min)
                {
                    closestLandmark = landmarks;
                    min             = dist_h;
                }
            }
            bool altused_2;

            tree.A.Refresh_Search();
            List <long> path_2 = tree.GetWay(closestLandmark, end, out altused_2);

            map.getWay(tree.A, path_1, map_index, Brushes.Red);
            map.getWay(tree.A, path_2, map_index, Brushes.Red);
            //Выбор транспорта
            double[] tps_costs = new double[] { 7.0f, 8.5f, 4.0f, 2.5f };
            for (int i = 0; i < 4; i++)
            {
                if (costs[i] != 0)
                {
                    tps_costs[i] = costs[i];
                }
            }
            double max_cost = tps_costs.Sum() + 1;

            foreach (var list_path in path.Values)
            {
                foreach (var single_path in list_path)
                {
                    if (single_path.transport_id_dest == 200)
                    {
                        single_path.transport_cost_dest = tps_costs[0];
                    }
                    if (single_path.transport_id_dest == 210)
                    {
                        single_path.transport_cost_dest = tps_costs[1];
                    }
                    if (single_path.transport_id_dest == 300)
                    {
                        single_path.transport_cost_dest = tps_costs[2];
                    }
                    if (single_path.transport_id_dest == 310)
                    {
                        single_path.transport_cost_dest = tps_costs[3];
                    }
                }
            }
            double total_cost;
            double total_time;
            Dictionary <long, long> way_trans;
            int mode = 0;

            if (checkBox_mode1.Checked)
            {
                mode = 1;
            }
            if (checkBox_mode2.Checked)
            {
                mode = 2;
            }
            if (altused)
            {
                path_1.Reverse();
            }
            if (altused_2)
            {
                path_2.Reverse();
            }
            List <long> way_publicstop = PublicTransportPath.GetPath(path, path_1[path_1.Count - 1], path_2[path_2.Count - 1], max_cost, out way_trans, out total_cost, out total_time, mode);
            double      t = total_cost;

            map.getWay(tree.A, way_publicstop, 0, Brushes.Red);
            textBox_info.Text       = "Travel cost:" + total_cost + " / Travel time:" + total_time;
            pictureBox_navmap.Image = map.temp_map;
            foreach (var itemlist in path)
            {
                foreach (var item in itemlist.Value)
                {
                    item.Reset();
                }
            }
        }