Exemplo n.º 1
0
        public void createMBR()
        {
            _mbr = new MBR();
            _mbr.unionWith(this.from);
            _mbr.unionWith(this.to);

            hasMBR = true;
        }
Exemplo n.º 2
0
        private void loadVertices(string vfile)
        {
            if (_V == null)
            {
                _V = new Dictionary <int, Vertex>();
            }
            else
            {
                _V.Clear();
            }

            System.IO.FileStream fs = new System.IO.FileStream(vfile, FileMode.Open, FileAccess.Read);
            StreamReader         sr = new StreamReader(fs);
            string strLine          = sr.ReadLine();

            while (strLine != null)
            {
                // 这里处理每一行
                string[] items = strLine.Split(new char[] { '\t' });
                Vertex   v     = new Vertex();
                v.ID = int.Parse(items[0]);
                v.X  = double.Parse(items[1]);
                v.Y  = double.Parse(items[2]);
                //v.type = int.Parse(items[3]);
                //v.entrance = int.Parse(items[4]);

                _ext.unionWith(v.X, v.Y);
                _V.Add(v.ID, v);

                strLine = sr.ReadLine();
            }

            sr.Close();
            fs.Close();
        }
Exemplo n.º 3
0
        protected void quadraticSplitNodes(List <rtree> oldItems, rtree newItem, List <rtree> set_one, List <rtree> set_two, MBR br_one, MBR br_two)
        {
            oldItems.Add(newItem);

            int    m = 0, n = 1;
            double maxArea = areaExpand(oldItems[0].m_br, oldItems[1].m_br);

            for (int i = 0; i < oldItems.Count; i++)
            {
                for (int j = i + 1; j < oldItems.Count; j++)
                {
                    double area = areaExpand(oldItems[i].m_br, oldItems[j].m_br);
                    if (area > maxArea)
                    {
                        maxArea = area;
                        m       = i;
                        n       = j;
                    }
                }
            }

            set_one.Add(oldItems[m]);
            set_two.Add(oldItems[n]);

            MBR set_one_mbr = new MBR(oldItems[m].m_br);
            MBR set_two_mbr = new MBR(oldItems[n].m_br);

            oldItems.RemoveAt(m);

            if (m < n)
            {
                oldItems.RemoveAt(n - 1);
            }
            else
            {
                oldItems.RemoveAt(n);
            }

            while (!(oldItems.Count == 0))
            {
                if (minItems - set_one.Count == oldItems.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_one.Add(oldItems[i]);
                        set_one_mbr.unionWith(oldItems[i].m_br);
                    }
                    break;
                }
                else if (oldItems.Count == minItems - set_two.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_two.Add(oldItems[i]);
                        set_two_mbr.unionWith(oldItems[i].m_br);
                    }
                    break;
                }

                int k = 0;

                double s = areaExpand(set_one_mbr, oldItems[k].m_br);
                double t = areaExpand(set_two_mbr, oldItems[k].m_br);

                if (s < t)
                {
                    set_one.Add(oldItems[k]);
                    set_one_mbr.unionWith(oldItems[k].m_br);
                }
                else
                {
                    set_two.Add(oldItems[k]);
                    set_two_mbr.unionWith(oldItems[k].m_br);
                }

                oldItems.RemoveAt(k);
            }

            br_one.become(set_one_mbr);
            br_two.become(set_two_mbr);
        }
        public void loadTrjfile(string trjfile, double Md)
        {
            double       time_interval = 0;//时间间隔
            FileStream   fs            = new FileStream(trjfile, FileMode.Open, FileAccess.Read);
            StreamReader sr            = new StreamReader(fs);
            int          i             = 0;

            if (_trj == null)
            {
                _trj = new Trajectory();
            }
            else
            {
                _trj.Clear();
            }

            if (_ext == null)
            {
                _ext = new MBR();
            }
            else
            {
                _ext.reset();
            }

            //mode
            string line = sr.ReadLine();

            while (line != null)
            {
                if (line == "X\tY\tT\tS\tD")
                {
                    line = sr.ReadLine();
                    continue;
                }
                string[] items = line.Split(new char[] { '\t' });

                double x = double.Parse(items[0]);
                double y = double.Parse(items[1]);
                //DateTime.Parse(items[0])
                DateTime t         = Convert.ToDateTime(items[2]);
                double   speed     = double.Parse(items[3]);
                double   direction = double.Parse(items[4]);

                if (i > 0)
                {
                    //以s为时间间隔进行读取
                    TimeSpan ts = t.Subtract(_trj[_trj.Count - 1].T).Duration();
                    if (Convert.ToDouble(ts.TotalSeconds) < time_interval)
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                    if (Math.Abs(x - _trj[_trj.Count - 1].X) < 0.00000001 && Math.Abs(y - _trj[_trj.Count - 1].Y) < 0.00000001)//剔除重复的点!!!
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                    if (Point.Distance(x, y, _trj[_trj.Count - 1].X, _trj[_trj.Count - 1].Y) < 20)//聚集点除噪音 && long.Parse(items[0]) != 1381604233
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                }
                Point p = new Point(t, x, y, direction, speed);
                _trj.Add(p);
                _ext.unionWith(p);


                if (i > 0)
                {
                    //斜率约束
                    if (i % 5 == 4)
                    {
                        Point p1 = _trj[_trj.Count - 5];
                        Point p2 = _trj[_trj.Count - 4];
                        Point p4 = _trj[_trj.Count - 2];
                        Point p5 = _trj[_trj.Count - 1];

                        double m1 = (p2.Y - p1.Y) / (p2.X - p1.X);
                        double m2 = (p5.Y - p4.Y) / (p5.X - p4.X);

                        if (Math.Abs(m2 - m1) <= Md)
                        {
                            _trj[_trj.Count - 3].X = (p2.X + p4.X) / 2;
                            _trj[_trj.Count - 3].Y = (p2.Y + p4.Y) / 2;
                        }
                    }
                }

                i++;

                line = sr.ReadLine();
            }

            sr.Close();
            fs.Close();

            _trj_size = _trj.Count;
        }
