Exemple #1
0
        public static string[] DrawGrid(SquareGrid grid, AStarSearch astar, Location start, Location goal)
        {
            string[] output = new string[4];
            // Печать массива cameFrom
            for (int z = 0; z < 4; z++)
            {
                for (var y = 0; y < 41; y++)
                {
                    for (var x = 0; x < 41; x++)
                    {
                        Location id  = new Location(x, y, z);
                        Location ptr = id;
                        if (!astar.cameFrom.TryGetValue(id, out ptr))
                        {
                            ptr = id;
                        }
                        if (start.x == x && start.y == y && start.z == z) /*Console.Write("\u2191 ");*/ x {
                            ++; output[z] += "S";
                        }
                        if (goal.x == x && goal.y == y && goal.z == z) /*Console.Write("\u2191 ");*/ x {
                            ++; output[z] += "F";
                        }

                        if (grid.walls.Contains(id)) /*Console.Write("##");*/ output {
Exemple #2
0
        private void AstarButton_Click(object sender, EventArgs e)
        {
            //routing path = new routing();
            Graph search = new Graph();

            Location[] route = new Location[pointsCount];
            Graph[]    links = new Graph[pointsCount];

            if (comboBox1.Text == "")
            {
                MessageBox.Show("Please select drone");
                return;
            }

            if (comboBox1.Text == drones[2].name)
            {
                MessageBox.Show("Sorry.\nCalculated route is out of range of selected Drone\nPlease selsect different Drone and try again");
                return;
            }

            switch (pointsCount)
            {
            case 0:
                MessageBox.Show("Not enough checkpoints. Please add more points to the route");
                return;

            case 1:
                route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4);
                break;

            case 2:
                route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4);
                route[1] = search.findNode(linkLabel2.Text, map, 41, 41, 4);
                break;

            case 3:
                route[0] = search.findNode(linkLabel1.Text, map, 41, 41, 4);
                route[1] = search.findNode(linkLabel2.Text, map, 41, 41, 4);
                route[2] = search.findNode(linkLabel3.Text, map, 41, 41, 4);
                break;
            }

            int    selected;
            string unserviced = "Sorry, chosen addresses:\n";
            bool   unsrvcd    = false;

            for (int i = 0; i < pointsCount; i++)
            {
                if (route[i].x < 0)
                {
                    unserviced += points[i] + "\n";
                    unsrvcd     = true;
                }
            }
            if (unsrvcd)
            {
                unserviced += "are yet to be added to our coverage";
                MessageBox.Show(unserviced);
                return;
            }
            for (selected = 0; selected < 3; selected++)
            {
                if (comboBox1.Text == drones[selected].name)
                {
                    break;
                }
            }

            NewGrid(41, 41, 4, route);
            AStarSearch astar = new AStarSearch(grid, route[0], route[1]);

            ThePath = astar.ReconstructPath(route[0], route[1], astar.cameFrom);

            KML makefile = new KML();

            makefile.NewKML(ThePath, map);
        }