Ejemplo n.º 1
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode, LinkedList <NodeDisabledMovementDTO> nodes)
        {
            startNode.CurrentDistance = 0;
            NodeGraphDTO currentNode = null;
            bool         repeat      = true;

            while (repeat)
            {
                repeat = false;
                foreach (NodeDisabledMovementDTO node in nodes)
                {
                    currentNode = node;
                    foreach (Edge edge in currentNode.Node.EdgeStartNodeNavigation)
                    {
                        NodeGraphDTO adjacentNode = PrepareData.NodesGraph[edge.EndNodeNavigation];
                        double       edgeWeight   = edge.DistanceInMeters;

                        double sourceDistance = currentNode.CurrentDistance;
                        if (sourceDistance + edgeWeight < adjacentNode.CurrentDistance)
                        {
                            adjacentNode.CurrentDistance = sourceDistance + edgeWeight;
                            adjacentNode.PreviousNode    = currentNode;
                            repeat = true;
                        }

                        Utils.PocetSpracovanychVrcholov++;
                    }
                }
            }

            return(endNode);
        }
Ejemplo n.º 2
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode, Dictionary <Node, NodeGraphDTO> nodes)
        {
            startNode.CurrentDistance = 0;
            NodeGraphDTO currentNode = null;
            bool         repeat      = true;

            while (repeat)
            {
                repeat = false;
                foreach (KeyValuePair <Node, NodeGraphDTO> node in nodes)
                {
                    currentNode = node.Value;
                    foreach (Edge edge in currentNode.Node.EdgeStartNodeNavigation)
                    {
                        NodeGraphDTO adjacentNode = edge.EndNodeNavigation.NodeGraphDTO;
                        double       edgeWeight   = edge.DistanceInMeters;

                        double sourceDistance = currentNode.CurrentDistance;
                        if (sourceDistance + edgeWeight < adjacentNode.CurrentDistance)
                        {
                            adjacentNode.CurrentDistance = sourceDistance + edgeWeight;
                            adjacentNode.PreviousNode    = currentNode;
                            repeat = true;
                        }
                    }
                    Utils.PocetSpracovanychVrcholov++;
                }
            }

            if (endNode.PreviousNode == null)
            {
                return(null);
            }
            return(endNode);
        }
Ejemplo n.º 3
0
        private bool CalculateShortestPathR(NodeGraphDTO startNode)
        {
            NodeGraphDTO currentNode = GetLowestDistanceNode(unsettledTreeR);

            if (currentNode.Settled)
            {
                return(true);
            }

            foreach (Edge edge in currentNode.Node.EdgeEndNodeNavigation)
            {
                NodeGraphDTO adjacentNode = edge.StartNodeNavigation.NodeGraphDTO;
                double       edgeWeight   = edge.DistanceInMeters;

                if (!adjacentNode.SettledR)
                {
                    CalculateMinimumDistance(adjacentNode, edgeWeight, currentNode, unsettledTreeR);
                    if (adjacentNode.Equals(startNode))
                    {
                        settledNodesB.Add(adjacentNode);
                    }
                    if (!adjacentNode.UnsettledR)
                    {
                        unsettledTreeR.Add(adjacentNode);
                        adjacentNode.UnsettledR = true;
                    }
                }
            }

            Utils.PocetSpracovanychVrcholov++;
            currentNode.SettledR = true;
            return(false);
        }
Ejemplo n.º 4
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode)
        {
            startNode.MultiLabelMark.Add(new MultiLabelMark(0, 0, null, 0));

            MultiLabelMarkQueue currentMark   = null;
            BinaryTree          unsettledTree = new BinaryTree();

            foreach (Edge edge in startNode.Node.EdgeStartNodeNavigation)
            {
                unsettledTree.Add(new MultiLabelMarkQueue(edge.EndNodeNavigation.NodeGraphDTO, edge.DistanceInMeters, startNode, 0));
            }

            while (!unsettledTree.IsEmpty() && endNode.MultiLabelMark.Count < K)
            {
                currentMark = GetLowestDistanceNode(unsettledTree);

                int k = currentMark.W.MultiLabelMark.Count;
                if (k < K)
                {
                    k++;
                    currentMark.W.MultiLabelMark.Add(new MultiLabelMark(k, currentMark.T, currentMark.X, currentMark.Xk));

                    foreach (Edge edge in currentMark.W.Node.EdgeStartNodeNavigation)
                    {
                        if (!PathContainsNode(edge.EndNodeNavigation.NodeGraphDTO, currentMark.W, k))
                        {
                            unsettledTree.Add(new MultiLabelMarkQueue(edge.EndNodeNavigation.NodeGraphDTO, currentMark.T + edge.DistanceInMeters, currentMark.W, k));
                        }
                    }
                }
            }
            return(endNode);
        }
