本文整理匯總了Python中Problem.Problem.write_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Problem.write_file方法的具體用法?Python Problem.write_file怎麽用?Python Problem.write_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Problem.Problem
的用法示例。
在下文中一共展示了Problem.write_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from Problem import Problem [as 別名]
# 或者: from Problem.Problem import write_file [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)