Exemple #1
0
        private void Button_Click_Play(object sender, RoutedEventArgs e)
        {
            MazeShortPath shortpath = new MazeShortPath();

            for (int i = 1; i < bestx.Length; i++)
            {
                if (i + 1 == bestx.Length)
                {
                    return;
                }
                else
                {
                    shortpath.Path_Load(mr, mc, path[bestx[i] - 1], path[bestx[i + 1] - 1]);
                    Position[] position_array = shortpath.get_WalkPoint();
                    int        n = shortpath.get_PointFlag();
                    Console.WriteLine("到类时:n=" + n + "值为:");
                    for (int j = 0; j < n + 1; j++)
                    {
                        Console.Write("(" + position_array[j].x + "," + position_array[j].y + ")");
                        Button     c_btn        = grid.FindName("Button" + position_array[j].x + "_" + position_array[j].y) as Button;
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"roadp.jpg", UriKind.Relative)
                                );
                        c_btn.Background = berriesBrush;
                    }
                }
            }
        }
Exemple #2
0
        public void Setpath(Position[] point, int p_num, int[,] a_map_1, int r, int c)
        {
            n          = p_num;
            City_Graph = new int[n + 1, n + 1];
            x          = new int[n + 1];
            isIn       = new int[n + 1];
            bestx      = new int[n + 1];
            MazeShortPath shortpath = new MazeShortPath();

            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n; j++)
                {
                    City_Graph[i, j] = NO_PATH;
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i != j)
                    {
                        Console.WriteLine(i + "-" + j);
                        City_Graph[i + 1, j + 1] = shortpath.Path_Load(r, c, point[i], point[j]);
                        Console.WriteLine("起-" + point[i].x + "," + point[i].y + "终-" + point[j].x + "," + point[j].y);
                    }
                }
            }
            for (int i = 1; i <= n; i++)
            {
                x[i]     = 0;           //表示第i步还没有解
                bestx[i] = 0;           //还没有最优解
                isIn[i]  = 0;           //表示第i个城市还没有加入到路径中
            }
            x[1]    = 1;                //第一步 走城市1
            isIn[1] = 1;                //第一个城市 加入路径
            bestw   = MAX_WEIGHT;
            cw      = 0;
            Travel_Backtrack(2);        //从第二步开始选择城市
            Console.WriteLine("最优值为" + bestw + "零阶矩阵:");
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n; j++)
                {
                    Console.Write(City_Graph[i, j] + " ");
                }
                Console.WriteLine("");
            }
            Console.WriteLine("最优解为:");
            for (int i = 1; i <= n; i++)
            {
                Console.Write(bestx[i] + ">>");
            }
            Console.WriteLine("");

            PositionForAll pfa = new PositionForAll();
            //Console.WriteLine("" + pfa.get_Start(1).x + "," + pfa.get_Start(1).y);
            //Console.WriteLine("" + pfa.get_End(1).x + "," + pfa.get_End(1).y);
            //pfa.show_Array();
        }