本文整理汇总了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
#.........这里部分代码省略.........