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


Python State.balance_bank方法代码示例

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


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

示例1: modifyPlan

# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import balance_bank [as 别名]
	def modifyPlan(self, initState, goalState, currentCase):
		# initState - our init state
		# goalState - our goal state
		# currentCase - retrieved case from the retriever
		
		
		
		# We have two different strategy for modification
		# 1. We will try to replace the retrieved init / goal state with our init / goal state
		# and will test whether the adapted plan really works or not. If works return this plan.
		# 2. If strategy #1 fails, we will try to fill up the missing part at the beginning of the plan
		# and at the end of the plan
		
		
		# Mark the flag as True
		successFlag = True
		if len(currentCase) == 0:
			# No previous plan found
			# Call pyhop to get plan from scratch
			print "Calling pyhop to get plan from scratch"			
			modifiedPlan = find_plan(initState, goalState)
		else:
			# We will try to modify the plan
			
			# Initiate current init state and goal state
			currentInitState = State("currentInitState")
			currentGoalState = State("currentGoalState")			
			for stateItem in currentCase[0][0]:						
				exec("currentInitState."+stateItem)							
			for stateItem in currentCase[0][1]:						
				exec("currentGoalState."+stateItem)
				
			# Copying random bus stop to loc[bus] to avoid KeyError
			currentGoalState.loc['bus'] = 'bus_stop_1'
			
			fo = self.__openFile('static_value.txt')	
			exec('content=' + fo.read())
			for stateItem in content:				
				exec("currentInitState."+stateItem)
				exec("currentGoalState."+stateItem)
			
			currentGoalState.time = {}
			currentGoalState.nearest_bus_stop = {}
			currentGoalState.balance_bank = {}
			currentGoalState.time[currentGoalState.target] = \
				currentInitState.time[currentGoalState.target]
			currentGoalState.nearest_bus_stop[currentGoalState.target] = 'bus_stop_1'
			currentGoalState.balance_bank[currentGoalState.target] = \
				initState.balance_bank[initState.target]
			
			currentPlan = currentCase[1]
			
			# Try to adapt the retrieve plan to the current plan
			modifiedPlan, isComplete = self.__adaptToCurrentPlan(initState, goalState, \
								currentInitState, currentGoalState, currentPlan)
			if isComplete == True:
				# Modification completed
				return modifiedPlan, successFlag
			else:
				# Continue with the returned plan, it could be partially adapted
				currentPlan = deepcopy(modifiedPlan)
			
			# At this point, the adaptation strategy didn't work out correctly
			# we will try to apply our second strategy
			
			
			# cost for current plan
			costOfCurrentPlan = self.__costForPlan(currentPlan)
			
			currentGoalState.cash[currentGoalState.target] = \
				initState.cash[initState.target]-costOfCurrentPlan
			
			modifiedPlan = deepcopy(currentPlan)
			
			if self.__isSimilar(initState, currentInitState) == False:
				# Need to fillup the missing travel at the beginning
				#print "Calling pyhop to get plan for the beginning part"	
				
				newPlan = find_plan(initState, currentInitState)				
				
				if newPlan != False:
					# Got a plan, append it at the beginning
					print newPlan
					print
					newPlan.extend(modifiedPlan)
					modifiedPlan = []
					modifiedPlan = deepcopy(newPlan)
				else:
					print 'Could not find a suitable plan for the beginning part'
					print
					successFlag = False
				
			if self.__isSimilar(goalState, currentGoalState) == False:
				# Need to fillup the missing travel at the end part
				
				#print "Calling pyhop to get plan for the ending part"					
				
				newPlan = find_plan(currentGoalState, goalState)
				
				if newPlan != False:
#.........这里部分代码省略.........
开发者ID:ishtiakzaman,项目名称:KnowledgeBasedTravelPlan,代码行数:103,代码来源:modifier.py

示例2: openFile

# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import balance_bank [as 别名]
	# Open the predefined problem domain related info file here
	fo = openFile('static_value.txt')	
	exec('content=' + fo.read())
	
	# Create the Retriever module, given case based memory file and 
	# problem domain related info file 
	rt = Retriever('generated_plan.txt', 'state_similarity.txt')
	
	# Create a current state and goal state to test our program
	
	# Create the current state here
	currentState = State('current')
	currentState.target = 'me'
	currentState.loc = {'me':'IU Campus', 'bus':'bus_stop_2'}
	currentState.cash = {'me':3050}	
	currentState.balance_bank = {'me':120}
	currentState.time = {'me':1820}
	currentState.nearest_bus_stop={'me': 'bus_stop_2'}
	# Put the domain related info into the state
	for stateItem in content:				
		exec("currentState."+stateItem)
	
	# Create the goal state here
	goalState = State('goal')
	goalState.loc = {'me':'Paris'}
	goalState.cash = {'me':170}
	goalState.target = 'me'
	# Put the domain related info into the state
	for stateItem in content:		
		exec("goalState."+stateItem)
		
开发者ID:ishtiakzaman,项目名称:KnowledgeBasedTravelPlan,代码行数:32,代码来源:client.py


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