コード例 #1
0
	def __init__(self, time, init_fact):
		self.time = time
		self.fact = init_fact # nested list
		if self.fact[0] == 'not':
			self.type = 'NEGATED_BOOLEAN'
			self.value = False
			self.predicate = tuple(self.fact[1])
			self.atom = conditions.Atom(self.fact[1][0], [conditions.parse_term(term) for term in self.fact[1][1:]])
		elif self.fact[0] == '=':
			if f_expression.isFloat(self.fact[2]):
				self.type = 'NUMERICAL_FUNCTION'
				self.value = float(self.fact[2])
				self.predicate = tuple(self.fact[1])
				self.atom = f_expression.parse_assignment(fact)
			else:
				self.type = 'OBJECT_FUNCTION'
				self.value = self.fact[2]
				self.predicate = tuple(self.fact[1])
				function = conditions.parse_term(self.fact[1])
				terms = function.args
				terms.append(conditions.parse_term(self.fact[2]))
				atomname = conditions.function_predicate_name(function.name)
				self.atom = conditions.Atom(atomname, terms)
		else:
			self.type = 'BOOLEAN'
			self.value = True
			self.atom = conditions.Atom(self.fact[0], [conditions.parse_term(term) for term in self.fact[1:]])
			self.predicate = tuple(self.fact)
コード例 #2
0
ファイル: tasks.py プロジェクト: aldukeman/lmtd
  def parse(domain_pddl, task_pddl):
    domain_name, requirements, constants, predicates, types, functions, actions, durative_actions, axioms \
                 = parse_domain(domain_pddl)
    task_name, task_domain_name, objects, init, goal = parse_task(task_pddl)

    assert domain_name == task_domain_name
    objects = constants + objects
    init += [conditions.Atom("=", (conditions.parse_term(obj.name), conditions.parse_term(obj.name))) 
             for obj in objects]
    return Task(domain_name, task_name, requirements, types, objects,
                predicates, init, goal, actions, durative_actions, axioms, Task.FUNCTION_SYMBOLS)
コード例 #3
0
  def parse(domain_pddl, task_pddl):
    domain_name, requirements, constants, predicates, types, functions, actions, durative_actions, axioms \
                 = parse_domain(domain_pddl)
    task_name, task_domain_name, objects, init, goal, metric = parse_task(task_pddl)

    assert domain_name == task_domain_name
    objects = constants + objects
    init += [conditions.Atom("=", (conditions.parse_term(obj.name), conditions.parse_term(obj.name)))
             for obj in objects]
    return Task(domain_name, task_name, requirements, types, objects,
                predicates, init, goal, metric, actions, durative_actions, axioms, Task.FUNCTION_SYMBOLS)
コード例 #4
0
def parse_task(task_pddl):
    iterator = iter(task_pddl)

    assert iterator.next() == "define"
    problem_line = iterator.next()
    assert problem_line[0] == "problem" and len(problem_line) == 2
    yield problem_line[1]
    domain_line = iterator.next()
    assert domain_line[0] == ":domain" and len(domain_line) == 2
    yield domain_line[1]

    objects_opt = iterator.next()
    if objects_opt[0] == ":objects":
        yield pddl_types.parse_typed_list(objects_opt[1:])
        init = iterator.next()
    else:
        yield []
        init = objects_opt

    assert init[0] == ":init"
    initial = []
    for fact in init[1:]:
        if fact[0] == "=":
            if conditions.is_function_comparison(fact):  # numeric function
                initial.append(f_expression.parse_assignment(fact))
            else:  # object function
                function = conditions.parse_term(fact[1])
                terms = function.args
                terms.append(conditions.parse_term(fact[2]))
                atomname = conditions.function_predicate_name(function.name)
                initial.append(conditions.Atom(atomname, terms))
        else:
            initial.append(
                conditions.Atom(
                    fact[0],
                    [conditions.parse_term(term) for term in fact[1:]]))
    yield initial

    goal = iterator.next()
    assert goal[0] == ":goal" and len(goal) == 2
    yield conditions.parse_condition(goal[1])

    metric_defined = False
    for entry in iterator:
        if entry[0] == ":metric":
            metric_defined = True
            #        if entry[2][0] in ["total-time", "total-cost"] :
            metric = (entry[1], entry[2])

            yield metric
    if not metric_defined:
        metric = ()
        yield metric
