Ejemplo n.º 1
0
 def find_children(self):
     remaining = self.string
     result = []
     child, new_start = Utils.find_child(remaining)
     while new_start >= 0:
         remaining = remaining[new_start:]
         result.append(child)
         child, new_start = Utils.find_child(remaining) #TODO: Fix bug where "and" is turning into "(an)"
     return result
Ejemplo n.º 2
0
def get_compiled_pddl_from_filenames(dom_filename, prob_filename):
    dom_string = Utils.get_trimmed_string_from_file(dom_filename)
    dom_child, _ = Utils.find_child(dom_string)

    prob_string = Utils.get_trimmed_string_from_file(prob_filename)
    problem_child, _ = Utils.find_child(prob_string)

    prob = Problem.Problem(problem_child)
    dom = Domain.Domain(dom_child)

    bcp = BeliefCompiledProblem(dom, prob)
    comp_dom = bcp.compiled_domain.to_pddl()
    comp_prob = bcp.compiled_problem.to_pddl()

    return comp_dom, comp_prob
Ejemplo n.º 3
0
 def __init__(self, raw_string):
     if raw_string is not None:
         super().__init__(raw_string)
         for child in self.children:
             tokens = re.split(r'\s', child)
             identifier = tokens[0]
             if identifier == "problem":
                 self.name = tokens[1]
             elif identifier == ":domain":
                 self.dom_name = tokens[1]
             elif identifier == ":objects":
                 self.objects = child
             elif identifier == ":init":
                 self.init_state = [
                     fluenttree.FluentTree(c)
                     for c in PDDLPart.PDDLPart(child).children
                 ]
             elif identifier == ":goal":
                 self.goal = fluenttree.FluentTree(
                     Utils.find_child(child)[0])
     else:
         super().__init__('')
         self.name = ''
         self.dom_name = ''
         self.objects = ''
         self.init_state = []
         self.goal = None
Ejemplo n.º 4
0
 def __init__(self, dom_string):
     if dom_string is not None:
         super().__init__(dom_string)
         self.prelude = ""
         self.actions = []
         for child in self.children:
             tokens = re.split(r'\s', child)
             identifier = tokens[0]
             if identifier == 'domain':
                 self.name = tokens[1]
             elif identifier == ':requirements':
                 self.requirements = Utils.get_colon_sections(child)[1:]
             elif identifier == ':types':
                 self.type_string = child.replace(":types", "")
             elif identifier == ':predicates':
                 # self.predicates = PDDLPart.PDDLPart(child).children  # TODO: Map these to their own objects eventually?
                 self.predicates = [
                     fluenttree.AbstractPredicate(ch)
                     for ch in PDDLPart.PDDLPart(child).children
                 ]
             elif identifier == ':action':
                 self.actions.append(Operator.Operator(child))
         self.summary = self.name + "\nPredicates: " + str(
             len(self.predicates)) + "\nActions: " + str(len(self.actions))
     else:  # Blank domain for writing into
         super().__init__("")
         self.actions = []
         self.name = "EMPTY-DOMAIN"
         self.requirements = []
         self.type_string = ""
         self.predicates = []
         self.summary = self.name + "\nPredicates: " + str(
             len(self.predicates)) + "\nActions: " + str(len(self.actions))
         self.prelude = ""
Ejemplo n.º 5
0
def decompile(plan_str, original_domain_file):
    steps = get_steps(plan_str)
    dom_string = Utils.get_trimmed_string_from_file(original_domain_file)
    dom_child, _ = Utils.find_child(dom_string)
    orig_dom = Domain(dom_child)
    orig_actions = orig_dom.actions
    action_names = [x.name for x in orig_actions]
    decompiled_plan = []
    for step in steps:
        if ":untaken" in step:
            continue
        trimmed_name = step[:max(step.find("_success"), step.find("_fail"))]
        trimmed_params = 2
        int_str = trimmed_name + str(trimmed_params)
        decompiled_plan.append(trimmed_name)
        # if trimmed_name in action_names:
        #     decompiled_plan.append(int_str)
        # else:
        #     pass

    return str(decompiled_plan)
