Пример #1
0
class TestGrounder(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    def test_basic(self):
        problem = self.problems['basic'].problem

        gro = TransformersGrounder(problem)
        with self.assertRaises(UPUsageError) as e:
            gro.get_rewrite_back_map()
        self.assertIn('The get_rewrite_back_map method must be called after the function get_rewritten_problem!', str(e.exception))

        grounded_problem = gro.get_rewritten_problem()
        grounded_problem_2 = gro.get_rewritten_problem()
        self.assertEqual(grounded_problem, grounded_problem_2)
        grounded_problem.name = problem.name
        self.assertEqual(grounded_problem, problem)

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(full_numeric_kind))
    def test_robot(self):
        problem = self.problems['robot'].problem

        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 2)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)

        with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            grounded_plan = planner.solve(grounded_problem).plan
            plan = gro.rewrite_back_plan(grounded_plan)
            for ai in plan.actions:
                a = ai.action
                self.assertEqual(a, problem.action(a.name))
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, plan))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(full_numeric_kind))
    def test_robot_locations_connected(self):
        problem = self.problems['robot_locations_connected'].problem

        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 28)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)
        for i, a in enumerate(problem.actions):
            if i == 0:
                self.assertEqual(len(gro.get_transformed_actions(a)), 8)
            elif i == 1:
                self.assertEqual(len(gro.get_transformed_actions(a)), 20)
            else:
                self.assertTrue(False)

        with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            grounded_plan = planner.solve(grounded_problem).plan
            plan = gro.rewrite_back_plan(grounded_plan)
            for ai in plan.actions:
                a = ai.action
                self.assertEqual(a, problem.action(a.name))
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, plan))


    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(full_numeric_kind))
    def test_robot_locations_connected_from_factory(self):
        problem = self.problems['robot_locations_connected'].problem

        with Grounder(name='up_grounder') as embedded_grounder:
            self.assertTrue(embedded_grounder.supports(problem.kind))
            ground_result = embedded_grounder.ground(problem)
            grounded_problem, rewrite_plan_funct = ground_result.problem, ground_result.lift_action_instance
            self.assertEqual(len(grounded_problem.actions), 28)
            for a in grounded_problem.actions:
                self.assertEqual(len(a.parameters), 0)

            with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
                self.assertNotEqual(planner, None)
                grounded_plan = planner.solve(grounded_problem).plan
                plan = grounded_plan.replace_action_instances(rewrite_plan_funct)
                for ai in plan.actions:
                    a = ai.action
                    self.assertEqual(a, problem.action(a.name))
                with PlanValidator(problem_kind=problem.kind) as pv:
                    self.assertTrue(pv.validate(problem, plan))


    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(full_numeric_kind))
    def test_robot_locations_connected_from_factory_with_problem_kind(self):
        problem = self.problems['robot_locations_connected'].problem
        kind = problem.kind

        with Grounder(problem_kind=kind) as embedded_grounder:
            self.assertTrue(embedded_grounder.supports(kind))
            ground_result = embedded_grounder.ground(problem)
            grounded_problem, rewrite_plan_funct = ground_result.problem, ground_result.lift_action_instance
            self.assertEqual(len(grounded_problem.actions), 28)
            for a in grounded_problem.actions:
                self.assertEqual(len(a.parameters), 0)

            with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
                self.assertNotEqual(planner, None)
                grounded_plan = planner.solve(grounded_problem).plan
                plan = grounded_plan.replace_action_instances(rewrite_plan_funct)
                for ai in plan.actions:
                    a = ai.action
                    self.assertEqual(a, problem.action(a.name))
                with PlanValidator(problem_kind=problem.kind) as pv:
                    self.assertTrue(pv.validate(problem, plan))


    @skipIfNoOneshotPlannerForProblemKind(hierarchical_kind)
    @skipIfNoPlanValidatorForProblemKind(hierarchical_kind)
    def test_hierarchical_blocks_world(self):
        problem = self.problems['hierarchical_blocks_world'].problem

        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 108)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)
        for i, a in enumerate(problem.actions):
            if i == 0:
                self.assertEqual(len(gro.get_transformed_actions(a)), 108)
            else:
                self.assertTrue(False)

        with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            grounded_plan = planner.solve(grounded_problem).plan
            plan = gro.rewrite_back_plan(grounded_plan)
            for ai in plan.actions:
                a = ai.action
                self.assertEqual(a, problem.action(a.name))
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, plan))


    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(basic_temporal_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(basic_temporal_kind))
    def test_matchcellar(self):
        problem = self.problems['matchcellar'].problem

        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 6)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)
        for a in problem.actions:
            self.assertEqual(len(gro.get_transformed_actions(a)), 3)

        with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            grounded_plan = planner.solve(grounded_problem).plan
            plan = gro.rewrite_back_plan(grounded_plan)
            for _, ai, _ in plan.actions:
                a = ai.action
                self.assertEqual(a, problem.action(a.name))
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, plan))


    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(basic_temporal_kind))
    @skipIfNoPlanValidatorForProblemKind(classical_kind.union(basic_temporal_kind))
    def test_matchcellar_grounder_from_factory(self):
        problem = self.problems['matchcellar'].problem

        gro = TransformersGrounder(problem)
        grounded_problem_test = gro.get_rewritten_problem()
        with Grounder(name='up_grounder') as grounder:
            self.assertTrue(grounder.supports(problem.kind))
            ground_result = grounder.ground(problem)
            grounded_problem_try, rewrite_back_plan_function = ground_result.problem, ground_result.lift_action_instance
            self.assertEqual(grounded_problem_test, grounded_problem_try)
            with OneshotPlanner(problem_kind=grounded_problem_try.kind) as planner:
                self.assertNotEqual(planner, None)
                grounded_plan = planner.solve(grounded_problem_try).plan
                plan = grounded_plan.replace_action_instances(rewrite_back_plan_function)
                for _, ai, _ in plan.actions:
                    a = ai.action
                    self.assertEqual(a, problem.action(a.name))
                with PlanValidator(problem_kind=problem.kind) as pv:
                    self.assertTrue(pv.validate(problem, plan))

    def test_timed_connected_locations(self):
        problem = self.problems['timed_connected_locations'].problem

        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 20)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)
        for a in problem.actions:
            self.assertEqual(len(gro.get_transformed_actions(a)), 20)

    def test_ad_hoc_1(self):
        problem = Problem('ad_hoc')
        Location = UserType('Location')
        visited = Fluent('at', BoolType(), position=Location)
        l1 = Object('l1', Location)
        visit = InstantaneousAction('visit', l_to=Location)
        l_to = visit.parameter('l_to')
        visit.add_effect(visited(l_to), True)
        visit_l1 = InstantaneousAction('visit_l1')
        visit_l1.add_effect(visited(l1), True)
        problem.add_fluent(visited)
        problem.set_initial_value(visited(l1), True)
        problem.add_object(l1)
        problem.add_action(visit)
        problem.add_action(visit_l1)
        gro = TransformersGrounder(problem)
        grounded_problem = gro.get_rewritten_problem()
        self.assertEqual(len(grounded_problem.actions), 2)
        for a in grounded_problem.actions:
            self.assertEqual(len(a.parameters), 0)
        for a in problem.actions:
            self.assertEqual(len(gro.get_transformed_actions(a)), 1)

    def test_ad_hoc_2(self):
        problem = Problem('ad_hoc')
        gro = TransformersGrounder(problem)
        gro.get_rewritten_problem()
        with self.assertRaises(AttributeError):
            gro.rewrite_back_plan(problem)

    @skipIfSolverNotAvailable('pyperplan')
    def test_pyperplan_grounder(self):

        problem = self.problems['robot_no_negative_preconditions'].problem
        for action in problem.actions:
            self.assertTrue(len(action.parameters) > 0)
        with Grounder(name='pyperplan') as grounder:
            ground_result = grounder.ground(problem)
            grounded_problem, rewrite_back_plan_function = ground_result.problem, ground_result.lift_action_instance
            for grounded_action in grounded_problem.actions:
                self.assertEqual(len(grounded_action.parameters), 0)
            with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
                self.assertNotEqual(planner, None)
                grounded_plan = planner.solve(grounded_problem).plan
                plan = grounded_plan.replace_action_instances(rewrite_back_plan_function)
                for ai in plan.actions:
                    a = ai.action
                    self.assertEqual(a, problem.action(a.name))
                with PlanValidator(problem_kind=problem.kind) as pv:
                    self.assertTrue(pv.validate(problem, plan))

    @skipIfSolverNotAvailable('pyperplan')
    def test_pyperplan_grounder_mockup_problem(self):
        problem = Problem('mockup')
        Location = UserType('Location')
        at = Fluent('at', BoolType(), position=Location)
        at_l2 = Fluent('at_l2')
        l1 = Object('l1', Location)
        l2 = Object('l2', Location)
        move_to = InstantaneousAction('move_to', l_to=Location)
        l_to = move_to.parameter('l_to')
        move_to.add_effect(at(l_to), True)
        move_to_l2 = InstantaneousAction('move_to_l2')
        move_to_l2.add_effect(at_l2, True)
        problem.add_fluent(at, default_initial_value=False)
        problem.add_fluent(at_l2, default_initial_value=False)
        problem.add_object(l1)
        problem.add_object(l2)
        problem.add_action(move_to)
        problem.add_action(move_to_l2)
        problem.add_goal(at(l1))
        problem.add_goal(at(l2))
        problem.add_goal(at_l2)

        with Grounder(name='pyperplan') as grounder:
            ground_result = grounder.ground(problem)
            grounded_problem, rewrite_back_plan_function = ground_result.problem, ground_result.lift_action_instance
            for grounded_action in grounded_problem.actions:
                self.assertEqual(len(grounded_action.parameters), 0)
            with OneshotPlanner(problem_kind=grounded_problem.kind) as planner:
                self.assertNotEqual(planner, None)
                grounded_plan = planner.solve(grounded_problem).plan
                plan = grounded_plan.replace_action_instances(rewrite_back_plan_function)
                for ai in plan.actions:
                    a = ai.action
                    self.assertEqual(a, problem.action(a.name))
                with PlanValidator(problem_kind=problem.kind) as pv:
                    self.assertTrue(pv.validate(problem, plan))
