def _modify_domain(f_domain, f_out, tr_outfiles): """Create a new domain file. Return the name of the new file.""" f_add_effects = tr_outfiles["add_effects"] f_del_effects = tr_outfiles["del_effects"] f_axioms = tr_outfiles["axioms"] # the domain domain = get_contents(f_domain) domain_tree = LispParser.get_tree(domain) # add and del effects add_effects_tree = LispParser.get_tree(get_contents(f_add_effects)) del_effects_tree = LispParser.get_tree(get_contents(f_del_effects)) TreeHanger.add_add_del_effects(domain_tree, add_effects_tree, del_effects_tree) # domain prefs axioms = get_contents(f_axioms) axiom_tree = LispParser.get_tree(axioms) TreeHanger.add_domain_prefs(domain_tree, axiom_tree) # write to the new domain file fp = open(f_out, "w") fp.write(domain_tree.to_lisp()) fp.close() return f_out
def _modify_problem(f_problem, f_out, tr_outfiles): """Modify the problem by writing it to a new file. Return the name of the new problem file.""" f_init_states = tr_outfiles["init_states"] f_axioms = tr_outfiles["axioms"] # the problem problem = get_contents(f_problem) problem_tree = LispParser.get_tree(problem) # the preferences init_states = get_contents(f_init_states) init_states_tree = LispParser.get_tree(init_states) TreeHanger.add_init_state_prefs(problem_tree, init_states_tree) # the axioms axioms = get_contents(f_axioms) axiom_tree = LispParser.get_tree(axioms) TreeHanger.add_metric_functions(problem_tree, axiom_tree) # write to the new problem file fp = open(f_out, "w") fp.write(problem_tree.to_lisp()) fp.close() return f_out
def _modify_problem(f_problem, f_out, tr_outfiles): '''Modify the problem by writing it to a new file. Return the name of the new problem file.''' f_init_states = tr_outfiles["init_states"] f_axioms = tr_outfiles["axioms"] # the problem problem = get_contents(f_problem) problem_tree = LispParser.get_tree(problem) # the preferences init_states = get_contents(f_init_states) init_states_tree = LispParser.get_tree(init_states) TreeHanger.add_init_state_prefs(problem_tree, init_states_tree) # the axioms axioms = get_contents(f_axioms) axiom_tree = LispParser.get_tree(axioms) TreeHanger.add_metric_functions(problem_tree, axiom_tree) # write to the new problem file fp = open(f_out, "w") fp.write(problem_tree.to_lisp()) fp.close() return f_out
def _modify_domain(f_domain, f_out, tr_outfiles): '''Create a new domain file. Return the name of the new file.''' f_add_effects= tr_outfiles["add_effects"] f_del_effects= tr_outfiles["del_effects"] f_axioms = tr_outfiles["axioms"] # the domain domain = get_contents(f_domain) domain_tree = LispParser.get_tree(domain) # add and del effects add_effects_tree = LispParser.get_tree(get_contents(f_add_effects)) del_effects_tree = LispParser.get_tree(get_contents(f_del_effects)) TreeHanger.add_add_del_effects(domain_tree, add_effects_tree, del_effects_tree) # domain prefs axioms = get_contents(f_axioms) axiom_tree = LispParser.get_tree(axioms) TreeHanger.add_domain_prefs(domain_tree, axiom_tree) # write to the new domain file fp = open(f_out, "w") fp.write(domain_tree.to_lisp()) fp.close() return f_out
def compare(f_baseline, f_generated): '''Compare the given generated file to the baseline file.''' baseline_tokens = LispParser().get_tokens(get_contents(f_baseline)) generated_tokens = LispParser().get_tokens(get_contents(f_generated)) i = j = 0 len_match = token_match = True if len(baseline_tokens) != len(generated_tokens): print "different amount of tokens" len_match = False while i < len(baseline_tokens) and j < len(generated_tokens): if baseline_tokens[i] != generated_tokens[j]: token_match = False print "==> difference" print "Context for baseline:" print " ".join(baseline_tokens[i - LispDiff.CONTEXT_WINDOW : i + LispDiff.CONTEXT_WINDOW]) print "Context for generated:" print " ".join(generated_tokens[j - LispDiff.CONTEXT_WINDOW : j + LispDiff.CONTEXT_WINDOW]) # here we need a way to try to line them up again for ii in range(-1 - LispDiff.ALIGN_WINDOW, 1 + LispDiff.ALIGN_WINDOW): if ii == 0: continue if baseline_tokens[i + ii : i + ii + LispDiff.MATCH_WINDOW + 1] == generated_tokens[j : j + LispDiff.MATCH_WINDOW + 1]: if ii > 0: print "===> roll forward %d chars" % ii else: print "===> roll back %d chars" % (-1 * ii) i += ii break i += 1 j += 1 if token_match and not len_match: print "Tokens all match even though lengths are different" print len(baseline_tokens) print len(generated_tokens) return len_match and token_match
def __init__(self): LispParser.__init__(self)