Beispiel #1
0
 public PublicTransportPath(PublicTransport parent_p, long dest_p_id, long transport_id = 0, double transport_cost_dest = 0)
 {
     koef                     = 1;
     time_for_travel          = 5;
     koef_transfer            = 1;
     transport_id_dest        = transport_id;
     transport_id_sour        = parent_p.transport_id;
     parent_tp                = parent_p.point_id;
     dest_tp                  = dest_p_id;
     this.transport_cost_dest = transport_cost_dest;
 }
Beispiel #2
0
 public PublicTransportPath(PublicTransport last_point, double transport_cost_dest = 0)
 {
     koef                     = 999;
     time_for_travel          = 999;
     koef_transfer            = 99;
     transport_id_dest        = last_point.transport_id;
     transport_id_sour        = transport_id_dest;
     parent_tp                = last_point.point_id;
     dest_tp                  = last_point.point_id;
     this.transport_cost_dest = transport_cost_dest;
 }
Beispiel #3
0
 public PublicTransportPath(PublicTransport parent_p, PublicTransport dest_p, double transport_cost_dest = 0)
 {
     koef                     = 1;
     time_for_travel          = 5;
     koef_transfer            = 1;
     transport_id_sour        = parent_p.transport_id;
     transport_id_dest        = dest_p.transport_id;
     parent_tp                = parent_p.point_id;
     dest_tp                  = dest_p.point_id;
     this.transport_cost_dest = transport_cost_dest;
     if (dest_p.transport_id == parent_p.transport_id)
     {
         time_for_travel = Math.Abs(parent_p.avarage_time - dest_p.avarage_time);
     }
 }
Beispiel #4
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);
            }
        }