Beispiel #1
0
def poss_or_ssa(action_str, fluent=None):
	#print("aaaaa",action_str)
	'''
	#take(1,X,fun(1,2)) -> take   1,X,fun(1,2)
	action_name, action_args_str, nothing= parse_function(action_str)
	#print action_name, action_args_str
	# 1,X,fun(1,2) ->  1,X,fun[1_2] -> ['1', 'X', 'fun[1_2]'] -> ['1', 'X', 'fun[1_2]'] -> ['1','X','fun(1,2)']
	para_list = get_paras_from_str(action_args_str)
	#['1','X','fun(1,2)'] -> take_1_X_fun(1,2)
	action_feature = action_name + '_' + '_'.join(para_list)
	action_feature = re.sub(r'\s+', '', action_feature)
	print action_feature
	'''
	#print 'action_str,fluent', action_str, fluent
	axiom_name = "poss"
	feature =  Util.generate_function_feature(action_str)
	#take_1_X_fun(1,2) -> function to handle this function, parameters ['X', 'fun(1,2)']
	#print('feature', feature)
	#print('fluent', fluent)
	if fluent:
		feature = Util.generate_function_feature(fluent)+'_'+feature
		axiom_name = "ssa"

	lambda_function, para_selected_list= context_operator.find_axiom_with_feature(axiom_name, feature)
	#print '----', lambda_function, para_selected_list
	formula = lambda_function if  isinstance(lambda_function, str) else lambda_function(para_selected_list)

	return formula
Beispiel #2
0
def __model_ssa(fluent, action_str, model):

	feature = Util.generate_function_feature(fluent)+'_'+Util.generate_function_feature(action_str)
	lambda_function, para_selected_list= context_operator.find_axiom_with_feature("ssa", feature)
	#print '----', lambda_function, para_selected_list
	formula = lambda_function if  isinstance(lambda_function, str) else lambda_function(para_selected_list)

	#print 'ffff', formula
	return model_checker.sat_formula(model, formula)#eval(__replace_model(ground_formula, model))
Beispiel #3
0
def poss(action_str, model):

	feature =  Util.generate_function_feature(action_str)
	lambda_function, para_selected_list= context_operator.find_axiom_with_feature('poss', feature)
	#print '----', lambda_function, para_selected_list
	formula = lambda_function if  isinstance(lambda_function, str) else lambda_function(para_selected_list)

	return model_checker.sat_formula(model, formula)
Beispiel #4
0
def ____get_features_vars(m_str):
    #print '1111',m_str
    feature_list = list()
    var_list = list()
    names_list = list()
    functions = Util.get_paras_from_str(m_str)
    for function in functions:
        fun_name, fun_para, fun_value = Util.parse_relation_or_function(
            function)
        var_list += [
            mvar for mvar in Util.get_paras_from_str(fun_para) + [fun_value]
            if Util.isVar(mvar)
        ]
        feature_list.append(Util.generate_function_feature(function))
        names_list.append(fun_name)
    return names_list, feature_list, var_list
Beispiel #5
0
def get_goal(player):
	lambda_fun, para_list = context_operator.find_axiom_with_feature('win', Util.generate_function_feature(player+'()'))
	Win = lambda_fun(para_list)
	End = context_operator.get_axioms()['end']['']
	return "( %s ) => ( %s )"%(End, Win)