当前位置: 首页>>代码示例>>Python>>正文


Python State.print_state方法代码示例

本文整理汇总了Python中State.State.print_state方法的典型用法代码示例。如果您正苦于以下问题:Python State.print_state方法的具体用法?Python State.print_state怎么用?Python State.print_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在State.State的用法示例。


在下文中一共展示了State.print_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: depth_first

# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import print_state [as 别名]
def depth_first(file_name):
	tile_set = read_file(file_name) #list of tiles
	start_state = State([],tile_set) #State with no placed tiles
	root = Node(start_state, 0.0, None) #First Node, no cost, no parent
	frontier = [root] #list of nodes
	best_solution = State([],[]) #stores best solution
	best_cost = float("inf") #set to infinity
	nodes_generated = len(frontier)

	#runs while frontier is not empty
	while frontier:
		current_node = frontier.pop() #removes last node in frontier, stores in current_node
		
		#checks if current_node is a solution 
		#compares current_node to best_solution
		#stores new best solution
		if current_node.get_state().is_goal() and current_node.get_cost() < best_cost:
			best_cost = current_node.get_cost()
			best_solution = current_node.get_state()

		#creates child_nodes to search 
		#adds child_nodes to frontier
		child_nodes = current_node.expand()
		nodes_generated = len(child_nodes) + nodes_generated
		for c_n in child_nodes:
			frontier.append(c_n)

	#prints best solution to console
	print "HERE IS THE BEST"
	print best_cost
	print ""
	best_solution.print_state()
	print "Nodes Generated: " + str(nodes_generated)
开发者ID:Joel-Venzke,项目名称:Automated-nmr-assignment,代码行数:35,代码来源:search_project.py

示例2: uniform_cost

# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import print_state [as 别名]
def uniform_cost(file_name):
	tile_set = read_file(file_name) #list of tiles
	start_state = State([],tile_set) #State with no placed tiles
	root = Node(start_state, 0.0, None) #First Node, no cost, no parent
	frontier = [root] #list of nodes
	best_solution = State([],[]) #stores best solution
	best_cost = float("inf") #set to infinity
	nodes_generated = len(frontier)
	keep_running = True
	nodes_generated = len(frontier)

	#runs while frontier is not empty
	while keep_running:
		best_cost_index = None
		current_best_cost = float("inf")
		frontier_length = range(len(frontier))
		for f in frontier_length:
			if frontier[f].get_cost() < current_best_cost:
				best_cost_index = f
				current_best_cost = frontier[f].get_cost()
				
		current_node = frontier.pop(best_cost_index) #removes best_cost_index node in frontier, stores in current_node
		
		#checks if current_node is a solution 
		#compares current_node to best_solution
		#stores new best solution
		if current_node.get_state().is_goal() and current_node.get_cost() < best_cost:
			best_cost = current_node.get_cost()
			best_solution = current_node.get_state()

		#creates child_nodes to search 
		#adds child_nodes to frontier
		child_nodes = current_node.expand()
		nodes_generated = len(child_nodes) + nodes_generated
		for c_n in child_nodes:
			frontier.append(c_n)
			frontier_length = range(len(frontier))
			keep_running = False 
		for f in frontier_length:
			if keep_running == False and frontier[f].get_cost() < best_cost:
				keep_running = True
	#prints best solution to console
	print "HERE IS THE BEST"
	print best_cost
	print ""
	best_solution.print_state()
	print "Nodes Generated: " + str(nodes_generated)
开发者ID:Joel-Venzke,项目名称:Automated-nmr-assignment,代码行数:49,代码来源:search_project.py


注:本文中的State.State.print_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。