Exemplo n.º 5
0
        protected void quadraticSplitElements(List <Edge> oldItems, Edge newItem, List <Edge> set_one, List <Edge> set_two, MBR br_one, MBR br_two)
        {
            oldItems.Add(newItem);

            int    m = 0, n = 1;
            double maxdis = 0;

            for (int i = 0; i < oldItems.Count; i++)
            {
                for (int j = i + 1; j < oldItems.Count; j++)
                {
                    double p1_mid_x = (oldItems[i].From.X + oldItems[i].To.X) / 2;
                    double p1_mid_y = (oldItems[i].From.Y + oldItems[i].To.Y) / 2;
                    double p2_mid_x = (oldItems[j].From.X + oldItems[j].To.X) / 2;
                    double p2_mid_y = (oldItems[j].From.Y + oldItems[j].To.Y) / 2;

                    double dis = Math.Pow(p1_mid_x - p2_mid_x, 2) +
                                 Math.Pow(p1_mid_y - p2_mid_y, 2);

                    if (dis > maxdis)
                    {
                        maxdis = dis;
                        m      = i;
                        n      = j;
                    }
                }
            }

            set_one.Add(oldItems[m]);
            set_two.Add(oldItems[n]);

            br_one.unionWith(oldItems[m].getMBR());
            br_two.unionWith(oldItems[n].getMBR());

            oldItems.RemoveAt(m);

            if (m < n)
            {
                oldItems.RemoveAt(n - 1);
            }
            else
            {
                oldItems.RemoveAt(n);
            }

            while (!(oldItems.Count == 0))
            {
                if (minItems - set_one.Count == oldItems.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_one.Add(oldItems[i]);
                        br_one.unionWith(oldItems[i].getMBR());
                    }
                    break;
                }
                else if (oldItems.Count == minItems - set_two.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_two.Add(oldItems[i]);
                        br_two.unionWith(oldItems[i].getMBR());
                    }

                    break;
                }
                int k = 0;

                double s = areaEnlarge(br_one, oldItems[k]);
                double t = areaEnlarge(br_two, oldItems[k]);

                if (s < t)
                {
                    set_one.Add(oldItems[k]);
                    br_one.unionWith(oldItems[k].getMBR());
                }
                else
                {
                    set_two.Add(oldItems[k]);
                    br_two.unionWith(oldItems[k].getMBR());
                }

                oldItems.RemoveAt(k);
            }
        }