Exemplo n.º 1
0
def __mrepl_detect_fluent(matched):
	#print "hello",matched.groups()
	if not __equality(matched.group('pos')) or matched.group('pre') in ['+','-','*','/','%']:
		fluent = matched.group('fun').replace(' ','').replace('[','(').replace(']',')') #decode
		#print 'fluent--', fluent
		if fluent not in context_operator.get_local_dict().keys():
			context_operator.get_local_dict()[fluent] = context_operator.get_new_var()
		#print "replace--",matched.group('pre')+' '+context_operator.get_local_dict()[fluent]+' '+matched.group('pos')
		return matched.group('pre')+' '+context_operator.get_local_dict()[fluent]+' '+matched.group('pos')
	else:
		return matched.group()
Exemplo n.º 2
0
def __mrepl_rename(match):
    #print "hello",match.group(0)
    old_var_list = match.group('var').split(',')
    old_var_list = [r'\b' + var + r'\b' for var in old_var_list]
    new_var_list = [
        context_operator.get_new_var() for e in range(0, len(old_var_list))
    ]
    #print zip(old_var_list,new_var_list)
    rename_str = repeat_do_function(sub_lambda_exp,
                                    zip(old_var_list, new_var_list),
                                    match.group(0))
    #print rename_str
    encoded_rename_str = endecode_string(rename_str, encode_pair_forall[0],
                                         encode_pair_forall[1])
    return encoded_rename_str
Exemplo n.º 3
0
def ____rename_rule_vars(rule_list, varlist_list):
    #rename free varable

    for e, rename_var_list in enumerate(varlist_list):
        #print "rename##########:", rename_var_list
        new_var_list = [
            context_operator.get_new_var() for i in rename_var_list
        ]
        #print "new_var#########",new_var_list
        rename_var_list = [r'\b' + elem + r'\b' for elem in rename_var_list]
        temp_rule = Util.repeat_do_function(
            Util.sub_lambda_exp, zip(rename_var_list, new_var_list),
            rule_list[e][1] + "#" + rule_list[e][2])
        #print "temp_rule ~~~~~~~~>:", temp_rule
        #print Util.rename_forall(temp_rule.split('&')[1])
        rule_list[e] = (rule_list[e][0], temp_rule.split('#')[0],
                        Util.rename_forall(temp_rule.split('#')[1]))
    return rule_list
Exemplo n.º 4
0
def __generate_pi_action(player):
    """
		generate a program denoting doing any possible action
	"""
    functions_sorts = context_operator.get_functions_sorts()
    sort_consts_dict = context_operator.get_sort_symbols_dict()
    p_sort = [
        sort for sort, consts in sort_consts_dict.iteritems()
        if player in consts
    ].pop()

    actions_sorts_vars = [ (fun, sorts[0:len(sorts)-1] , \
    [ context_operator.get_new_var() if s!=p_sort else player for s in sorts[0:len(sorts)-1]] ) \
    for fun, sorts in functions_sorts.iteritems() if fun in context_operator.get_actions() ]

    action_list = [ "pi(%s)[%s(%s)]"%(','.join(["%s:%s"%(v,s) for (v,s) in zip(v_list,s_list) if s!=p_sort]) \
     , action, ','.join(v_list)) for (action, s_list, v_list) in actions_sorts_vars]

    return '#'.join(action_list)
Exemplo n.º 5
0
def __get_vars(sorts):
	return [ (context_operator.get_new_var(), sort) for sort in sorts]