Exemple #1
0
        private void SavePathInfoInDatabase(PathResultInformation pathResultInformation)
        {
            DatabaseInformationInputer dbOut = new DatabaseInformationInputer();

            dbOut.info.Add(pathResultInformation);
            dbOut.SaveChanges();
        }
Exemple #2
0
        private void WorkAtOverAgain(ref Stack <int> stackFirstManipulator, ref PathResultInformation pathResultInformation)
        {
            int iteration = 0;

            Initalize();
            int pathStackCapacity = -1;
            Tuple <int, int, int, int, int, int> region = GetRegionMarks(_startPoint, _endPoint);

            rbLog.AppendText("Определяем регион вхождения точек..\n");
            rbLog.ScrollToCaret();
            rbLog.Refresh();
            PathRegion pathRegion = new PathRegion(region.Item1, region.Item4, region.Item2, region.Item5, region.Item3, region.Item6);

            do
            {
                rbLog.AppendText("Составляем вероятностную дорожную карту..\n");
                rbLog.ScrollToCaret();
                rbLog.Refresh();
                GetGraphPath(1, 0, pathRegion);
                rbLog.AppendText("Обработка графа алгоритмом Дейкстры..\n");
                rbLog.ScrollToCaret();
                rbLog.ScrollToCaret();
                rbLog.Refresh();
                Deikstra(ref _graphVertices, _adjencyMatrixManipulator);
                rbLog.AppendText("Попытка найти путь в графе..\n");
                rbLog.ScrollToCaret();
                rbLog.Refresh();
                stackFirstManipulator = GetPathAfterDeikstra(_graphVertices, _adjencyMatrixManipulator);
                pathStackCapacity     = stackFirstManipulator.Count;
                if (stackFirstManipulator.Count > 1)
                {
                    rbLog.AppendText("Путь найден..\n");
                    rbLog.ScrollToCaret();
                    rbLog.Refresh();
                    GetFinalPathAndDraw(stackFirstManipulator, Brushes.Purple, _graphVertices, _startPoint, _endPoint);
                }
                iteration++;
                if (iteration >= 2 && iteration <= 4)
                {
                    rbLog.Text += "Расширяем регион карты..\n";
                    rbLog.ScrollToCaret();
                    rbLog.Refresh();
                    pathRegion = new PathRegion((pathRegion.minX - _safeDistance) > 0 ? pathRegion.minX - _safeDistance : 0,
                                                pathRegion.maxX + _safeDistance, (pathRegion.minY - _safeDistance) > 0 ? pathRegion.minY - _safeDistance : 0,
                                                pathRegion.maxY + _safeDistance, (pathRegion.minZ - _safeDistance) > 0 ? pathRegion.minZ - _safeDistance : 0, pathRegion.maxZ + _safeDistance);
                }
            }while (pathStackCapacity <= 1);
            rbLog.AppendText("Сохраняем решение в базу данных..\n");
            rbLog.ScrollToCaret();
            rbLog.Refresh();
            pathResultInformation =
                new PathResultInformation(
                    new PathRegion(region.Item1, region.Item4, region.Item2, region.Item5, region.Item3, region.Item6),
                    _obstaclesPoints, _adjencyMatrixManipulator, _graphVertices, _safeDistance);
        }