Ejemplo n.º 5
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode)
        {
            startNode.CurrentDistance = 0;

            NodeGraphDTO currentNode   = null;
            BinaryTree   unsettledTree = new BinaryTree(1);

            unsettledTree.Add(startNode);

            while (!unsettledTree.IsEmpty())
            {
                currentNode           = unsettledTree.GetMin();
                currentNode.Unsettled = false;

                if (currentNode.Equals(endNode))
                {
                    return(currentNode);
                }

                foreach (Edge edge in currentNode.Node.EdgeStartNodeNavigation)
                {
                    NodeGraphDTO adjacentNode = edge.EndNodeNavigation.NodeGraphDTO;
                    double       edgeWeight   = edge.DistanceInMeters;

                    if (!adjacentNode.Settled)
                    {
                        CalculateMinimumDistance(adjacentNode, edgeWeight, currentNode, unsettledTree);
                    }
                }
                Utils.PocetSpracovanychVrcholov++;
                currentNode.Settled = true;
            }
            return(null);
        }
Ejemplo n.º 6
0
 private void AddPrivate(NodeTree nodeTree, NodeGraphDTO nodeNew)
 {
     if ((comparer == 0 && nodeNew.Node.IdNode <= nodeTree.node.Node.IdNode) ||
         (comparer == 1 && nodeNew.CurrentDistance <= nodeTree.node.CurrentDistance) ||
         (comparer == 2 && nodeNew.FScore <= nodeTree.node.FScore) ||
         (comparer == 3 && nodeNew.CurrentDistanceR <= nodeTree.node.CurrentDistanceR))
     {
         if (nodeTree.left == null)
         {
             nodeTree.left = new NodeTree(nodeNew);
             return;
         }
         else
         {
             AddPrivate(nodeTree.left, nodeNew);
         }
     }
     else
     {
         if (nodeTree.right == null)
         {
             nodeTree.right = new NodeTree(nodeNew);
             return;
         }
         else
         {
             AddPrivate(nodeTree.right, nodeNew);
         }
     }
 }
Ejemplo n.º 7
0
        private void CalculateMinimumDistance(NodeGraphDTO evaluationNode, double edgeWeigh, NodeGraphDTO sourceNode, BinaryTree unsettledTree)
        {
            double sourceDistance = straight ? sourceNode.CurrentDistance : sourceNode.CurrentDistanceR;

            if ((straight && sourceDistance + edgeWeigh < evaluationNode.CurrentDistance) ||
                (!straight && sourceDistance + edgeWeigh < evaluationNode.CurrentDistanceR))
            {
                if (straight)
                {
                    if (evaluationNode.Unsettled)
                    {
                        evaluationNode.Unsettled = false;
                        unsettledTree.Remove(evaluationNode);
                    }
                    evaluationNode.CurrentDistance = sourceDistance + edgeWeigh;
                    evaluationNode.PreviousNode    = sourceNode;
                }
                else
                {
                    if (evaluationNode.UnsettledR)
                    {
                        evaluationNode.UnsettledR = false;
                        unsettledTree.Remove(evaluationNode);
                    }
                    evaluationNode.CurrentDistanceR = sourceDistance + edgeWeigh;
                    evaluationNode.PreviousNodeR    = sourceNode;
                }
                if (evaluationNode.PreviousNode != null && evaluationNode.PreviousNodeR != null)
                {
                    settledNodesB.Add(evaluationNode);
                }
            }
        }
Ejemplo n.º 8
0
        private RoutesDTO AfterCalculateShortestPath(NodeGraphDTO nodeCon)
        {
            if (nodeCon == null)
            {
                return(null);
            }

            NodeGraphDTO node = nodeCon;
            LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();

            while (node != null)
            {
                nodeRoute.AddLast(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNode;
            }

            RouteDTO route = new RouteDTO()
            {
                PocetHranCesty            = nodeRoute.Count - 1,
                PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                DlzkaCesty = Math.Round(nodeCon.CurrentDistance, 5),
                CasVypoctu = Math.Round(time.TotalMilliseconds, 5),
                Nodes      = nodeRoute
            };

            RoutesDTO routes = new RoutesDTO();

            routes.Route.AddLast(route);
            return(routes);
        }
Ejemplo n.º 9
0
        public RoutesDTO DuplexDijkster(string startLatLon, string endLatLon)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateShortestPath(startLatLon, endLatLon);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = duplexDijkster.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            return(AfterCalculateShortestPathDuplex(node));
        }
