Beispiel #1
0
        // this fuction read the quary "main problem" and take file name as a parameter
        //return a list of quaries that we should solve

        public static List <quary> read_queries(string file_name)     // O(Q) Q is the # of Queries.
        {
            file_name += ".txt";
            List <quary> queries   = new List <quary>();
            FileStream   F         = new FileStream(file_name, FileMode.OpenOrCreate);
            StreamReader R         = new StreamReader(F);
            int          n_queries = int.Parse(R.ReadLine());

            for (int i = 0; i < n_queries; i++)                    // O(Q) Q is the # of Queries.
            {
                string   line = R.ReadLine();
                string[] l    = line.Split(' ');
                quary    q    = new quary(double.Parse(l[0]), double.Parse(l[1]), double.Parse(l[2]), double.Parse(l[3]), double.Parse(l[4]));
                queries.Add(q);
            }

            R.Close();
            return(queries);
        }
Beispiel #2
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);
                    }
                }
            }
        }