예제 #1
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void SetupCheckpionts()
        {
            chkpntList    = new List <Point3dNode> [4];
            chkpntList[0] = new List <Point3dNode>();
            chkpntList[1] = new List <Point3dNode>();
            chkpntList[2] = new List <Point3dNode>();
            chkpntList[3] = new List <Point3dNode>();

            //chkpntList.Clear();
            Point3dNode p;

            float dx = (float)a / n;

            for (int i = 0; i <= n; i++)
            {
                p        = new Point3dNode(i * dx, (float)(-b / a * (i * dx) + b), 0f);
                p.Region = 1;
                chkpntList[0].Add(p);

                p        = new Point3dNode(i * dx, 0f, (float)(-h / a * (i * dx) + h));
                p.Region = 2;
                chkpntList[1].Add(p);

                p        = new Point3dNode(i * dx, (float)(-c / a * (i * dx) + c), 0f);
                p.Region = 3;
                chkpntList[2].Add(p);
            }

            //chkpntList.Add(new Point3dNode(0f, (float)c, 0f));
            //chkpntList.Add(new Point3dNode(0f, (float)b, 0f));
            //chkpntList.Add(new Point3dNode(0f, 0f, (float)h));
            //chkpntList.Add(new Point3dNode((float)a, 0f, 0f));
        }
예제 #2
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!SetStartState && !SetFinishState)
            {
                return;
            }

            Point3dNode p;

            float eX = (e.X - vpr.ox) / vpr.zoom;
            float eY = (e.Y - vpr.oy) / vpr.zoom;

            double sinPhiH = Graphic3D.sin(vpr.phiH);
            double cosPhiH = Graphic3D.cos(vpr.phiH);
            double sinPhiV = Graphic3D.sin(vpr.phiV);
            double cosPhiV = Graphic3D.cos(vpr.phiV);

            //
            // ex   sinPhiH          -cosPhiH
            // ey   cosPhiH·cosPhiV  sinPhiH·cosPhiV
            //

            double Det = sinPhiH * sinPhiH * cosPhiV + cosPhiH * cosPhiV * cosPhiH;
            double Dx  = eX * sinPhiH * cosPhiV + eY * cosPhiH;
            double Dy  = sinPhiH * eY - cosPhiH * cosPhiV * eX;

            p = new Point3dNode((float)(Dx / Det), (float)(Dy / Det), 0f);

            Cursor = Cursors.Default;

            if (SetStartState)
            {
                p.Region = 0;
                startPos = p;
                checkBoxStart.Checked = false;
                SetStartState         = false;
            }

            if (SetFinishState)
            {
                p.Region  = 4;
                finishPos = p;
                checkBoxFinish.Checked = false;
                SetFinishState         = false;

                if (chkpntList != null)
                {
                    chkpntList[3].Clear();
                    chkpntList[3].Add(finishPos);
                }
            }

            Refresh();
        }
예제 #3
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void TestPath(List <Point3dNode> path)
        {
            if (bestPath == null)
            {
                bestPathLen = double.MaxValue;
                bestPath    = new List <Point3dNode>();
            }

            if (path.Count < 2)
            {
                //throw new ArgumentException();
                return;
            }

            double cost = 0;
            double dist = 0, time = 0;

            List <Point3dNode> .Enumerator i = path.GetEnumerator();
            i.MoveNext();
            Point3dNode prev = i.Current;

            for (; i.MoveNext();)
            {
                //cost += measuringMethod((Point3D)prev, (Point3D)i.Current);
                dist += MeasureDist((Point3D)prev, (Point3D)i.Current);
                time += MeasureTime((Point3D)prev, (Point3D)i.Current);
                prev  = i.Current;
            }

            if (measuringMethod == MeasureDist)
            {
                cost = dist;
            }
            if (measuringMethod == MeasureTime)
            {
                cost = time;
            }

            if (cost < bestPathLen)
            {
                bestPath.Clear();
                bestPath.AddRange(path);
                bestPathLen = cost;
            }

            Debug.Print("dist: {0}, time: {1}; best: {2}", dist, time, bestPathLen);

            Log(string.Format(
                    "Dist.: {0:#.000}, time.: {1:#.000}; best: {2:#.000}",
                    dist, time, bestPathLen)
                );
        }