Ejemplo n.º 10
0
        public RoutesDTO Zakladny(string startLatLon, string endLatLon)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateShortestPath(startLatLon, endLatLon);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = zakladny.CalculateShortestPath(nodes.Key, nodes.Value, PrepareData.NodesGraph);

            watch.Stop();
            time = watch.Elapsed;
            return(AfterCalculateShortestPath(node));
        }
Ejemplo n.º 11
0
 public void Add(NodeGraphDTO node)
 {
     if (root == null)
     {
         root = new NodeTree(node);
     }
     else
     {
         AddPrivate(root, node);
     }
 }
Ejemplo n.º 12
0
        public RoutesDTO MultiLabel(string startLatLon, string endLatLon, string k)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateShortestPath(startLatLon, endLatLon);

            multiLabel.K = Int32.Parse(k);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = multiLabel.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            return(AfterCalculateShortestPathMultiLabel(node));
        }
Ejemplo n.º 13
0
 private static void PrepareNode(NodeGraphDTO n)
 {
     n.PreviousNode          = null;
     n.CurrentDistance       = Double.MaxValue;
     n.EstimateDistanceToEnd = Double.MaxValue;
     n.FScore           = Double.MaxValue;
     n.PreviousNodeR    = null;
     n.CurrentDistanceR = Double.MaxValue;
     n.MultiLabelMark.Clear();
     n.Settled    = false;
     n.Unsettled  = false;
     n.SettledR   = false;
     n.UnsettledR = false;
 }
