當前位置: 首頁>>代碼示例>>Python>>正文


Python Action.to_concrete_string方法代碼示例

本文整理匯總了Python中Action.Action.to_concrete_string方法的典型用法代碼示例。如果您正苦於以下問題:Python Action.to_concrete_string方法的具體用法?Python Action.to_concrete_string怎麽用?Python Action.to_concrete_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Action.Action的用法示例。


在下文中一共展示了Action.to_concrete_string方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Schema

# 需要導入模塊: from Action import Action [as 別名]
# 或者: from Action.Action import to_concrete_string [as 別名]
class Schema(GObject.Object):
	#__metaclass__ = ABCMeta

	def __init__(self, mem):
		self.mem = mem
		self.preconditions = WorldState()
		self.postconditions =  WorldState()
		self.associated_observations = WorldState()
		self.associated_preconditions = WorldState()
		self.disappeared_observations = WorldState()
		self.action = Action()
		self.id  = -1
		self.generalised = False
		self.successes = 0.0
		self.excitation = 0.0
		self.activations = 0.0
		self.parent_schemas = []
		self.child_schemas = []
		self.added_ID = 0
		self.execution_ID = []
		self.failed_schemas = []


	def __lt__(self, other):
		return self.excitation < other.excitation

	def add_precondition(self, precondition):
		"""Add given observation to the Precondition"""
		self.preconditions.add_observation(precondition)

	def add_postcondition(self, postcondition):
		"""Add given observation to the Postcondition"""
		self.postconditions.add_observation(postcondition)

	def add_associated_observation(self, o):
		"""Add given observation to the associated"""
		self.associated_observations.add_observation(o)

	def add_disappeared_observation(self, o):
		"""Add given observation to the associated"""
		self.disappeared_observations.add_observation(o)

	def add_associated_preconditions(self, o):
		"""Add given observation to the associated"""
		self.associated_preconditions.add_observation(o)

	def add_failed_schema(self, s2):
		if not self.generalised:
			return
		for s in self.failed_schemas:
			if s2.equals(s):
				return
		self.failed_schemas.append(s2)

	def execute(self):
		"""Execute the schema and increment activations"""
		self.execution_ID.append(int(self.mem.total_executions))
		if (self.action != None):
			print "Executing schema action with execution ID %s Excitation = %0.4f  @execute/Schema:"%(str(self.execution_ID), self.excitation), self.action.to_concrete_string(),"\n"
			self.action.execute(); self.activations +=1; print "@Schema/execute ID: %i ,Activations: %f, Successes: %f"%(self.id, self.activations, self.successes), self.added_ID, self.execution_ID
			return 1
		else:
			self.mem.achieve_goal2(self.postconditions, [self.id], self.disappeared_observations, False)
			self.activations +=1
			return 2

	def is_post_pre(self):
		"""Retrun True if Posts and Pres are equal"""
		return self.precondition.equal(self.postcondition)


	def equals(self, so2):
		"""Returns true if two schemas are equal"""
		if (self.generalised):
			self.set_vars_from_state(so2.preconditions)
		return self.preconditions.equals(so2.preconditions) and self.associated_preconditions.equals(so2.associated_preconditions) and ( (self.action == None and so2.action == None) or (self.action != None and so2.action != None and self.action.equals(so2.action)) ) and self.postconditions.equals(so2.postconditions) and self.associated_observations.equals(so2.associated_observations) and self.disappeared_observations.equals(so2.disappeared_observations)

	def satisfies(self, pre2, a2, post2, ignore=False):
		"""Returns true is second schema is subset of first schema"""
		if (self.generalised):
			self.set_vars_from_state(pre2)
			s_post = self.postconditions.copy(); self.mem.remove_ignored_preconditions(s_post)
			c_post2 = post2.copy(); self.mem.remove_ignored_preconditions(c_post2)
			return self.preconditions.satisfies(pre2, ignore) and s_post.satisfies(c_post2)
		return self.preconditions.satisfies(pre2, ignore) and (a2 == None or (self.action != None and self.action.equals(a2))) and self.postconditions.satisfies(post2, ignore)

	def get_similarity(self, s2):
		"""Retruns similarity between two schemas
		Similarity is scalled to 1.00"""
		pre = WorldState()
		pre = s2.preconditions.copy()
		#print "@schema simi Matching with: ", s2.id,"\n",pre.to_string()
		if self.generalised:
			self.set_vars_from_state(pre)
		Total_similarity = 0.0
		similarity = self.preconditions.get_similarity(s2.preconditions)
		Total_similarity += similarity
		similarity = self.postconditions.get_similarity(s2.postconditions)
		Total_similarity += similarity
		return Total_similarity/2
#.........這裏部分代碼省略.........
開發者ID:kumar54,項目名稱:Dev-PSchema,代碼行數:103,代碼來源:Schema.py


注:本文中的Action.Action.to_concrete_string方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。