Exemple #1
0
        // Frist function that calc the source and distination edges that will be inserted into the graph to solve
        // insert the edge twice sorce to dis and the opposite
        public static void start_checking(quary q)  //Overall Complexity is O(|V|)
        {
            double x1 = new double();
            double y1 = new double();
            double x2 = new double();
            double y2 = new double();
            double r1 = new double();
            double x3 = new double();
            double y3 = new double();
            double x4 = new double();
            double y4 = new double();
            double r2 = new double();

            for (int i = 0; i < points.Count; i++)  //O(|V|)
            {
                x1 = Math.Abs(q.xs - points[i].x);
                y1 = Math.Abs(q.ys - points[i].y);
                x2 = x1 * x1;
                y2 = y1 * y1;
                r1 = Math.Sqrt(x2 + y2);
                x3 = Math.Abs(q.xd - points[i].x);
                y3 = Math.Abs(q.yd - points[i].y);
                x4 = x3 * x3;
                y4 = y3 * y3;
                r2 = Math.Sqrt(x4 + y4);
                if ((q.R / 1000) >= r1)
                {
                    source_intersections.Add(i);
                    edge e1 = new edge(oo, i, r1, 5);
                    edge e2 = new edge(i, oo, r1, 5);

                    map[i].Add(e2);
                    if (map.ContainsKey(oo))
                    {
                        List <edge> temp1 = map[oo];
                        temp1.Add(e1);
                        map[oo] = temp1;
                    }
                    else
                    {
                        List <edge> temp1 = new List <edge>();
                        temp1.Add(e1);
                        map.Add(oo, temp1);
                    }
                }

                if ((q.R / 1000) >= r2)
                {
                    destination_intersections.Add(i);
                    edge e1 = new edge(n_oo, i, r2, 5);
                    edge e2 = new edge(i, n_oo, r2, 5);

                    map[i].Add(e2);
                    if (map.ContainsKey(n_oo))
                    {
                        List <edge> temp1 = map[n_oo];
                        temp1.Add(e1);
                        map[n_oo] = temp1;
                    }
                    else
                    {
                        List <edge> temp1 = new List <edge>();
                        temp1.Add(e1);
                        map.Add(n_oo, temp1);
                    }
                }
            }
        }
Exemple #2
0
        public static long inner_st;                        //to get the execution time.
        /*This function read the map Text file witch contain the nodes and the edges*/
        //takes the file name as a parameter

        public static void read_map(string file_name)   // Overall Complexity is O(|E|).
        {
            file_name += ".txt";
            points     = new Dictionary <int, point>();
            map        = new Dictionary <int, List <edge> >();
            FileStream   F = new FileStream(file_name, FileMode.OpenOrCreate);
            StreamReader R = new StreamReader(F);

            int n_points = int.Parse(R.ReadLine());

            for (int i = 0; i < n_points; i++)        // O(|V|).
            {
                string   line = R.ReadLine();
                string[] l    = line.Split(' ');
                point    p    = new point();
                p.x = double.Parse(l[1]);
                p.y = double.Parse(l[2]);
                points.Add(int.Parse(l[0]), p);
            }

            int n_edges = int.Parse(R.ReadLine());

            for (int i = 0; i < n_edges; i++)             // O(|E|).
            {
                string   line = R.ReadLine();
                string[] l    = line.Split(' ');

                int    from     = int.Parse(l[0]);
                int    to       = int.Parse(l[1]);
                double distance = double.Parse(l[2]);
                double speed    = double.Parse(l[3]);

                /*here we do this as we want to add the edge twice
                 * so we cheak that if it was there just insert not add another new one and forget the old one */

                if (map.ContainsKey(from))
                {
                    List <edge> temp   = map[from];
                    edge        temp_e = new edge(from, to, distance, speed);
                    temp.Add(temp_e);
                    map[from] = temp;
                }
                else
                {
                    List <edge> temp   = new List <edge>();
                    edge        temp_e = new edge(from, to, distance, speed);
                    temp.Add(temp_e);
                    map.Add(from, temp);
                }

                if (map.ContainsKey(to))
                {
                    List <edge> temp1  = map[to];
                    edge        temp_p = new edge(to, from, distance, speed);
                    temp1.Add(temp_p);
                    map[to] = temp1;
                }
                else
                {
                    List <edge> temp1  = new List <edge>();
                    edge        temp_k = new edge(to, from, distance, speed);
                    temp1.Add(temp_k);
                    map.Add(to, temp1);
                }
            }
            R.Close();
        }