コード例 #1
0
ファイル: Program.cs プロジェクト: abdosayed22/Map-rotring
            public List <vertex> graphconst(string mapnom)
            {
                List <vertex>       listofpoints = new List <vertex>();
                List <weightededge> listofedgs   = new List <weightededge>();

                FileStream   fs = new FileStream(mapnom, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);

                using (StreamReader reader = File.OpenText(mapnom))
                {
                    int count = Int32.Parse(sr.ReadLine());
                    int a     = count;
                    reader.ReadLine();
                    for (int i = 0; i < count; i++)
                    {
                        vertex   p     = new vertex();
                        string   text  = reader.ReadLine();
                        string[] bitss = text.Split(' ');
                        p.index = int.Parse(bitss[0]);
                        p.index++;
                        p.x = float.Parse(bitss[1]);
                        p.y = float.Parse(bitss[2]);
                        listofpoints.Add(p);
                    }

                    int countE = Int32.Parse(reader.ReadLine());
                    for (int i = 0; i < countE; i++)
                    {
                        weightededge edge  = new weightededge();
                        string       textt = reader.ReadLine();
                        string[]     bits  = textt.Split(' ');
                        edge.start = int.Parse(bits[0]);
                        edge.start++;

                        edge.end = int.Parse(bits[1]);
                        edge.end++;

                        edge.distance = float.Parse(bits[2]);
                        edge.speed    = int.Parse(bits[3]);
                        edge.timecost = edge.distance / edge.speed;
                        listofedgs.Add(edge);
                    }

                    for (int i = 0; i < listofedgs.Count(); i++)
                    {
                        int s = listofedgs[i].start;
                        int d = listofedgs[i].end;


                        nieghbours n  = new nieghbours(d, listofedgs[i]);
                        nieghbours n2 = new nieghbours(s, listofedgs[i]);

                        listofpoints[s - 1].nieghbourr.Add(n);
                        listofpoints[d - 1].nieghbourr.Add(n2);
                    }

                    return(listofpoints);
                }
            }
コード例 #2
0
ファイル: Program.cs プロジェクト: abdosayed22/Map-rotring
            public List <data> runqueries(string querynom, List <vertex> nlistofpoints)
            {
                List <data>  qeuriesdata = new List <data>();
                queries      QE          = new queries();
                FileStream   fss         = new FileStream(querynom, FileMode.Open, FileAccess.Read);
                StreamReader srr         = new StreamReader(fss);
                int          countQ      = Int32.Parse(srr.ReadLine());

                using (StreamReader reader = File.OpenText(querynom))
                {
                    reader.ReadLine();
                    for (int i = 0; i < countQ; i++)
                    {
                        string   text  = reader.ReadLine();
                        string[] bitss = text.Split(' ');
                        QE.startX = float.Parse(bitss[0]);
                        QE.startY = float.Parse(bitss[1]);
                        QE.endX   = float.Parse(bitss[2]);
                        QE.endY   = float.Parse(bitss[3]);
                        QE.rad    = float.Parse(bitss[4]);

                        vertex v = new vertex();
                        v.x     = QE.startX;
                        v.y     = QE.startY;
                        v.index = 0;
                        nlistofpoints.Insert(0, v);

                        vertex vv = new vertex();
                        vv.x     = QE.endX;
                        vv.y     = QE.endY;
                        vv.index = nlistofpoints.Count();
                        nlistofpoints.Add(vv);

                        int cc = nlistofpoints.Count();
                        for (int j = 0; j < nlistofpoints.Count(); j++)
                        {
                            double result = Math.Pow(Math.Pow((nlistofpoints[j].x - QE.startX), 2) + Math.Pow((nlistofpoints[j].y - QE.startY), 2), 0.5);

                            if (QE.rad / 1000 >= result)
                            {
                                weightededge n  = new weightededge(0, j, (result / 5), 5, result);
                                nieghbours   ne = new nieghbours(j, n);
                                nlistofpoints[0].nieghbourr.Add(ne);


                                weightededge nn  = new weightededge(j, 0, (result / 5), 5, result);
                                nieghbours   nee = new nieghbours(0, nn);
                                nlistofpoints[j].nieghbourr.Add(nee);
                            }


                            if (j != nlistofpoints.Count() - 1)
                            {
                                double result1 = Math.Pow(Math.Pow((nlistofpoints[j].x - QE.endX), 2) + Math.Pow((nlistofpoints[j].y - QE.endY), 2), 0.5);

                                if (QE.rad / 1000 >= result1)
                                {
                                    weightededge n  = new weightededge((nlistofpoints.Count() - 1), j, (result1 / 5), 5, result1);
                                    nieghbours   ne = new nieghbours(j, n);
                                    nlistofpoints[(nlistofpoints.Count() - 1)].nieghbourr.Add(ne);
                                    weightededge nn  = new weightededge(j, (nlistofpoints.Count() - 1), (result1 / 5), 5, result1);
                                    nieghbours   nee = new nieghbours((nlistofpoints.Count() - 1), nn);
                                    nlistofpoints[j].nieghbourr.Add(nee);
                                }
                            }
                        }
                        wightedgraph g  = new wightedgraph(nlistofpoints);
                        dikstra      DS = new dikstra();
                        Stopwatch    sw = new Stopwatch();
                        sw.Start();
                        data qeurydata = DS.rundijkstra(g.graph.First().index, g.graph.Last().index, g);
                        sw.Stop();
                        long lon = sw.ElapsedMilliseconds;
                        sw.Reset();
                        qeurydata.elapsed = lon;
                        qeuriesdata.Add(qeurydata);

                        for (int m = 0; m < nlistofpoints.Count(); m++)
                        {
                            for (int n = 0; n < nlistofpoints[m].nieghbourr.Count(); n++)
                            {
                                if (nlistofpoints[m].nieghbourr[n].destnode == nlistofpoints.First().index || nlistofpoints[m].nieghbourr[n].destnode == nlistofpoints.Last().index)
                                {
                                    nlistofpoints[m].nieghbourr.RemoveAt(n);
                                }
                            }
                        }
                        nlistofpoints.Remove(nlistofpoints.First());
                        nlistofpoints.Remove(nlistofpoints.Last());
                    }
                }

                //Console.Write(sw.ElapsedMilliseconds + " \n");
                return(qeuriesdata);
            }