Exemple #3
0
        private void btnStartAlgoritm_Click(object sender, EventArgs e)
        {
            _startPoint            = new Point3D((double)nudStartXVertex.Value, (double)nudStartYVertex.Value, (double)nudStartZVertex.Value);
            _endPoint              = new Point3D((double)nudEndXVertex.Value, (double)nudEndYVertex.Value, (double)nudEndZVertex.Value);
            _boxSize               = new Size3D((int)nudWidthObject.Value, (int)nudLengthObject.Value, (int)nudHeightObject.Value);
            _percentageComparer    = (int)nudPercentagePointCloud.Value;
            _iterations            = (int)nudIterationCount.Value;
            _distanceBetweenPoints = (int)nudDistanceBetweenVertexes.Value;
            _safeDistance          = GetSafeDistance(_boxSize);
            rbLog.AppendText("Обработка введенной информации..\n");
            rbLog.ScrollToCaret();
            rbLog.Refresh();
            DateTimeOffset             start                 = DateTimeOffset.Now;
            PathRegion                 finalPathRegion       = new PathRegion();
            Stack <int>                stackFirstManipulator = new Stack <int>();
            PathResultInformation      pathResultInformation = new PathResultInformation();
            DatabaseInformationInputer dbGet                 = new DatabaseInformationInputer();

            rbLog.AppendText("Получение информации из базы данных..\n");
            rbLog.ScrollToCaret();
            rbLog.Refresh();
            var getAllDb = (from p in dbGet.info
                            join c in dbGet.pathRegions on p.regionGraph.id equals c.id
                            where (c.maxX >= _startPoint.X && c.minX <= _startPoint.X && c.maxY >= _startPoint.Y && c.minY <= _startPoint.Y &&
                                   c.maxZ >= _startPoint.Z && c.minZ <= _startPoint.Z) ||
                            (c.maxX >= _endPoint.X && c.minX <= _endPoint.X && c.maxY >= _endPoint.Y && c.minY <= _endPoint.Y &&
                             c.maxZ >= _endPoint.Z && c.minZ <= _endPoint.Z)
                            select new
            {
                graphVertex = p.graphVertexes,
                adjencyMatrix = p.adjencyMatrix,
                obstaclesPoint = p.obstaclesPoint,
                pathRegion = p.regionGraph,
                safeDistance = p.safeDistance
            }).ToList();

            rbLog.AppendText("Проверка подходящих вариантов из базы данных..\n");
            rbLog.ScrollToCaret();
            rbLog.Refresh();
            if (!getAllDb.Count.Equals(0))
            {
                for (int i = 0; i < getAllDb.Count; i++)
                {
                    PathRegion         pathRegion     = getAllDb[i].pathRegion;
                    Tuple <bool, bool> comparerResult = PathParametersComparer.RegionCompare(_startPoint, _endPoint, pathRegion, _safeDistance);
                    bool isSolutionFind = false;
                    if (!comparerResult.Equals(new Tuple <bool, bool>(false, false)) &&
                        ComparerItemsInalizer.ComparerPointCloudComparerInPercenrage(_obstaclesPoints,
                                                                                     (List <Point3D>)CompleteSolutionAnalizer.GetObstaclesVertexes(getAllDb[i].obstaclesPoint), pathRegion) >= _percentageComparer &&
                        PathParametersComparer.AnalizeSafeDistance(_safeDistance, getAllDb[i].safeDistance))
                    {
                        switch (comparerResult)
                        {
                        case var tuple when tuple.Item1.Equals(true) && tuple.Item2.Equals(false):
                        {
                            rbLog.AppendText("Стартовая точка входит в регион. Идет достроение веротяностной карты (графа)..\n");
                            rbLog.ScrollToCaret();
                            rbLog.Refresh();
                            isSolutionFind            = true;
                            _adjencyMatrixManipulator = CompleteSolutionAnalizer.GetAdjencyMatrix(getAllDb[i].adjencyMatrix);
                            _graphVertices            = CompleteSolutionAnalizer.GetGraphVertexes(getAllDb[i].graphVertex);
                            _graphVertices.Add(new GraphVertex(_graphVertices.Count, _startPoint, true));
                            _graphVertices.Add(new GraphVertex(_graphVertices.Count, _endPoint, true));
                            SolutionFinderFromDb(_endPoint, pathRegion, ref finalPathRegion, ref isSolutionFind, _adjencyMatrixManipulator, _graphVertices,
                                                 _graphVertices.Count - 1, _graphVertices.Count - 2);
                            break;
                        }

                        case var tuple when tuple.Item1.Equals(false) && tuple.Item2.Equals(true):
                        {
                            rbLog.AppendText("Конечная точка входит в регион. Идет достроение вероятностной карты (графа)..\n");
                            rbLog.ScrollToCaret();
                            rbLog.Refresh();
                            isSolutionFind            = true;
                            _adjencyMatrixManipulator = CompleteSolutionAnalizer.GetAdjencyMatrix(getAllDb[i].adjencyMatrix);
                            _graphVertices            = CompleteSolutionAnalizer.GetGraphVertexes(getAllDb[i].graphVertex);
                            _graphVertices.Add(new GraphVertex(_graphVertices.Count, _startPoint, true));
                            _graphVertices.Add(new GraphVertex(_graphVertices.Count, _endPoint, true));
                            SolutionFinderFromDb(_startPoint, pathRegion, ref finalPathRegion, ref isSolutionFind, _adjencyMatrixManipulator, _graphVertices,
                                                 _graphVertices.Count - 1, _graphVertices.Count - 2);
                            break;
                        }

                        case var tuple when tuple.Item1.Equals(true) && tuple.Item2.Equals(true):
                        {
                            rbLog.AppendText("Обе точки входят в регион..\n");
                            rbLog.AppendText("Добавляем точки в карту..\n");
                            rbLog.ScrollToCaret();
                            rbLog.Refresh();
                            _adjencyMatrixManipulator = CompleteSolutionAnalizer.GetAdjencyMatrix(getAllDb[i].adjencyMatrix);
                            _graphVertices            = CompleteSolutionAnalizer.GetGraphVertexes(getAllDb[i].graphVertex);
                            List <GraphVertex> startEndVertexes = new List <GraphVertex>();
                            startEndVertexes.AddRange(new List <GraphVertex> {
                                    new GraphVertex(_graphVertices.Count, _startPoint, true),
                                    new GraphVertex(_graphVertices.Count + 1, _endPoint, true)
                                });
                            _adjencyMatrixManipulator = ResizeAdjencyMatrixManipulator(_adjencyMatrixManipulator, startEndVertexes.Count);
                            TryToConnect(_graphVertices, _distanceBetweenPoints, _adjencyMatrixManipulator, AlgoritmTryType.DatabaseDataWork, startEndVertexes);         ///////
                            _graphVertices.AddRange(startEndVertexes);
                            Deikstra(ref _graphVertices, _adjencyMatrixManipulator, _graphVertices.Count - 2);
                            stackFirstManipulator = GetPathAfterDeikstra(_graphVertices, _adjencyMatrixManipulator, _graphVertices.Count - 1);
                            GetFinalPathAndDraw(stackFirstManipulator, Brushes.Purple, _graphVertices, _startPoint, _endPoint);
                            finalPathRegion = pathRegion;
                            isSolutionFind  = true;
                            break;
                        }
                        }
                        if (isSolutionFind)
                        {
                            rbLog.AppendText("Решение найдено, происходит сохранение в базу данных..\n");
                            rbLog.ScrollToCaret();
                            rbLog.Refresh();
                            pathResultInformation = new PathResultInformation(finalPathRegion, _obstaclesPoints, _adjencyMatrixManipulator, _graphVertices, _safeDistance);
                            break;
                        }
                    }
                    if (!isSolutionFind)
                    {
                        _adjencyMatrixManipulator = new int[0, 0];
                        _graphVertices.Clear();
                        rbLog.AppendText("Не было найдено подходящих вариантов из базы данных..\n");
                        rbLog.ScrollToCaret();
                        rbLog.Refresh();
                    }
                }
            }
            else
            {
                rbLog.AppendText("Подходящих решений не найдено. Поиск нового решения..\n");
                rbLog.ScrollToCaret();
                rbLog.Refresh();
                WorkAtOverAgain(ref stackFirstManipulator, ref pathResultInformation);
            }
            try
            {
                SavePathInfoInDatabase(pathResultInformation);
            }
            catch (Exception ex)
            {
                WorkAtOverAgain(ref stackFirstManipulator, ref pathResultInformation);
                SavePathInfoInDatabase(pathResultInformation);
            }
            MessageBox.Show($"Путь найден!\n{start.ToString()}\n{DateTimeOffset.Now.ToString()}\nВсего вершин: {_graphVertices.Count}", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }