示例#1
0
def __parse_Win(*tuples):
    for mtuple in tuples:
        #'numStone=Y, take(P,X)' -> [numStone=Y, take(P,X)]
        formula = mtuple[2]
        name_list, feature_list, var_list = ____get_features_vars(mtuple[1])
        #print name_list, feature_list, var_list
        feature = ____generate_feature_pattern(feature_list, var_list)
        context_operator.set_axiom("win", feature, var_list, formula)
示例#2
0
def __parse_Poss(
    *tuples
):  #(('Poss', 'take(P,X)', ' num_stone>=X and (X=1 or X=2 or X=3)       and turn(P)    '),)
    #print tuples
    for mtuple in tuples:
        #'numStone=Y, take(P,X)' -> [numStone=Y, take(P,X)]
        formula = mtuple[2]
        #print '----',mtuple[1]
        name_list, feature_list, var_list = ____get_features_vars(mtuple[1])
        feature = ____generate_feature_pattern(feature_list, var_list)
        context_operator.add_actions(
            [name for name in name_list if name.strip() != "pi"])
        #print '-------',feature, name_list, feature_list, var_list
        context_operator.set_axiom("poss", feature, var_list, formula)
示例#3
0
def __parse_SSA(*tuples):
    #print tuples
    '''
	divide_pattern_str = r"(?P<fun>[\w]+)(?P<para>(?:\(.*?\))?)\s*(?:=\s*(?P<value>(?:"+var_pattern_str+"|"+const_pattern_str+")))?"# (?:" + const_pattern_str +"|"+ var_pattern_str+ "))?,"
	divide_pattern = re.compile(divide_pattern_str)
	for mtuple in tuples:
		match = re.match(divide_pattern,mtuple[2])
		print match
	'''
    #generate ssa[key]
    for mtuple in tuples:
        #'numStone=Y, take(P,X)' -> [numStone=Y, take(P,X)]

        formula = mtuple[2]
        '''
		for function in functions:
			if function.split('=')[0].find('(')==-1: # it's f = X or f or f = g(Y) where f is zero-para function
				matched = name_pattern.match(function)
				if matched.group():
					context_operator.add_zero_fluent(matched.group())     #add to const set()
					function = function.replace(matched.group(),matched.group()+"()",1) # change f -> f()
				else:
					print "#EOROR(__parse_SSA|Poss): name eror when parsing function: ",function
			fun_name, fun_para, fun_value = Util.parse_function(function)
			#get vars from para and values
			var_list+= [mvar.strip() for mvar in Util.get_paras_from_str(fun_para)+[fun_value] if isVar(mvar.strip()) ] 
			#generate feature
			feature_list.append(Util.generate_function_feature(function))
		'''
        #print var_list
        name_list, feature_list, var_list = ____get_features_vars(mtuple[1])
        #print name_list, feature_list, var_list
        feature_pattern = ____generate_feature_pattern(feature_list, var_list)
        actions = [
            name for e, name in enumerate(name_list)
            if e % 2 == 1 and name.strip() != "pi"
        ]
        fluents = [name for e, name in enumerate(name_list) if e % 2 == 0]
        context_operator.add_actions(actions)
        context_operator.add_fluents(fluents)

        #print feature
        context_operator.set_axiom("ssa", feature_pattern, var_list, formula)
示例#4
0
def __parse_Init(*tuples):
    #print tuples
    formulas = list()
    for mtuple in tuples:
        formulas.append(mtuple[2])
    context_operator.set_axiom("init", "", [], "&".join(formulas))
示例#5
0
def __parse_End(*tuples):
    #print tuples
    for mtuple in tuples:
        formula = mtuple[2]
        context_operator.set_axiom("end", "", [], formula)