Ejemplo n.º 6
0
    def __init__(self, to_parse):
        if to_parse is not None:

            super().__init__(to_parse)
            self.base_string = to_parse
            self.name = re.split(r'\s', self.base_string)[1]
            tokens = Utils.get_colon_sections(self.base_string)
            self.agents = []
            self.parameters = []
            self.precondition = None
            self.effect = None
            self.fail = None
            for token in tokens:
                title = token.split()[0]
                if title == ":action":
                    self.name = token.split()[1]
                    # self.name = fluenttree.first_word(token)
                elif title == ":parameters":
                    # self.parameters = Parameter.parameter_list(Utils.find_child(token)[0])
                    self.parameters = fluenttree.AbstractPredicate(
                        "X " + Utils.find_child(token)[0])
                    self.parameters.identifier = ""
                elif title == ":precondition":
                    self.precondition = fluenttree.FluentTree(
                        Utils.find_child(token)[0])
                elif title == ":effect":
                    self.effect = fluenttree.FluentTree(
                        Utils.find_child(token)[0])
                elif title == ":fail":
                    self.fail = fluenttree.FluentTree(
                        Utils.find_child(token)[0])
                elif title == ":agents":
                    self.agents = Utils.get_question_mark_sections(
                        Utils.find_child(token)[0])
        else:
            super().__init__("")
            self.base_string = "blank"
            self.name = "blank"
            self.agents = []
            self.parameters = fluenttree.AbstractPredicate("")
            self.precondition = None
            self.effect = None
            self.fail = None
Ejemplo n.º 7
0
if __name__ == '__main__':
    args = argparse.ArgumentParser(description='Process Domain and Problem Files.')
    args.add_argument('-d','--domain', type=str, help='The Domain File', default=r'../samples/aladdin-domain.pddl')
    args.add_argument('-p','--problem', type=str, help='The Problem File', default=r'../samples/aladdin-problem.pddl')
    arguments = args.parse_args()

    domain_string = ''
    prob_string = ''
    with open(arguments.domain) as domF:
        for line in domF:
            trimmed = line[:line.find(';')].strip()
            if trimmed:
                domain_string += trimmed + '\n'
    verify_parens(domain_string)
    child, _ = Utils.find_child(domain_string)
    # print(child)

    with open(arguments.problem) as probF:
        for line in probF:
            trimmed = line[:line.find(';')].strip()
            if trimmed:
                prob_string += trimmed + '\n'

    verify_parens(prob_string)
    problem_child, _ = Utils.find_child(prob_string)

    prob = Problem.Problem(problem_child)
    dom = Domain.Domain(child)

    # print(dom.string)
Ejemplo n.º 8
0
    prob_string = Utils.get_trimmed_string_from_file(prob_filename)
    problem_child, _ = Utils.find_child(prob_string)

    prob = Problem.Problem(problem_child)
    dom = Domain.Domain(dom_child)

    bcp = BeliefCompiledProblem(dom, prob)
    comp_dom = bcp.compiled_domain.to_pddl()
    comp_prob = bcp.compiled_problem.to_pddl()

    return comp_dom, comp_prob


if __name__ == '__main__':

    dom_string = Utils.get_trimmed_string_from_file(
        r'../samples/rooms-domain.pddl')
    dom_child, _ = Utils.find_child(dom_string)

    prob_string = Utils.get_trimmed_string_from_file(
        r'../samples/rooms-problem.pddl')
    problem_child, _ = Utils.find_child(prob_string)

    prob = Problem.Problem(problem_child)
    dom = Domain.Domain(dom_child)

    bcp = BeliefCompiledProblem(dom, prob)
    comp_dom = bcp.compiled_domain.to_pddl()
    comp_prob = bcp.compiled_problem.to_pddl()
    # comp_prob = bcp.compiled_problem.to_pddl()
    print(comp_dom)
    # Utils.send_to_file(r'../samples/compiled/rooms-domain_bompiled.pddl', comp_dom)