示例#1
0
        public void SetPathInfoCharacteristic()
        {
            if (stop == null)
            {
                distance = Double.MaxValue;
                exists   = false;
                return;
            }

            if (stop.IsNode)
            {
                ShortestPath firstPart = new ShortestPath(gps, start, (Node)stop);
                pathNodes.AddRange(firstPart.pathNodes);
                pathEdges.AddRange(firstPart.pathEdges);

                pathNodes.RemoveAt(pathNodes.Count - 1);

                ShortestPath secondPart = new ShortestPath(gps, (Node)stop, end);
                pathNodes.AddRange(secondPart.pathNodes);
                pathEdges.AddRange(secondPart.pathEdges);

                distance = firstPart.distance + secondPart.distance;
            }
            else
            {
                Edge eStop = (Edge)stop;

                double currentDistance = new ShortestPath(gps, start, eStop.Start()).distance + eStop.Distance + new ShortestPath(gps, eStop.End(), end).distance;
                double reverseDistance = Double.MaxValue;
                Node   eStart          = eStop.Start();
                Node   eEnd            = eStop.End();

                if (eStop.SingleDirection == false)
                {
                    reverseDistance = new ShortestPath(gps, start, eStop.End()).distance + eStop.Distance + new ShortestPath(gps, eStop.Start(), end).distance;
                }

                if (reverseDistance < currentDistance)
                {
                    Node tmp = eStart;
                    eStart = eEnd;
                    eEnd   = tmp;
                }

                ShortestPath firstPart = new ShortestPath(gps, start, eStart);
                pathNodes.AddRange(firstPart.pathNodes);
                pathEdges.AddRange(firstPart.pathEdges);

                pathEdges.Add(eStop);

                ShortestPath secondPart = new ShortestPath(gps, eEnd, end);
                pathNodes.AddRange(secondPart.pathNodes);
                pathEdges.AddRange(secondPart.pathEdges);

                distance = firstPart.distance + eStop.Distance + secondPart.distance;
            }
        }
示例#2
0
        private void button4_Click(object sender, EventArgs e)
        {
            userControl11.Hide();
            userControl31.Hide();

            GPSDatabase gpsDatabase = new GPSDatabase();
            Node        startNode   = gpsDatabase.FindNodeByName(userControl21.textBox1.Text);
            Node        endNode     = gpsDatabase.FindNodeByName(userControl21.textBox2.Text);

            if (startNode != null && endNode != null)
            {
                userControl21.Hide();
                button4.Hide();

                Graphics g = pictureBox1.CreateGraphics();

                userControl31.Show();

                userControl31.label1.Text = startNode.Name;
                userControl31.label2.Text = endNode.Name;

                GPSNavigation gps = new GPSNavigation();

                if (userControl21.isChecked == -1)
                {
                    path = new ShortestPath(gps, startNode, endNode);
                }
                else
                {
                    path = new ShortestPath(gps, startNode, endNode, (Characteristic.CharacteristicTypes)userControl21.isChecked);
                }

                pictureBox1.Refresh();
            }
            else
            {
                string errorMessage = "Navedene lokacije ne postoje na karti:\n";
                errorMessage += (startNode == null ? userControl21.textBox1.Text : "") + Environment.NewLine;

                errorMessage += (endNode == null ? userControl21.textBox2.Text : "");
                userControl21.Show();
                button4.Show();
                ErrorMsg notFoundForm = new ErrorMsg(errorMessage);
                notFoundForm.ShowDialog();
            }
        }
示例#3
0
        public void FindShortestPath(Characteristic.CharacteristicTypes type)
        {
            double minDistance = Double.MaxValue;

            stop = null;

            var typeNodes = gps.NodesByChType(type);

            foreach (Node n in typeNodes)
            {
                double currentDistance = new ShortestPath(gps, start, n).distance + new ShortestPath(gps, n, end).distance;

                if (currentDistance < minDistance)
                {
                    minDistance = currentDistance;
                    stop        = n;
                }
            }

            var typeEdges = gps.EdgesByChType(type);

            foreach (Edge e in typeEdges)
            {
                double currentDistance = new ShortestPath(gps, start, e.Start()).distance + e.Distance + new ShortestPath(gps, e.End(), end).distance;
                double reverseDistance = Double.MaxValue;

                if (e.SingleDirection == false)
                {
                    reverseDistance = new ShortestPath(gps, start, e.End()).distance + e.Distance + new ShortestPath(gps, e.Start(), end).distance;
                }

                if (currentDistance < minDistance || reverseDistance < minDistance)
                {
                    minDistance = Math.Min(currentDistance, reverseDistance);
                    stop        = e;
                }
            }
        }
示例#4
0
 private void button2_Click(object sender, EventArgs e)
 {
     path = null;
     pictureBox1.Refresh();
 }