예제 #1
0
        //输出迷宫

        private void PrintMaze(int[,] Maze)//收尾工作

        {
            PositionForAll pfa = new PositionForAll();

            Console.WriteLine("传出时point_flag为:" + point_flag + "--" + Walk_point[point_flag].x + ", " + Walk_point[point_flag].y);
            pfa.Add_position_forAll(Walk_point, point_flag);

            Console.WriteLine("========================================================");

            for (int i = 0; i < row; i++)

            {
                for (int j = 0; j < column; j++)

                {
                    Console.Write("" + Maze[i, j]);
                }
                Console.WriteLine("");
            }

            Console.WriteLine("========================================================");



            try
            {
                string str      = null;
                string filename = "" + StartPos.x + "p" + StartPos.y + "_" + EndPosition.x + "p" + EndPosition.y + ".txt";
                //int[,] other_map = null;

                /*if (flag == 0)
                 *  filename = "地图01.txt";
                 * else
                 *  filename = "解出地图.txt";
                 * Loading_map loadfile = new Loading_map(filename);
                 * loadfile.Loading();
                 * other_map = loadfile.get_map();*/
                /*using (StreamWriter file = new StreamWriter(filename))
                 * {
                 *  for(int i = 0; i < row; i++)
                 *  {
                 *      for(int j = 0; j < column; j++)
                 *      {
                 *          //if(Maze[i, j]==3&&other_map[i, j]==0)
                 *              str += Maze[i, j];
                 *          //else
                 *          //    str += other_map[i, j];
                 *      }
                 *      file.WriteLine(str);
                 *      str = null;
                 *  }
                 *  file.Close();
                 * }*/
            }
            catch (Exception e)
            {
                MessageBox.Show("解出图输出失败:\n" + e);
            }
        }
예제 #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();
        }