Ejemplo n.º 14
0
        public RoutesDTO DuplexDijksterDisabled(string startLatLon, string endLatLon)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = duplexDijkster.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathDuplex(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Ejemplo n.º 15
0
        private void CalculateMinimumDistance(NodeGraphDTO evaluationNode, double edgeWeigh, NodeGraphDTO sourceNode, BinaryTree unsettledTree)
        {
            double sourceDistance = sourceNode.CurrentDistance;

            if (sourceDistance + edgeWeigh < evaluationNode.CurrentDistance)
            {
                if (evaluationNode.Unsettled)
                {
                    evaluationNode.Unsettled = false;
                    unsettledTree.Remove(evaluationNode);
                }
                evaluationNode.CurrentDistance = sourceDistance + edgeWeigh;
                evaluationNode.PreviousNode    = sourceNode;
            }
        }
Ejemplo n.º 16
0
        public RoutesDTO MultiLabelDIsabled(string startLatLon, string endLatLon, string k)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            multiLabel.K = Int32.Parse(k);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = multiLabel.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathMultiLabel(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Ejemplo n.º 17
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode)
        {
            straight = true;
            startNode.CurrentDistance = 0;
            endNode.CurrentDistanceR  = 0;
            unsettledTree.Clear();
            unsettledTreeR.Clear();
            settledNodesB = new HashSet <NodeGraphDTO>();

            unsettledTree.Add(startNode);
            unsettledTreeR.Add(endNode);

            bool found = false;

            while (!unsettledTree.IsEmpty() && !unsettledTreeR.IsEmpty() && !found)
            {
                if (straight)
                {
                    found    = CalculateShortestPathS(endNode);
                    straight = false;
                }
                else
                {
                    found    = CalculateShortestPathR(startNode);
                    straight = true;
                }
            }

            if (found)
            {
                NodeGraphDTO lowestDistanceNode = null;
                double       lowestDistance     = Double.MaxValue;
                foreach (NodeGraphDTO node in settledNodesB)
                {
                    double nodeDistance = node.CurrentDistance + node.CurrentDistanceR;
                    if (nodeDistance < lowestDistance)
                    {
                        lowestDistance     = nodeDistance;
                        lowestDistanceNode = node;
                    }
                }
                lowestDistanceNode.CurrentDistance = lowestDistance;
                return(lowestDistanceNode);
            }
            return(null);
        }
Ejemplo n.º 18
0
        private bool PathContainsNode(NodeGraphDTO nodeI, NodeGraphDTO nodePath, int kk)
        {
            NodeGraphDTO node = nodePath;
            int          k    = kk;
            int          xk;

            while (node.MultiLabelMark[k - 1].Xk != 0)
            {
                xk   = node.MultiLabelMark[k - 1].Xk;
                node = node.MultiLabelMark[k - 1].X;
                if (node.Equals(nodeI))
                {
                    return(true);
                }
                k = xk;
            }
            return(false);
        }
Ejemplo n.º 19
0
        public static void RemoveStartEnd(NodeGraphDTO nodeStart, NodeGraphDTO nodeEnd)
        {
            nodeStart.Node.EdgeStartNodeNavigation.Clear();
            tempStartEdge.ForEach(e => nodeStart.Node.EdgeStartNodeNavigation.Add(e));

            Dictionary <NodeDisabledMovementDTO, Edge> edgeForRemoveEnd = new Dictionary <NodeDisabledMovementDTO, Edge>();

            foreach (KeyValuePair <NodeDisabledMovementDTO, double> ndmEnd in NodesTempEnd[nodeEnd.Node])
            {
                foreach (Edge edge in ndmEnd.Key.Node.EdgeStartNodeNavigation)
                {
                    if (edge.IdEdge == -1)
                    {
                        edgeForRemoveEnd.Add(ndmEnd.Key, edge);
                    }
                }
            }
            foreach (KeyValuePair <NodeDisabledMovementDTO, Edge> remove in edgeForRemoveEnd)
            {
                remove.Key.Node.EdgeStartNodeNavigation.Remove(remove.Value);
            }

            nodeEnd.Node.EdgeEndNodeNavigation.Clear();
            tempEndEdge.ForEach(e => nodeEnd.Node.EdgeEndNodeNavigation.Add(e));

            edgeForRemoveEnd = new Dictionary <NodeDisabledMovementDTO, Edge>();
            foreach (KeyValuePair <NodeDisabledMovementDTO, double> ndmStart in NodesTempStart[nodeStart.Node])
            {
                foreach (Edge edge in ndmStart.Key.Node.EdgeEndNodeNavigation)
                {
                    if (edge.IdEdge == -1)
                    {
                        edgeForRemoveEnd.Add(ndmStart.Key, edge);
                    }
                }
            }
            foreach (KeyValuePair <NodeDisabledMovementDTO, Edge> remove in edgeForRemoveEnd)
            {
                remove.Key.Node.EdgeEndNodeNavigation.Remove(remove.Value);
            }
        }
Ejemplo n.º 20
0
        private void AfterCalculateShortestPathDuplex(NodeGraphDTO nodeCon, TimeSpan time, RoutesDTO routes)
        {
            if (nodeCon == null)
            {
                return;
            }

            NodeGraphDTO node = nodeCon;
            LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();

            while (node != null)
            {
                nodeRoute.AddLast(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNode;
            }

            node = nodeCon != null ? nodeCon.PreviousNodeR : null;
            while (node != null)
            {
                nodeRoute.AddFirst(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNodeR;
            }

            RouteDTO route = new RouteDTO()
            {
                PocetHranCesty            = nodeRoute.Count - 1,
                PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                DlzkaCesty = nodeCon.CurrentDistance / 1000,
                CasVypoctu = time.TotalMilliseconds
            };

            routes.Route.AddLast(route);
        }
Ejemplo n.º 21
0
        private RoutesDTO AfterCalculateShortestPathMultiLabel(NodeGraphDTO nodeCon)
        {
            if (nodeCon == null)
            {
                return(null);
            }

            RoutesDTO routes = new RoutesDTO();

            foreach (MultiLabelMark n in nodeCon.MultiLabelMark)
            {
                int          k     = n.K;
                int          xk    = k;
                NodeGraphDTO node  = nodeCon;
                RouteDTO     route = null;
                LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();
                while (xk != 0)
                {
                    nodeRoute.AddLast(new NodeLocationDTO()
                    {
                        Lat = node.Node.Lat,
                        Lon = node.Node.Lon
                    });
                    xk   = node.MultiLabelMark[k - 1].Xk;
                    node = node.MultiLabelMark[k - 1].X;
                    k    = xk;
                }

                route = new RouteDTO()
                {
                    PocetHranCesty            = nodeRoute.Count - 1,
                    PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                    DlzkaCesty = Math.Round(nodeCon.MultiLabelMark[n.K - 1].T, 5),
                    CasVypoctu = Math.Round(time.TotalMilliseconds, 5),
                    Nodes      = nodeRoute
                };
                routes.Route.AddLast(route);
            }
            return(routes);
        }
Ejemplo n.º 22
0
        public static void PutStartEnd(NodeGraphDTO nodeStart, NodeGraphDTO nodeEnd)
        {
            int idEdge = -1;

            tempStartEdge = nodeStart.Node.EdgeStartNodeNavigation.ToList();
            nodeStart.Node.EdgeStartNodeNavigation.Clear();
            if (NodesGraph.Keys.Contains(nodeStart.Node))
            {
                foreach (KeyValuePair <NodeDisabledMovementDTO, double> ndmStart in NodesTempStart[nodeStart.Node])
                {
                    Edge edge = new Edge()
                    {
                        IdEdge              = idEdge,
                        DistanceInMeters    = ndmStart.Value,
                        EndNodeNavigation   = ndmStart.Key.Node,
                        StartNodeNavigation = nodeStart.Node
                    };
                    nodeStart.Node.EdgeStartNodeNavigation.Add(edge);
                    ndmStart.Key.Node.EdgeEndNodeNavigation.Add(edge);
                }
            }

            tempEndEdge = nodeEnd.Node.EdgeEndNodeNavigation.ToList();
            nodeEnd.Node.EdgeEndNodeNavigation.Clear();
            if (NodesGraph.Keys.Contains(nodeEnd.Node))
            {
                foreach (KeyValuePair <NodeDisabledMovementDTO, double> ndmEnd in NodesTempEnd[nodeEnd.Node])
                {
                    Edge edge = new Edge()
                    {
                        IdEdge              = idEdge,
                        DistanceInMeters    = 0,
                        EndNodeNavigation   = nodeEnd.Node,
                        StartNodeNavigation = ndmEnd.Key.Node
                    };
                    ndmEnd.Key.Node.EdgeStartNodeNavigation.Add(edge);
                    nodeEnd.Node.EdgeEndNodeNavigation.Add(edge);
                }
            }
        }
Ejemplo n.º 23
0
        public NodeGraphDTO CalculateShortestPath(NodeGraphDTO startNode, NodeGraphDTO endNode)
        {
            startNode.CurrentDistance = 0;

            NodeGraphDTO         currentNode    = null;
            Queue <NodeGraphDTO> unsettledNodes = new Queue <NodeGraphDTO>();

            unsettledNodes.Enqueue(startNode);

            while (unsettledNodes.Count() != 0)
            {
                currentNode           = unsettledNodes.Dequeue();
                currentNode.Unsettled = false;

                foreach (Edge edge in currentNode.Node.EdgeStartNodeNavigation)
                {
                    NodeGraphDTO adjacentNode = edge.EndNodeNavigation.NodeGraphDTO;
                    double       edgeWeight   = edge.DistanceInMeters;

                    double sourceDistance = currentNode.CurrentDistance;
                    if (sourceDistance + edgeWeight < adjacentNode.CurrentDistance)
                    {
                        adjacentNode.CurrentDistance = sourceDistance + edgeWeight;
                        adjacentNode.PreviousNode    = currentNode;
                        if (!adjacentNode.Unsettled)
                        {
                            unsettledNodes.Enqueue(adjacentNode);
                            adjacentNode.Unsettled = true;
                        }
                    }
                }
                Utils.PocetSpracovanychVrcholov++;
            }

            if (endNode.PreviousNode == null)
            {
                return(null);
            }
            return(endNode);
        }
Ejemplo n.º 24
0
        public ActionResult Statistics()
        {
            var statistic = new
            {
                GraphMemory         = Utils.GraphMemory,
                DisabledGraphMemory = Utils.DisabledGraphMemory,
                GraphTime           = Utils.GraphTime,
                DisabledGraphTime   = Utils.DisabledGraphTime,
                PocetVrcholov       = Utils.PocetVrcholov
            };
            int            opakovani  = 10;
            int            algoritmus = 0;
            TimeSpan       time;
            Zakladny       zakladny       = new Zakladny();
            Dijkster       dijkster       = new Dijkster();
            AStar          astar          = new AStar();
            LabelCorrect   labelCorrect   = new LabelCorrect();
            LabelSet       labelSet       = new LabelSet();
            DuplexDijkster duplexDijkster = new DuplexDijkster();
            var            watch          = Stopwatch.StartNew();
            Random         random         = new Random();

            NodeGraphDTO[]   startNodes = new NodeGraphDTO[opakovani];
            NodeGraphDTO[]   endNodes   = new NodeGraphDTO[opakovani];
            List <RoutesDTO> routesAll  = new List <RoutesDTO>(6);

            for (int i = 0; i < opakovani; i++)
            {
                startNodes[i] = PrepareData.NodesGraph.Values.ElementAt(random.Next(PrepareData.NodesGraph.Count));
                endNodes[i]   = PrepareData.NodesGraph.Values.ElementAt(random.Next(PrepareData.NodesGraph.Count));
            }

            for (int j = 0; j < 6; j++)
            {
                RoutesDTO routes = new RoutesDTO();
                for (int i = 0; i < opakovani; i++)
                {
                    PrepareData.PrepareNodesGraph();
                    switch (j)
                    {
                    case 0:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        var n = zakladny.CalculateShortestPath(startNodes[i], endNodes[i], PrepareData.DisabledMovementGraph);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 1:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = dijkster.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 2:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = astar.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        var a = routes.Route.Last;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 3:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = labelSet.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 4:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = labelCorrect.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 5:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = duplexDijkster.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPathDuplex(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;
                    }
                }
                routesAll.Add(routes);
            }

            double[] PocetHranCesty            = new double[6];
            double[] PocetSpracovanychVrcholov = new double[6];
            double[] DlzkaCesty = new double[6];
            double[] CasVypoctu = new double[6];
            algoritmus = 0;
            foreach (RoutesDTO r in routesAll)
            {
                opakovani = r.Route.Count == 0 ? opakovani : r.Route.Count;
                long   PocetHranCestyA            = 0;
                long   PocetSpracovanychVrcholovA = 0;
                double DlzkaCestyA = 0;
                double CasVypoctuA = 0;
                foreach (RouteDTO route in r.Route)
                {
                    PocetHranCestyA            += route.PocetHranCesty;
                    PocetSpracovanychVrcholovA += route.PocetSpracovanychVrcholov;
                    DlzkaCestyA += route.DlzkaCesty;
                    CasVypoctuA += route.CasVypoctu;
                }
                PocetHranCesty[algoritmus]            = (double)PocetHranCestyA / opakovani;
                PocetSpracovanychVrcholov[algoritmus] = (double)PocetSpracovanychVrcholovA / opakovani;
                DlzkaCesty[algoritmus] = DlzkaCestyA / opakovani;
                CasVypoctu[algoritmus] = CasVypoctuA / opakovani;
                algoritmus++;
            }
            return(Json(statistic));
        }
Ejemplo n.º 25
0
        public bool Remove(NodeGraphDTO node)
        {
            if (root == null)
            {
                return(false);
            }
            NodeTree currentNode  = root;
            NodeTree previousNode = null;
            bool     left         = true;

            while (currentNode != null)
            {
                if (currentNode.node.Equals(node))
                {
                    NodeTree n = null, rightNode;
                    if (previousNode == null)
                    {
                        rightNode = root.right;
                        if (root.left == null)
                        {
                            root = root.right;
                        }
                        else
                        {
                            root = root.left;
                            n    = root;
                        }
                    }
                    else if (left)
                    {
                        rightNode = currentNode.right;
                        if (currentNode.left == null)
                        {
                            previousNode.left = currentNode.right;
                        }
                        else
                        {
                            previousNode.left = currentNode.left;
                            n = previousNode.left;
                        }
                    }
                    else
                    {
                        rightNode = currentNode.right;
                        if (currentNode.left == null)
                        {
                            previousNode.right = currentNode.right;
                        }
                        else
                        {
                            previousNode.right = currentNode.left;
                            n = previousNode.right;
                        }
                    }

                    if (n != null && rightNode != null)
                    {
                        while (n.right != null)
                        {
                            n = n.right;
                        }
                        n.right = rightNode;
                    }
                    return(true);
                }
                else if ((comparer == 0 && node.Node.IdNode <= currentNode.node.Node.IdNode) ||
                         (comparer == 1 && node.CurrentDistance <= currentNode.node.CurrentDistance) ||
                         (comparer == 2 && node.FScore <= currentNode.node.FScore) ||
                         (comparer == 3 && node.CurrentDistanceR <= currentNode.node.CurrentDistanceR))
                {
                    left         = true;
                    previousNode = currentNode;
                    currentNode  = currentNode.left;
                }
                else
                {
                    left         = false;
                    previousNode = currentNode;
                    currentNode  = currentNode.right;
                }
            }
            return(false);
        }
Ejemplo n.º 26
0
 public NodeTree(NodeGraphDTO node)
 {
     this.node = node;
 }