コード例 #5
0
def parse_init_fact(fact):
    if fact[0] == "=":
        if conditions.is_function_comparison(fact): # numeric function
            return f_expression.parse_assignment(fact)
        else: # object function
            function = conditions.parse_term(fact[1])
            terms = function.args
            terms.append(conditions.parse_term(fact[2]))
            atomname = conditions.function_predicate_name(function.name)
            return conditions.Atom(atomname, terms)
    else:
        return conditions.Atom(fact[0], [conditions.parse_term(term) for term in fact[1:]])
コード例 #6
0
  def parse(domain_pddl, task_pddl):
    domain_name, requirements, oplinit, constants, predicates, types, functions, actions, durative_actions, axioms, modules, subplan_generators \
                 = parse_domain(domain_pddl)
    task_name, task_domain_name, module_inits, module_exits, objects, init, timed_init, goal = parse_task(task_pddl)

    assert domain_name == task_domain_name
    objects = constants + objects

    if timed_init:
      timed_initials.compile_away(predicates, durative_actions, init, goal, timed_init)

    init += [conditions.Atom("=", (conditions.parse_term(obj.name), conditions.parse_term(obj.name))) 
             for obj in objects]
    return Task(domain_name, task_name, requirements, oplinit, types, objects, modules,
                predicates, init, goal, actions, durative_actions, axioms, Task.FUNCTION_SYMBOLS, subplan_generators, module_inits, module_exits)
コード例 #7
0
def parse_expression(exp, durative=False):
    if isinstance(exp, list):
        alist = exp
        operator_or_functionsymbol = alist[0]
        if operator_or_functionsymbol in ("+","/","*","-"):
            args = [parse_expression(arg,durative) for arg in alist[1:]]
            operator = operator_or_functionsymbol
        elif operator_or_functionsymbol == "?duration":
            return DurationVariable()
        else:
            return PrimitiveNumericExpression(operator_or_functionsymbol,
                                              [conditions.parse_term(arg) for arg in alist[1:]])
        if operator == "+":
            return Sum(args)
        elif operator == "/":
            assert len(args) == 2
            return Quotient(args)
        elif operator == "*":
            return Product(args)
        else:
            if len(args) == 1:
                return AdditiveInverse(args)
            else:
                assert len(args) == 2
                return Difference(args)
    elif isFloat(exp):
        return NumericConstant(string.atof(exp))
    elif exp == "?duration":
        return DurationVariable()
    else:
        return PrimitiveNumericExpression(exp,[])
コード例 #8
0
ファイル: f_expression.py プロジェクト: AT-GROUP/AT-PLANNER
def parse_expression(exp, durative=False):
    if isinstance(exp, list):
        alist = exp
        operator_or_functionsymbol = alist[0]
        if operator_or_functionsymbol in ("+","/","*","-"):
            args = [parse_expression(arg,durative) for arg in alist[1:]]
            operator = operator_or_functionsymbol
        elif operator_or_functionsymbol == "?duration":
            return DurationVariable()
        else:
            return PrimitiveNumericExpression(operator_or_functionsymbol,
                                              [conditions.parse_term(arg) for arg in alist[1:]])
        if operator == "+":
            return Sum(args)
        elif operator == "/":
            assert len(args) == 2
            return Quotient(args)
        elif operator == "*":
            return Product(args)
        else:
            if len(args) == 1:
                return AdditiveInverse(args)
            else:
                assert len(args) == 2
                return Difference(args)
    elif isFloat(exp):
        return NumericConstant(string.atof(exp))
    elif exp == "?duration":
        return DurationVariable()
    else:
        return PrimitiveNumericExpression(exp,[])