Пример #2
0
class TestPlanner(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    @skipIfSolverNotAvailable('tamer')
    def test_basic(self):
        problem = self.problems['basic'].problem
        a = problem.action('a')

        with OneshotPlanner(name='tamer', params={'weight': 0.8}) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertEqual(final_report.status,
                             PlanGenerationResultStatus.SOLVED_SATISFICING)
            self.assertEqual(len(plan.actions), 1)
            self.assertEqual(plan.actions[0].action, a)
            self.assertEqual(len(plan.actions[0].actual_parameters), 0)

    @skipIfSolverNotAvailable('tamer')
    def test_basic_with_timeout(self):
        problem = self.problems['basic'].problem
        a = problem.action('a')

        with OneshotPlanner(name='tamer', params={'weight': 0.8}) as planner:
            self.assertNotEqual(planner, None)
            with warnings.catch_warnings(record=True) as w:
                final_report = planner.solve(problem, timeout=0.001)
                self.assertIn(final_report.status, POSITIVE_OUTCOMES)
                plan = final_report.plan
                self.assertEqual(final_report.status,
                                 PlanGenerationResultStatus.SOLVED_SATISFICING)
                self.assertEqual(len(plan.actions), 1)
                self.assertEqual(plan.actions[0].action, a)
                self.assertEqual(len(plan.actions[0].actual_parameters), 0)
                self.assertEqual(len(w), 1)
                self.assertEqual('Tamer does not support timeout.',
                                 str(w[-1].message))

    @skipIfSolverNotAvailable('tamer')
    def test_basic_parallel(self):
        problem = self.problems['basic'].problem
        a = problem.action('a')

        with OneshotPlanner(names=['tamer', 'tamer'],
                            params=[{
                                'heuristic': 'hadd'
                            }, {
                                'heuristic': 'hmax'
                            }]) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertEqual(final_report.status,
                             PlanGenerationResultStatus.SOLVED_SATISFICING)
            self.assertEqual(len(plan.actions), 1)
            self.assertEqual(plan.actions[0].action, a)
            self.assertEqual(len(plan.actions[0].actual_parameters), 0)

    @skipIfSolverNotAvailable('tamer')
    def test_timed_connected_locations_parallel(self):
        problem = self.problems['timed_connected_locations'].problem
        move = problem.action('move')
        with OneshotPlanner(names=['tamer', 'tamer'],
                            params=[{
                                'heuristic': 'hadd'
                            }, {
                                'heuristic': 'hmax'
                            }]) as planner:
            self.assertNotEqual(planner, None)
            with self.assertRaises(up.exceptions.UPUsageError) as e:
                final_report = planner.solve(problem)
            self.assertIn('Tamer cannot solve this kind of problem!',
                          str(e.exception))
            quantifiers_remover = up.transformers.QuantifiersRemover(problem)
            suitable_problem = quantifiers_remover.get_rewritten_problem()
            final_report = planner.solve(suitable_problem)
            plan = quantifiers_remover.rewrite_back_plan(final_report.plan)
            self.assertEqual(final_report.status,
                             PlanGenerationResultStatus.SOLVED_SATISFICING)
            self.assertEqual(len(plan.actions), 2)
            self.assertEqual((plan.actions[0])[1].action, move)
            self.assertEqual((plan.actions[1])[1].action, move)

    @skipIfNoOneshotPlannerForProblemKind(
        classical_kind.union(quality_metrics_kind))
    @skipIfNoOneshotPlannerSatisfiesOptimalityGuarantee(
        PlanGenerationResultStatus.SOLVED_OPTIMALLY)
    def test_actions_cost(self):
        problem = self.problems['basic_with_costs'].problem
        opt_plan = self.problems['basic_with_costs'].plan
        with OneshotPlanner(problem_kind=problem.kind,
                            optimality_guarantee=PlanGenerationResultStatus.
                            SOLVED_OPTIMALLY) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertEqual(final_report.status,
                             PlanGenerationResultStatus.SOLVED_OPTIMALLY)
            self.assertEqual(plan, opt_plan)

    @skipIfNoOneshotPlannerForProblemKind(
        classical_kind.union(basic_numeric_kind))
    def test_robot(self):
        problem = self.problems['robot'].problem
        move = problem.action('move')

        with OneshotPlanner(problem_kind=problem.kind) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertIn(final_report.status, POSITIVE_OUTCOMES)
            self.assertNotEqual(plan, None)
            self.assertEqual(len(plan.actions), 1)
            self.assertEqual(plan.actions[0].action, move)
            self.assertEqual(len(plan.actions[0].actual_parameters), 2)

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    def test_robot_loader(self):
        problem = self.problems['robot_loader'].problem
        move = problem.action('move')
        load = problem.action('load')
        unload = problem.action('unload')

        with OneshotPlanner(problem_kind=problem.kind) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertIn(final_report.status, POSITIVE_OUTCOMES)
            self.assertEqual(len(plan.actions), 4)
            self.assertEqual(plan.actions[0].action, move)
            self.assertEqual(plan.actions[1].action, load)
            self.assertEqual(plan.actions[2].action, move)
            self.assertEqual(plan.actions[3].action, unload)
            self.assertEqual(len(plan.actions[0].actual_parameters), 2)
            self.assertEqual(len(plan.actions[1].actual_parameters), 1)
            self.assertEqual(len(plan.actions[2].actual_parameters), 2)
            self.assertEqual(len(plan.actions[3].actual_parameters), 1)

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    def test_robot_loader_adv(self):
        problem = self.problems['robot_loader_adv'].problem
        move = problem.action('move')
        load = problem.action('load')
        unload = problem.action('unload')

        with OneshotPlanner(problem_kind=problem.kind) as planner:
            self.assertNotEqual(planner, None)
            final_report = planner.solve(problem)
            plan = final_report.plan
            self.assertIn(final_report.status, POSITIVE_OUTCOMES)
            self.assertEqual(len(plan.actions), 5)
            self.assertEqual(plan.actions[0].action, move)
            self.assertEqual(plan.actions[1].action, load)
            self.assertEqual(plan.actions[2].action, move)
            self.assertEqual(plan.actions[3].action, unload)
            self.assertEqual(plan.actions[4].action, move)
            self.assertEqual(len(plan.actions[0].actual_parameters), 3)
            self.assertEqual(len(plan.actions[1].actual_parameters), 3)
            self.assertEqual(len(plan.actions[2].actual_parameters), 3)
            self.assertEqual(len(plan.actions[3].actual_parameters), 3)
            self.assertEqual(len(plan.actions[4].actual_parameters), 3)
Пример #3
0
class TestPlanValidator(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    @skipIfNoPlanValidatorForProblemKind(classical_kind)
    def test_basic(self):
        problem, plan = self.problems['basic']

        with PlanValidator(problem_kind=problem.kind) as validator:
            self.assertNotEqual(validator, None)

            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.VALID)

            plan = up.plan.SequentialPlan([])
            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.INVALID)

    @skipIfNoPlanValidatorForProblemKind(
        classical_kind.union(basic_numeric_kind))
    def test_robot(self):
        problem, plan = self.problems['robot']

        with PlanValidator(problem_kind=problem.kind) as validator:
            self.assertNotEqual(validator, None)

            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.VALID)

            plan = up.plan.SequentialPlan([])
            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.INVALID)

    @skipIfNoPlanValidatorForProblemKind(classical_kind)
    def test_robot_loader(self):
        problem, plan = self.problems['robot_loader']

        with PlanValidator(problem_kind=problem.kind) as validator:
            self.assertNotEqual(validator, None)

            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.VALID)

            plan = up.plan.SequentialPlan([])
            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.INVALID)

    @skipIfNoPlanValidatorForProblemKind(classical_kind)
    def test_robot_loader_adv(self):
        problem, plan = self.problems['robot_loader_adv']

        with PlanValidator(problem_kind=problem.kind) as validator:
            self.assertNotEqual(validator, None)

            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.VALID)

            plan = up.plan.SequentialPlan([])
            res = validator.validate(problem, plan)
            self.assertEqual(res.status,
                             up.solvers.ValidationResultStatus.INVALID)
