本文整理汇总了Python中Problem.Problem.generate_terrain方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.generate_terrain方法的具体用法?Python Problem.generate_terrain怎么用?Python Problem.generate_terrain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Problem.Problem
的用法示例。
在下文中一共展示了Problem.generate_terrain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Problem import Problem [as 别名]
# 或者: from Problem.Problem import generate_terrain [as 别名]
def main():
"""
Main method, where the magic is done. This method creates and initializes the original state.
Then, applying the selected search algorithm, it calculates and it writes the correct solution.
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--algorithm', required=True, type=str, default='DFS',
help='Set the search algorithm desired.')
parser.add_argument('-d', '--depth', default=9, type=int,
help='Set the maximum depth.')
parser.add_argument('-i', '--increase', default=1, type=int,
help='Set the increase in each iteration.')
parser.add_argument('-r', '--random', default=False, type=bool,
help='Initial state configuration is randomly generated.')
parser.add_argument('-f', '--file', default='../terrain.txt', type=str,
help='Route to load your initial state configuration.')
parser.add_argument('-o', '--output', default='successors.txt', type=str,
help='File to write the solution.')
args = parser.parse_args()
terrain = State(0, 0, 0, 0, 0, 0, 0) # Initial state. Initialized at 0.
operations = Problem(0, 0, args.file, terrain)
if args.random: # Generate the terrain randomly
operations.generate_terrain(terrain)
else:
if operations.file_format_correct():
operations.read_file(terrain)
else:
print("File {} has not a valid format.".format(args.file))
exit(1)
# Search algorithm to calculate the solution
sol = Search_Algorithm().search(operations, args.algorithm, args.depth, args.increase)
if sol is None:
print('No se ha encontrado una solución')
else:
operations.write_file(sol, args.output)