コード例 #9
0
ファイル: tasks.py プロジェクト: speckdavid/shakey2016
    def parse(domain_pddl, task_pddl):
        domain_name, requirements, oplinit, constants, predicates, types, functions, actions, durative_actions, axioms, modules, subplan_generators \
                     = parse_domain(domain_pddl)
        task_name, task_domain_name, module_inits, module_exits, objects, init, goal = parse_task(
            task_pddl)

        assert domain_name == task_domain_name
        objects = constants + objects
        init += [
            conditions.Atom("=", (conditions.parse_term(
                obj.name), conditions.parse_term(obj.name))) for obj in objects
        ]
        return Task(domain_name, task_name, requirements, oplinit, types,
                    objects, modules, predicates, init, goal, actions,
                    durative_actions, axioms, Task.FUNCTION_SYMBOLS,
                    subplan_generators, module_inits, module_exits)
コード例 #10
0
def parse_cond_effect(alist, durative=False):
    tag = alist[0]
    if tag == "and":
        return ConjunctiveEffect([parse_cond_effect(eff, durative) for eff in alist[1:]])
    elif tag in ("scale-up", "scale-down", "increase", "decrease"):
        return ConjunctiveEffect([f_expression.parse_assignment(alist, durative)])
    elif tag == "assign":
        symbol = alist[1]
        if isinstance(symbol, list):
            symbol = symbol[0]
        if tasks.Task.FUNCTION_SYMBOLS.get(symbol, "object") == "number":
            return ConjunctiveEffect([f_expression.parse_assignment(alist, durative)])
        else:
            return ConjunctiveEffect(
                [ObjectFunctionAssignment(conditions.parse_term(alist[1]), conditions.parse_term(alist[2]))])
    else:
        return ConjunctiveEffect([conditions.parse_condition(alist)])
コード例 #11
0
ファイル: f_expression.py プロジェクト: ErhuRong/planning
def parse_expression(exp):
    if isinstance(exp, list):
        functionsymbol = exp[0]
        return PrimitiveNumericExpression(functionsymbol,
                                          [conditions.parse_term(arg) for arg in exp[1:]])
    elif exp.replace(".","").isdigit():
        return NumericConstant(string.atof(exp))
    else:
        return PrimitiveNumericExpression(exp,[])
コード例 #12
0
ファイル: f_expression.py プロジェクト: javiercu/itsimple
def parse_expression(exp):
    if isinstance(exp, list):
        functionsymbol = exp[0]
        return PrimitiveNumericExpression(functionsymbol,
                                          [conditions.parse_term(arg) for arg in exp[1:]])
    elif exp.replace(".","").isdigit():
        return NumericConstant(string.atof(exp))
    else:
        return PrimitiveNumericExpression(exp,[])
コード例 #13
0
ファイル: tasks.py プロジェクト: aldukeman/lmtd
def parse_task(task_pddl):
  iterator = iter(task_pddl)

  assert iterator.next() == "define"
  problem_line = iterator.next()
  assert problem_line[0] == "problem" and len(problem_line) == 2
  yield problem_line[1]
  domain_line = iterator.next()
  assert domain_line[0] == ":domain" and len(domain_line) == 2
  yield domain_line[1]

  objects_opt = iterator.next()
  if objects_opt[0] == ":objects":
    yield pddl_types.parse_typed_list(objects_opt[1:])
    init = iterator.next()
  else:
    yield []
    init = objects_opt

  assert init[0] == ":init"
  initial = []
  for fact in init[1:]:
    if fact[0] == "=":
        if conditions.is_function_comparison(fact): # numeric function
            initial.append(f_expression.parse_assignment(fact))
        else: # object function
            function = conditions.parse_term(fact[1])
            terms = function.args
            terms.append(conditions.parse_term(fact[2]))
            atomname = conditions.function_predicate_name(function.name)
            initial.append(conditions.Atom(atomname, terms))
    else:
        initial.append(conditions.Atom(fact[0], [conditions.parse_term(term) for term in fact[1:]]))
  yield initial

  goal = iterator.next()
  assert goal[0] == ":goal" and len(goal) == 2
  yield conditions.parse_condition(goal[1])

  for entry in iterator:
    if entry[0] == ":metric" and entry[1]=="minimize":
        if entry[2][0] in ["total-time", "total-cost"] :
            continue
    assert False, entry
