Ejemplo n.º 1
0
    def test_robot_loader_adv_writer(self):
        problem = self.problems['robot_loader_adv'].problem

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :typing :negative-preconditions :equality)', pddl_domain)
        self.assertIn('(:types Robot Location Container)', pddl_domain)
        self.assertIn('(:predicates (robot_at ?robot - Robot ?position - Location) (cargo_at ?cargo - Container ?position - Location) (cargo_mounted ?cargo - Container ?robot - Robot))', pddl_domain)
        self.assertIn('(:action move', pddl_domain)
        self.assertIn(':parameters ( ?l_from - Location ?l_to - Location ?r - Robot)', pddl_domain)
        self.assertIn(':precondition (and (not (= ?l_from ?l_to)) (robot_at ?r ?l_from) (not (robot_at ?r ?l_to)))', pddl_domain)
        self.assertIn(':effect (and (not (robot_at ?r ?l_from)) (robot_at ?r ?l_to))', pddl_domain)
        self.assertIn('(:action load', pddl_domain)
        self.assertIn(':parameters ( ?loc - Location ?r - Robot ?c - Container)', pddl_domain)
        self.assertIn(':precondition (and (cargo_at ?c ?loc) (robot_at ?r ?loc) (not (cargo_mounted ?c ?r)))', pddl_domain)
        self.assertIn(':effect (and (not (cargo_at ?c ?loc)) (cargo_mounted ?c ?r))', pddl_domain)
        self.assertIn('(:action unload', pddl_domain)
        self.assertIn(':parameters ( ?loc - Location ?r - Robot ?c - Container)', pddl_domain)
        self.assertIn(':precondition (and (not (cargo_at ?c ?loc)) (robot_at ?r ?loc) (cargo_mounted ?c ?r))', pddl_domain)
        self.assertIn(':effect (and (cargo_at ?c ?loc) (not (cargo_mounted ?c ?r)))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain robot_loader_adv-domain)', pddl_problem)
        self.assertIn('(:objects', pddl_problem)
        self.assertIn('r1 - Robot', pddl_problem)
        self.assertIn('l1 l2 l3 - Location', pddl_problem)
        self.assertIn('c1 - Container', pddl_problem)
        self.assertIn('(:init (robot_at r1 l1) (cargo_at c1 l2))', pddl_problem)
        self.assertIn('(:goal (and (cargo_at c1 l3) (robot_at r1 l1)))', pddl_problem)
Ejemplo n.º 2
0
    def test_robot_loader_writer(self):
        problem = self.problems['robot_loader'].problem

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :typing :negative-preconditions :equality)', pddl_domain)
        self.assertIn('(:types Location)', pddl_domain)
        self.assertIn('(:predicates (robot_at ?position - Location) (cargo_at ?position - Location) (cargo_mounted))', pddl_domain)
        self.assertIn('(:action move', pddl_domain)
        self.assertIn(':parameters ( ?l_from - Location ?l_to - Location)', pddl_domain)
        self.assertIn(':precondition (and (not (= ?l_from ?l_to)) (robot_at ?l_from) (not (robot_at ?l_to)))', pddl_domain)
        self.assertIn(':effect (and (not (robot_at ?l_from)) (robot_at ?l_to))', pddl_domain)
        self.assertIn('(:action load', pddl_domain)
        self.assertIn(':parameters ( ?loc - Location)', pddl_domain)
        self.assertIn(':precondition (and (cargo_at ?loc) (robot_at ?loc) (not (cargo_mounted)))', pddl_domain)
        self.assertIn(':effect (and (not (cargo_at ?loc)) (cargo_mounted))', pddl_domain)
        self.assertIn('(:action unload', pddl_domain)
        self.assertIn(':parameters ( ?loc - Location)', pddl_domain)
        self.assertIn(':precondition (and (not (cargo_at ?loc)) (robot_at ?loc) (cargo_mounted))', pddl_domain)
        self.assertIn(':effect (and (cargo_at ?loc) (not (cargo_mounted)))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain robot_loader-domain)', pddl_problem)
        self.assertIn('(:objects', pddl_problem)
        self.assertIn('l1 l2 - Location', pddl_problem)
        self.assertIn('(:init (robot_at l1) (cargo_at l2))', pddl_problem)
        self.assertIn('(:goal (and (cargo_at l1)))', pddl_problem)