Пример #4
0
class TestNegativeConditionsRemover(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.env = get_env()
        self.problems = get_example_problems()

    @skipIfNoOneshotPlannerForProblemKind(basic_classical_kind)
    @skipIfNoPlanValidatorForProblemKind(classical_kind)
    def test_basic(self):
        problem = self.problems['basic'].problem
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        self.assertEqual(
            len(problem.fluents) + 1, len(positive_problem.fluents))
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        with OneshotPlanner(problem_kind=positive_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            positive_plan = planner.solve(positive_problem).plan
            new_plan = npr.rewrite_back_plan(positive_plan)
            with PlanValidator(problem_kind=problem.kind) as PV:
                self.assertTrue(PV.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(basic_classical_kind)
    @skipIfNoPlanValidatorForProblemKind(classical_kind)
    def test_robot_loader_mod(self):
        problem = self.problems['robot_loader_mod'].problem
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        positive_problem_2 = npr.get_rewritten_problem()
        self.assertEqual(positive_problem, positive_problem_2)
        self.assertEqual(
            len(problem.fluents) + 4, len(positive_problem.fluents))
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        with OneshotPlanner(problem_kind=positive_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            positive_plan = planner.solve(positive_problem).plan
            new_plan = npr.rewrite_back_plan(positive_plan)
            with PlanValidator(problem_kind=problem.kind) as PV:
                self.assertTrue(PV.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(
        basic_classical_kind.union(basic_temporal_kind))
    @skipIfNoPlanValidatorForProblemKind(
        classical_kind.union(basic_temporal_kind))
    def test_matchcellar(self):
        problem = self.problems['matchcellar'].problem
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        with OneshotPlanner(problem_kind=positive_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            positive_plan = planner.solve(positive_problem).plan
            new_plan = npr.rewrite_back_plan(positive_plan)
            with PlanValidator(problem_kind=problem.kind) as PV:
                self.assertTrue(PV.validate(problem, new_plan))
        self.assertEqual(
            len(problem.fluents) + 1, len(positive_problem.fluents))
        light_match = problem.action('light_match')
        mend_fuse = problem.action('mend_fuse')
        m1 = problem.object('m1')
        m2 = problem.object('m2')
        m3 = problem.object('m3')
        f1 = problem.object('f1')
        f2 = problem.object('f2')
        f3 = problem.object('f3')
        light_m1 = ActionInstance(light_match, (ObjectExp(m1), ))
        light_m2 = ActionInstance(light_match, (ObjectExp(m2), ))
        light_m3 = ActionInstance(light_match, (ObjectExp(m3), ))
        mend_f1 = ActionInstance(mend_fuse, (ObjectExp(f1), ))
        mend_f2 = ActionInstance(mend_fuse, (ObjectExp(f2), ))
        mend_f3 = ActionInstance(mend_fuse, (ObjectExp(f3), ))
        npa = [a for s, a, d in new_plan.actions]
        self.assertIn(light_m1, npa)
        self.assertIn(light_m2, npa)
        self.assertIn(light_m3, npa)
        self.assertIn(mend_f1, npa)
        self.assertIn(mend_f2, npa)
        self.assertIn(mend_f3, npa)

    @skipIfNoOneshotPlannerForProblemKind(full_classical_kind)
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind)
    def test_basic_conditional(self):
        problem = self.problems['basic_conditional'].problem
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        self.assertEqual(
            len(problem.fluents) + 2, len(positive_problem.fluents))
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        with OneshotPlanner(problem_kind=positive_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            positive_plan = planner.solve(positive_problem).plan
            new_plan = npr.rewrite_back_plan(positive_plan)
            with PlanValidator(problem_kind=problem.kind) as PV:
                self.assertTrue(PV.validate(problem, new_plan))

    def test_temporal_conditional(self):
        problem = self.problems['temporal_conditional'].problem
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        self.assertEqual(
            len(problem.fluents) + 3, len(positive_problem.fluents))
        self.assertTrue(problem.kind.has_negative_conditions())
        self.assertFalse(positive_problem.kind.has_negative_conditions())
        set_giver = problem.action('set_giver')
        new_actions = npr.get_transformed_actions(set_giver)
        self.assertEqual(len(new_actions), 1)
        self.assertNotEqual(new_actions[0], set_giver)
        take_ok = problem.action('take_ok')
        new_actions = npr.get_transformed_actions(take_ok)
        self.assertEqual(len(new_actions), 1)
        self.assertNotEqual(new_actions[0], take_ok)
        #lacking planners to test this with planner+plan_validator

    def test_ad_hoc_1(self):
        x = Fluent('x')
        y = Fluent('y')
        a = InstantaneousAction('a')
        a.add_precondition(And(Not(x), Not(y)))
        a.add_effect(x, True)
        problem = Problem('ad_hoc')
        problem.add_fluent(x)
        problem.add_fluent(y)
        problem.add_action(a)
        problem.set_initial_value(x, False)
        problem.set_initial_value(y, False)
        problem.add_goal(x)
        problem.add_goal(Not(y))
        problem.add_goal(Not(Iff(x, y)))
        problem.add_timed_goal(GlobalStartTiming(5), x)
        problem.add_timed_goal(
            ClosedTimeInterval(GlobalStartTiming(3), GlobalStartTiming(4)), x)
        npr = NegativeConditionsRemover(problem)
        with self.assertRaises(UPExpressionDefinitionError) as e:
            positive_problem = npr.get_rewritten_problem()
        self.assertIn(f"Expression: {Not(Iff(x, y))} is not in NNF.",
                      str(e.exception))

    def test_ad_hoc_2(self):
        x = Fluent('x')
        y = Fluent('y')
        t = GlobalStartTiming(5)
        problem = Problem('ad_hoc')
        problem.add_fluent(x)
        problem.add_fluent(y)
        problem.add_timed_effect(t, y, x, Not(y))
        problem.set_initial_value(x, True)
        problem.set_initial_value(y, False)
        problem.add_goal(x)
        npr = NegativeConditionsRemover(problem)
        positive_problem = npr.get_rewritten_problem()
        self.assertEqual(
            len(problem.fluents) + 1, len(positive_problem.fluents))
        y__negated__ = Fluent('ncrm_y_0')
        test_problem = Problem(positive_problem.name)
        test_problem.add_fluent(x)
        test_problem.add_fluent(y)
        test_problem.add_fluent(y__negated__)
        test_problem.add_timed_effect(t, y, x, y__negated__)
        test_problem.add_timed_effect(t, y__negated__, Not(x), y__negated__)
        test_problem.set_initial_value(x, True)
        test_problem.set_initial_value(y, False)
        test_problem.set_initial_value(y__negated__, True)
        test_problem.add_goal(x)
        self.assertEqual(positive_problem, test_problem)
Пример #5
0
class TestQuantifiersRemover(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind)
    def test_basic_exists(self):
        problem = self.problems['basic_exists'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        uq_problem_2 = qr.get_rewritten_problem()
        self.assertEqual(uq_problem, uq_problem_2)
        self.assertTrue(problem.kind.has_existential_conditions())
        self.assertFalse(uq_problem.kind.has_existential_conditions())
        self.assertEqual(len(problem.actions), len(uq_problem.actions))

        with OneshotPlanner(problem_kind=uq_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uq_plan = planner.solve(uq_problem).plan
            new_plan = qr.rewrite_back_plan(uq_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind)
    def test_basic_forall(self):
        problem = self.problems['basic_forall'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.kind.has_universal_conditions())
        self.assertFalse(uq_problem.kind.has_universal_conditions())
        self.assertEqual(len(problem.actions), len(uq_problem.actions))

        with OneshotPlanner(problem_kind=uq_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uq_plan = planner.solve(uq_problem).plan
            new_plan = qr.rewrite_back_plan(uq_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind.union(full_numeric_kind))
    def test_robot_locations_connected(self):
        problem = self.problems['robot_locations_connected'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.kind.has_existential_conditions())
        self.assertFalse(uq_problem.kind.has_existential_conditions())
        self.assertEqual(len(problem.actions), len(uq_problem.actions))

        with OneshotPlanner(problem_kind=uq_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uq_plan = planner.solve(uq_problem).plan
            new_plan = qr.rewrite_back_plan(uq_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind.union(full_numeric_kind))
    def test_robot_locations_visited(self):
        problem = self.problems['robot_locations_visited'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.kind.has_existential_conditions())
        self.assertFalse(uq_problem.kind.has_existential_conditions())
        self.assertTrue(problem.kind.has_universal_conditions())
        self.assertFalse(uq_problem.kind.has_universal_conditions())
        self.assertEqual(len(problem.actions), len(uq_problem.actions))

        with OneshotPlanner(problem_kind=uq_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uq_plan = planner.solve(uq_problem).plan
            new_plan = qr.rewrite_back_plan(uq_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))


    def test_hierarchical_blocks_world_exists(self):
        problem = self.problems['hierarchical_blocks_world_exists'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.kind.has_existential_conditions())
        self.assertFalse(uq_problem.kind.has_existential_conditions())
        self.assertTrue(uq_problem.kind.has_disjunctive_conditions())
        self.assertFalse(problem.kind.has_disjunctive_conditions())
        self.assertIn('(on(block_1, block_1) or on(block_2, block_1) or on(block_3, block_1))', str(uq_problem.goals))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(basic_temporal_kind))
    def test_timed_connected_locations(self):
        problem = self.problems['timed_connected_locations'].problem
        qr = QuantifiersRemover(problem)
        uq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.has_quantifiers())
        self.assertFalse(uq_problem.has_quantifiers())
        self.assertEqual(len(problem.actions), len(uq_problem.actions))

        with OneshotPlanner(problem_kind=uq_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uq_plan = planner.solve(uq_problem).plan
            new_plan = qr.rewrite_back_plan(uq_plan)
            for (s, a, d), (s_1, a_1, d_1) in zip(new_plan.actions, uq_plan.actions):
                self.assertEqual(s, s_1)
                self.assertEqual(d, d_1)
                self.assertIn(a.action, problem.actions)

    def test_ad_hoc_1(self):
        Obj = UserType('Obj')
        x = Fluent('x')
        y = Fluent('y', BoolType(), obj=Obj)
        o = Variable('o', Obj)
        a = InstantaneousAction('a')
        o1 = Object('o1', Obj)
        o2 = Object('o2', Obj)
        o3 = Object('o3', Obj)
        a.add_effect(x, True, Exists(FluentExp(y, [o]), o))
        da = DurativeAction('da')
        da.add_effect(StartTiming(), x, True, Forall(FluentExp(y, [o]), o))
        problem = Problem('ad_hoc')
        problem.add_fluent(x)
        problem.add_fluent(y)
        problem.add_action(a)
        problem.add_action(da)
        problem.add_object(o1)
        problem.add_object(o2)
        problem.add_object(o3)
        problem.add_timed_effect(GlobalStartTiming(4), x, Forall(FluentExp(y, [o]), o), Exists(FluentExp(y, [o]), o))
        problem.add_timed_goal(GlobalStartTiming(6), x)
        problem.add_timed_goal(OpenTimeInterval(GlobalStartTiming(8), GlobalStartTiming(10)), x)
        problem.set_initial_value(x, False)
        problem.set_initial_value(y(o1), True)
        problem.set_initial_value(y(o2), False)
        problem.set_initial_value(y(o3), True)
        problem.add_goal(x)
        qr = QuantifiersRemover(problem)
        unq_problem = qr.get_rewritten_problem()
        self.assertTrue(problem.has_quantifiers())
        self.assertFalse(unq_problem.has_quantifiers())
        unq_as = qr.get_transformed_actions(a)
        self.assertEqual(len(unq_as), 1)
        unq_a = unq_as[0]
        self.assertTrue(unq_a.effects[0].condition.is_or())
        unq_das = qr.get_transformed_actions(da)
        self.assertEqual(len(unq_das), 1)
        unq_da = unq_das[0]
        self.assertTrue((unq_da.effects[StartTiming()])[0].condition.is_and())
Пример #6
0
class TestConditionalEffectsRemover(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind)
    def test_basic_conditional(self):
        problem = self.problems['basic_conditional'].problem
        cer = ConditionalEffectsRemover(problem)
        unconditional_problem = cer.get_rewritten_problem()
        u_actions = unconditional_problem.actions
        a_x = problem.action("a_x")
        a_x_new_list = cer.get_transformed_actions(a_x)
        self.assertEqual(len(a_x_new_list), 1)
        new_action = unconditional_problem.action(a_x_new_list[0].name)
        y = FluentExp(problem.fluent("y"))
        a_x_e = a_x.effects
        new_action_e = new_action.effects

        self.assertEqual(len(u_actions), 2)
        self.assertEqual(problem.action("a_y"),
                         unconditional_problem.action("a_y"))
        self.assertTrue(a_x.is_conditional())
        self.assertFalse(unconditional_problem.has_action("a_x"))
        self.assertFalse(new_action.is_conditional())
        self.assertIn(y, new_action.preconditions)
        self.assertNotIn(y, a_x.preconditions)
        for e, ue in zip(a_x_e, new_action_e):
            self.assertEqual(e.fluent, ue.fluent)
            self.assertEqual(e.value, ue.value)
            self.assertFalse(ue.is_conditional())

        self.assertTrue(problem.kind.has_conditional_effects())
        self.assertFalse(unconditional_problem.kind.has_conditional_effects())
        for a in unconditional_problem.actions:
            self.assertFalse(a.is_conditional())

        with OneshotPlanner(
                problem_kind=unconditional_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uncond_plan = planner.solve(unconditional_problem).plan
            new_plan = cer.rewrite_back_plan(uncond_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(classical_kind)
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind)
    def test_complex_conditional(self):
        problem = self.problems['complex_conditional'].problem
        cer = ConditionalEffectsRemover(problem)
        unconditional_problem = cer.get_rewritten_problem()
        unconditional_problem_2 = cer.get_rewritten_problem()
        self.assertEqual(unconditional_problem, unconditional_problem_2)

        with OneshotPlanner(
                problem_kind=unconditional_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uncond_plan = planner.solve(unconditional_problem).plan
            new_plan = cer.rewrite_back_plan(uncond_plan)
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, new_plan))

    @skipIfNoOneshotPlannerForProblemKind(
        classical_kind.union(basic_temporal_kind))
    def test_temporal_conditional(self):
        problem = self.problems['temporal_conditional'].problem

        cer = ConditionalEffectsRemover(problem)
        unconditional_problem = cer.get_rewritten_problem()

        with OneshotPlanner(
                problem_kind=unconditional_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            uncond_plan = planner.solve(unconditional_problem).plan
            new_plan = cer.rewrite_back_plan(uncond_plan)
            for (s, a, d), (s_1, a_1, d_1) in zip(new_plan.actions,
                                                  uncond_plan.actions):
                self.assertEqual(s, s_1)
                self.assertEqual(d, d_1)
                self.assertIn(a.action, problem.actions)

    def test_ad_hoc_1(self):
        ct = GlobalStartTiming(2)
        x = unified_planning.model.Fluent('x')
        y = unified_planning.model.Fluent('y')
        problem = unified_planning.model.Problem('ad_hoc_1')
        problem.add_fluent(x, default_initial_value=True)
        problem.add_fluent(y, default_initial_value=True)
        problem.add_timed_effect(ct, y, Not(x), x)
        problem.add_goal(Not(y))
        cer = ConditionalEffectsRemover(problem)
        uncond_problem = cer.get_rewritten_problem()
        eff = uncond_problem.timed_effects[ct][0]
        self.assertFalse(eff.is_conditional())
        self.assertEqual(FluentExp(y), eff.fluent)
        self.assertEqual(And(Not(x), y), eff.value)

    def test_mockup_1(self):
        ct = GlobalStartTiming(2)
        x = unified_planning.model.Fluent('x', IntType())
        y = unified_planning.model.Fluent('y')
        problem = unified_planning.model.Problem('mockup_1')
        problem.add_fluent(x, default_initial_value=0)
        problem.add_fluent(y, default_initial_value=True)
        problem.add_timed_effect(ct, y, False)
        problem.add_timed_effect(ct, x, 5, y)
        cer = ConditionalEffectsRemover(problem)
        with self.assertRaises(UPProblemDefinitionError) as e:
            cer.get_rewritten_problem()
        self.assertIn(
            'The condition of effect: if y then x := 5\ncould not be removed without changing the problem.',
            str(e.exception))
Пример #7
0
class TestDisjunctiveConditionsRemover(TestCase):
    def setUp(self):
        TestCase.setUp(self)
        self.problems = get_example_problems()

    @skipIfNoOneshotPlannerForProblemKind(classical_kind.union(full_numeric_kind))
    @skipIfNoPlanValidatorForProblemKind(full_classical_kind.union(full_numeric_kind))
    def test_robot_locations_visited(self):
        problem = self.problems['robot_locations_visited'].problem

        dnfr = DisjunctiveConditionsRemover(problem)
        dnf_problem = dnfr.get_rewritten_problem()
        dnf_problem_2 = dnfr.get_rewritten_problem()
        self.assertEqual(dnf_problem, dnf_problem_2)

        is_connected = problem.fluent("is_connected")
        move = problem.action("move")
        robot, l_from, l_to = move.parameters
        self.assertEqual(len(problem.actions), 2)
        self.assertEqual(len(dnf_problem.actions), 3)

        cond = Or(is_connected(l_from, l_to), is_connected(l_to, l_from))
        self.assertIn(cond, move.preconditions)
        new_moves = dnfr.get_transformed_actions(move)
        for m in new_moves:
            self.assertNotIn(cond, m.preconditions)

        self.assertTrue(is_connected(l_from, l_to) in new_moves[0].preconditions or
                        is_connected(l_from, l_to) in new_moves[1].preconditions)
        if is_connected(l_from, l_to) in new_moves[0].preconditions:
            self.assertIn(is_connected(l_to, l_from), new_moves[1].preconditions)
            self.assertNotIn(is_connected(l_to, l_from), new_moves[0].preconditions)
            self.assertNotIn(is_connected(l_from, l_to), new_moves[1].preconditions)
        elif is_connected(l_from, l_to) in new_moves[1].preconditions:
            self.assertIn(is_connected(l_to, l_from), new_moves[0].preconditions)
            self.assertNotIn(is_connected(l_from, l_to), new_moves[0].preconditions)
            self.assertNotIn(is_connected(l_to, l_from), new_moves[1].preconditions)

        with OneshotPlanner(problem_kind=dnf_problem.kind) as planner:
            self.assertNotEqual(planner, None)
            dnf_plan = planner.solve(dnf_problem).plan
            plan = dnfr.rewrite_back_plan(dnf_plan)
            for ai in plan.actions:
                a = ai.action
                self.assertEqual(a, problem.action(a.name))
            with PlanValidator(problem_kind=problem.kind) as pv:
                self.assertTrue(pv.validate(problem, plan))

    def test_ad_hoc_1(self):
        #mockup problem
        a = Fluent('a')
        b = Fluent('b')
        c = Fluent('c')
        d = Fluent('d')
        act = InstantaneousAction('act')
        # (a <-> (b -> c)) -> (a & d)
        # In Dnf:
        # (!a & !b) | (!a & c) | (a & b & !c) | (a & d)
        cond = Implies(Iff(a, Implies(b, c)), And(a, d))
        possible_conditions = [{Not(a), Not(b)}, {Not(a), FluentExp(c)},
            {FluentExp(b), Not(c), FluentExp(a)}, {FluentExp(a), FluentExp(d)}]
        act.add_precondition(cond)
        act.add_effect(a, TRUE())
        problem = Problem('mockup')
        problem.add_fluent(a)
        problem.add_fluent(b)
        problem.add_fluent(c)
        problem.add_fluent(d)
        problem.add_action(act)
        problem.set_initial_value(a, True)
        problem.set_initial_value(b, False)
        problem.set_initial_value(c, True)
        problem.set_initial_value(d, False)
        problem.add_goal(a)
        dnfr = DisjunctiveConditionsRemover(problem)
        dnf_problem = dnfr.get_rewritten_problem()
        new_act = dnfr.get_transformed_actions(act)

        self.assertEqual(len(dnf_problem.actions), 4)
        self.assertEqual(len(new_act), 4)
        self.assertEqual(set(dnf_problem.actions), set(new_act))
        # Cycle over all actions. For every new action assume that the precondition is equivalent
        # to one in the possible_preconditions and that no other action has the same precondition.
        for i, new_action in enumerate(dnf_problem.actions):
            self.assertEqual(new_action.effects, act.effects)
            preconditions = set(new_action.preconditions)
            self.assertIn(preconditions, possible_conditions)
            for j, new_action_oth_acts in enumerate(dnf_problem.actions):
                preconditions_oth_acts = set(new_action_oth_acts.preconditions)
                if i != j:
                    self.assertNotEqual(preconditions, preconditions_oth_acts)

    def test_ad_hoc_2(self):
        #mockup problem
        a = Fluent('a')
        act = InstantaneousAction('act')
        cond = And(a, a)
        act.add_precondition(cond)
        act.add_effect(a, TRUE())
        problem = Problem('mockup')
        problem.add_fluent(a)
        problem.add_action(act)
        problem.set_initial_value(a, True)
        problem.add_goal(a)
        dnfr = DisjunctiveConditionsRemover(problem)
        dnf_problem = dnfr.get_rewritten_problem()
        new_act = dnfr.get_transformed_actions(act)

        self.assertEqual(len(dnf_problem.actions), 1)
        self.assertEqual(len(new_act), 1)
        self.assertEqual(set(dnf_problem.actions), set(new_act))
        new_action = new_act[0]
        self.assertEqual(new_action.effects, act.effects)
        preconditions = set(new_action.preconditions)
        self.assertEqual(preconditions, set((FluentExp(a), )))

    def test_temproal_mockup_1(self):
        # temporal mockup
        a = Fluent('a')
        b = Fluent('b')
        c = Fluent('c')
        d = Fluent('d')
        act = DurativeAction('act')
        # !a => (b | ((c <-> d) & d))
        # In Dnf:
        # a | b | (c & d)
        exp = Implies(Not(a), Or(b, And(Iff(c, d),d)))
        act.add_condition(StartTiming(), exp)
        act.add_condition(StartTiming(1), exp)
        act.add_condition(ClosedTimeInterval(StartTiming(2), StartTiming(3)), exp)
        act.add_condition(ClosedTimeInterval(StartTiming(4), StartTiming(5)), exp)
        act.add_effect(StartTiming(6), a, TRUE())

        problem = Problem('temporal_mockup')
        problem.add_fluent(a)
        problem.add_fluent(b)
        problem.add_fluent(c)
        problem.add_fluent(d)
        problem.add_action(act)
        problem.set_initial_value(a, False)
        problem.set_initial_value(b, False)
        problem.set_initial_value(c, True)
        problem.set_initial_value(d, False)
        problem.add_goal(a)
        dnfr = DisjunctiveConditionsRemover(problem)
        dnf_problem = dnfr.get_rewritten_problem()
        new_act = dnfr.get_transformed_actions(act)
        self.assertEqual(len(dnf_problem.actions), 81)
        self.assertEqual(len(new_act), 81)
        self.assertEqual(set(dnf_problem.actions), set(new_act))

    def test_temproal_mockup_2(self):
        # temporal mockup
        a = Fluent('a')
        b = Fluent('b')
        act = DurativeAction('act')
        exp = And(Not(a), b)
        act.add_condition(StartTiming(), exp)
        act.add_condition(StartTiming(1), exp)
        act.add_condition(ClosedTimeInterval(StartTiming(2), StartTiming(3)), exp)
        act.add_condition(ClosedTimeInterval(StartTiming(4), StartTiming(5)), exp)
        act.add_effect(StartTiming(6), a, TRUE())

        problem = Problem('temporal_mockup')
        problem.add_fluent(a)
        problem.add_fluent(b)
        problem.add_action(act)
        problem.set_initial_value(a, False)
        problem.set_initial_value(b, False)
        problem.add_goal(a)
        dnfr = DisjunctiveConditionsRemover(problem)
        dnf_problem = dnfr.get_rewritten_problem()
        new_act = dnfr.get_transformed_actions(act)
        self.assertEqual(len(dnf_problem.actions), 1)
        self.assertEqual(len(new_act), 1)
        self.assertEqual(set(dnf_problem.actions), set(new_act))