예제 #4
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void BreadthFirstSearch()
        {
            //1. Поместить все узлы из множества So в список OPEN.
            lOpen.Add(startPos);

            traversed = false;
            while (!traversed)
            {
                //Log(string.Format("Open: {0}, closed: {1}.", lOpen.Count, lClosed.Count));

                if (lOpen.Count == 0)
                {
                    traversed = true;
                    break;
                }
                if (lOpen[0].Region == 4)
                {
                    GeneratePath();
                    Animate();
                    TestPath(path);
                }

                if (lOpen[0].Region <= 3) // можно раскрыть
                {
                    //4. Раскрыть вершину n и все порождённые вершины поместить в список OPEN настроив указатели к вершине n
                    for (int i = 0; i < chkpntList[lOpen[0].Region + 1 - 1].Count; i++)
                    {
                        Point3dNode t = new Point3dNode(chkpntList[lOpen[0].Region + 1 - 1][i]);
                        t.Previous = lOpen[0];

                        //5. Если порожденная вершина целевая, т.е. принадлежит Sq то выдать решение с помощью указателей, иначе перейти к шагу №2.
                        if (t.Equals(finishPos))
                        {
                            GeneratePath();
                            Animate();
                            TestPath(path);
                        }
                        else
                        {
                            lOpen.Add(t);
                        }
                    }
                }

                lClosed.Add(lOpen[0]);
                lOpen.RemoveAt(0);
            }

            Log(string.Format("Best path BFS: {0:#.##}", bestPathLen));
        }
예제 #5
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        new public bool Equals(object obj)
        {
            if (obj is Point3dNode)
            {
                Point3dNode p = (Point3dNode)obj;

                return
                    (p.Region == this.Region &&
                     p.x == this.x &&
                     p.y == this.y &&
                     p.z == this.z);
            }

            return(base.Equals(obj));
        }
예제 #6
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void GeneratePath()
        {
            if (path == null)
            {
                path = new List <Point3dNode>();
            }
            else
            {
                path.Clear();
            }

            path.Add(finishPos);
            Point3dNode curr = lOpen[q];

            while (curr != null)
            {
                path.Add(curr);
                curr = curr.Previous;
            }
        }
예제 #7
0
파일: Form1.cs 프로젝트: a-27m/vssdb
 public Point3dNode(Point3dNode p)
     : base(p.x, p.y, p.z)
 {
     Previous = p.Previous;
     Region   = p.Region;
 }
예제 #8
0
파일: Form1.cs 프로젝트: a-27m/vssdb
 public Point3dNode(float x, float y, float z)
     : base(x, y, z)
 {
     Previous = null;
     Region   = -1;
 }
예제 #9
0
파일: Form1.cs 프로젝트: a-27m/vssdb
        private void HeuristicsSearch()
        {
            //1. Поместить все узлы из множества So в список OPEN.
            lOpen.Add(startPos);

            traversed = false;
            while (!traversed)
            {
                //Log(string.Format("Open: {0}, closed: {1}.", lOpen.Count, lClosed.Count));

                if (lOpen.Count == 0)
                {
                    traversed = true;
                    break;
                }

                int p = 1;
                // search [open] for p and q
                int    pos     = 0;
                double minDist = double.MaxValue;
                foreach (Point3dNode node in lOpen)
                {
                    double dist = MeasureDist(node, finishPos);
                    if (dist < minDist)
                    {
                        minDist = dist;
                        q       = pos;
                    }

                    pos++;
                }

                if (lOpen[q].Region == 4)
                {
                    GeneratePath();
                    Animate();
                    TestPath(path);
                }

                //q = 0;
                if (lOpen[q].Region <= 3) // можно раскрыть
                {
                    //4. Раскрыть вершину n и все порождённые вершины поместить в список OPEN настроив указатели к вершине n
                    for (int i = 0; i < chkpntList[lOpen[q].Region + 1 - 1].Count; i++)
                    {
                        Point3dNode t = new Point3dNode(chkpntList[lOpen[q].Region + 1 - 1][i]);
                        t.Previous = lOpen[q];

                        //5. Если порожденная вершина целевая, т.е. принадлежит Sq то выдать решение с помощью указателей, иначе перейти к шагу №2.
                        if (t.Equals(finishPos))
                        {
                            GeneratePath();
                            Animate();
                            TestPath(path);
                        }
                        else
                        {
                            lOpen.Add(t);
                            //lOpen.Insert(p, t);
                            //if (q >= p) q += p;
                        }
                    }
                }

                lClosed.Add(lOpen[q]);
                lOpen.RemoveAt(q);
            }

            Log(string.Format("Best path EVR: {0:#.##}", bestPathLen));
        }