Ejemplo n.º 3
0
    def test_rationals(self):
        problem = self.problems['robot_decrease'].problem.clone()

        # Check perfect conversion
        battery = problem.fluent('battery_charge')
        problem.set_initial_value(battery, Fraction(5, 2))
        w = PDDLWriter(problem)
        pddl_txt = w.get_problem()
        self.assertNotIn('5/2', pddl_txt)
        self.assertIn('2.5', pddl_txt)

        # Check imperfect conversion
        with pytest.warns(UserWarning, match="cannot exactly represent") as warns:
            battery = problem.fluent('battery_charge')
            problem.set_initial_value(battery, Fraction(10, 3))
            w = PDDLWriter(problem)
            pddl_txt = w.get_problem()
            self.assertNotIn('10/3', pddl_txt)
            self.assertIn('3.333333333', pddl_txt)
Ejemplo n.º 4
0
    def test_basic_writer(self):
        problem = self.problems['basic'].problem

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :negative-preconditions)', pddl_domain)
        self.assertIn('(:predicates (x))', pddl_domain)
        self.assertIn('(:action a', pddl_domain)
        self.assertIn(':parameters ()', pddl_domain)
        self.assertIn(':precondition (and (not (x)))', pddl_domain)
        self.assertIn(':effect (and (x))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain basic-domain)', pddl_problem)
        self.assertIn('(:init)', pddl_problem)
        self.assertIn('(:goal (and (x)))', pddl_problem)
Ejemplo n.º 5
0
    def test_basic_exists_writer(self):
        problem = self.problems['basic_exists'].problem

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :typing :existential-preconditions)', pddl_domain)
        self.assertIn('(:predicates (x) (y ?semaphore - Semaphore))', pddl_domain)
        self.assertIn('(:action a', pddl_domain)
        self.assertIn(':parameters ()', pddl_domain)
        self.assertIn(':precondition (and (exists (?s - Semaphore)\n (y ?s)))', pddl_domain)
        self.assertIn(':effect (and (x))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain basic_exists-domain)', pddl_problem)
        self.assertIn('(:objects \n   o1 o2 - Semaphore\n )', pddl_problem)
        self.assertIn('(:init (y o1))', pddl_problem)
        self.assertIn('(:goal (and (x)))', pddl_problem)
Ejemplo n.º 6
0
    def test_robot_writer(self):
        problem = self.problems['robot'].problem

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :typing :negative-preconditions :equality :numeric-fluents)', pddl_domain)
        self.assertIn('(:types Location)', pddl_domain)
        self.assertIn('(:predicates (robot_at ?position - Location))', pddl_domain)
        self.assertIn('(:functions (battery_charge))', pddl_domain)
        self.assertIn('(:action move', pddl_domain)
        self.assertIn(':parameters ( ?l_from - Location ?l_to - Location)', pddl_domain)
        self.assertIn(':precondition (and (<= 10 (battery_charge)) (not (= ?l_from ?l_to)) (robot_at ?l_from) (not (robot_at ?l_to)))', pddl_domain)
        self.assertIn(':effect (and (not (robot_at ?l_from)) (robot_at ?l_to) (assign (battery_charge) (- (battery_charge) 10)))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain robot-domain)', pddl_problem)
        self.assertIn('(:objects', pddl_problem)
        self.assertIn('l1 l2 - Location', pddl_problem)
        self.assertIn('(:init (robot_at l1) (= (battery_charge) 100))', pddl_problem)
        self.assertIn('(:goal (and (robot_at l2)))', pddl_problem)
Ejemplo n.º 7
0
    def test_basic_conditional_writer(self):
        problem = self.problems['basic_conditional'].problem

        self.assertTrue(problem.action('a_x').is_conditional())
        self.assertFalse(problem.action('a_y').is_conditional())

        w = PDDLWriter(problem)

        pddl_domain = w.get_domain()
        self.assertIn('(:requirements :strips :negative-preconditions :conditional-effects)', pddl_domain)
        self.assertIn('(:predicates (x) (y))', pddl_domain)
        self.assertIn('(:action a_x', pddl_domain)
        self.assertIn(':parameters ()', pddl_domain)
        self.assertIn(':precondition (and (not (x)))', pddl_domain)
        self.assertIn(':effect (and (when (y) (x)))', pddl_domain)
        self.assertIn('(:action a_y', pddl_domain)
        self.assertIn(':parameters ()', pddl_domain)
        self.assertIn(':precondition (and (not (y)))', pddl_domain)
        self.assertIn(':effect (and (y))', pddl_domain)

        pddl_problem = w.get_problem()
        self.assertIn('(:domain basic_conditional-domain)', pddl_problem)
        self.assertIn('(:init)', pddl_problem)
        self.assertIn('(:goal (and (x)))', pddl_problem)