コード例 #14
0
def parse_expression(exp):
    if isinstance(exp, list):
        functionsymbol = exp[0]
        return PrimitiveNumericExpression(
            functionsymbol, [conditions.parse_term(arg) for arg in exp[1:]])
    elif exp.replace(".", "").isdigit():
        return NumericConstant(string.atof(exp))
    elif exp[0] == "-":
        raise ValueError("Negative numbers are not supported")
    else:
        return PrimitiveNumericExpression(exp, [])
コード例 #15
0
ファイル: f_expression.py プロジェクト: aldukeman/fdss
def parse_expression(exp):
    if isinstance(exp, list):
        functionsymbol = exp[0]
        return PrimitiveNumericExpression(functionsymbol,
                                          [conditions.parse_term(arg) for arg in exp[1:]])
    elif exp.replace(".","").isdigit():
        return NumericConstant(string.atof(exp))
    elif exp[0] == "-":
        raise ValueError("Negative numbers are not supported")
    else:
        return PrimitiveNumericExpression(exp,[])
コード例 #16
0
ファイル: effects.py プロジェクト: AT-GROUP/AT-PLANNER
def parse_cond_effect(alist, durative=False):
    tag = alist[0]
    if tag == "and":
        return ConjunctiveEffect([parse_cond_effect(eff,durative) for eff in alist[1:]])
    elif tag in ("scale-up", "scale-down", "increase", "decrease"):
        return ConjunctiveEffect([f_expression.parse_assignment(alist,durative)])
    elif tag == "assign":
        symbol = alist[1]
        if isinstance(symbol,list):
            symbol = symbol[0]
        if tasks.Task.FUNCTION_SYMBOLS.get(symbol,"object")=="number":
            return ConjunctiveEffect([f_expression.parse_assignment(alist,durative)])
        else:
            return ConjunctiveEffect([ObjectFunctionAssignment(conditions.parse_term(alist[1]),conditions.parse_term(alist[2]))])
    else:
        return ConjunctiveEffect([conditions.parse_condition(alist)])
コード例 #17
0
ファイル: tasks.py プロジェクト: speckdavid/shakey2016
def parse_task(task_pddl):
    iterator = iter(task_pddl)

    assert iterator.next() == "define"
    problem_line = iterator.next()
    assert problem_line[0] == "problem" and len(problem_line) == 2
    yield problem_line[1]
    domain_line = iterator.next()
    assert domain_line[0] == ":domain" and len(domain_line) == 2
    yield domain_line[1]

    module_opt = iterator.next()
    if module_opt[0] == ":moduleoptions":
        yield [modules.ModuleInit.parse(mi) for mi in module_opt[1:]]
        module_exit_opt = iterator.next()
    else:
        yield []
        module_exit_opt = module_opt

    if module_exit_opt[0] == ":moduleexitoptions":
        yield [modules.ModuleExit.parse(mi) for mi in module_exit_opt[1:]]
        objects_opt = iterator.next()
    else:
        yield []
        objects_opt = module_exit_opt

    if objects_opt[0] == ":objects":
        yield pddl_types.parse_typed_list(objects_opt[1:])
        init = iterator.next()
    else:
        yield []
        init = objects_opt

    assert init[0] == ":init"
    initial = []
    for fact in init[1:]:
        if fact[0] == "=":
            if conditions.is_function_comparison(fact):  # numeric function
                initial.append(f_expression.parse_assignment(fact))
            else:  # object function
                function = conditions.parse_term(fact[1])
                terms = function.args
                terms.append(conditions.parse_term(fact[2]))
                atomname = conditions.function_predicate_name(function.name)
                initial.append(conditions.Atom(atomname, terms))
        else:
            initial.append(
                conditions.Atom(
                    fact[0],
                    [conditions.parse_term(term) for term in fact[1:]]))
    yield initial

    goal = iterator.next()
    assert goal[0] == ":goal" and len(goal) == 2
    yield conditions.parse_condition(goal[1])

    for entry in iterator:
        if entry[0] == ":metric" and entry[1] == "minimize":
            if entry[2][0] in ["total-time", "total-cost"]:
                continue
        assert False, "Can only minimize total-time or total-cost, got: " + str(
            entry)