def test_sudoku(self):
        try:
            handler = DesktopHandler(ClingoDesktopService(self.getPath()))

            inp = ASPInputProgram()

            for i in range(9):
                for j in range(9):
                    if (self.inputMatrix[i][j] != 0):
                        inp.add_object_input(Cell(i, j,
                                                  self.inputMatrix[i][j]))

            inp.add_files_path(
                os.path.join("..", "..", "..", "..", "test-resources", "asp",
                             "sudoku"))

            handler.add_program(inp)

            mc = MyCallback()

            handler.start_async(mc)

            mc. await ()

            out = mc.get_output()

            # out = handler.startSync()

            self.assertIsNotNone(out)

            self.assertTrue(isinstance(out, Output),
                            "Error, result object is not Output")

            self.assertIsNone(
                out.get_errors(),
                "Found error in the Plan\n" + str(out.get_errors()))

            if (len(out.get_answer_sets()) == 0):
                return

            ans = out.get_answer_sets()[0]

            for obj in ans.get_atoms():
                self.inputMatrix[obj.get_row()][
                    obj.get_column()] = obj.get_value()

            tmp = ""
            for i in range(9):
                for j in range(9):
                    tmp += str(self.inputMatrix[i][j]) + " "
                print(tmp)
                tmp = ""

        except Exception as e:
            self.fail("Exception " + str(e))
    def test_sudoku(self):
        try:
            handler = DesktopHandler(ClingoDesktopService(self.getPath()))

            inp = ASPInputProgram()

            for i in range(9):
                for j in range(9):
                    if (self.inputMatrix[i][j] != 0):
                        inp.add_object_input(
                            Cell(i, j, self.inputMatrix[i][j]))

            inp.add_files_path(os.path.join(
                "..", "..", "..", "..", "test-resources", "asp", "sudoku"))

            handler.add_program(inp)

            mc = MyCallback()

            handler.start_async(mc)

            mc.await()

            out = mc.get_output()

            # out = handler.startSync()

            self.assertIsNotNone(out)

            self.assertTrue(isinstance(out, Output),
                            "Error, result object is not Output")

            self.assertIsNone(
                out.get_errors(), "Found error in the Plan\n" + str(out.get_errors()))

            if (len(out.get_answer_sets()) == 0):
                return

            ans = out.get_answer_sets()[0]

            for obj in ans.get_atoms():
                self.inputMatrix[obj.get_row()][obj.get_column()
                                                ] = obj.get_value()

            tmp = ""
            for i in range(9):
                for j in range(9):
                    tmp += str(self.inputMatrix[i][j]) + " "
                print(tmp)
                tmp = ""

        except Exception as e:
            self.fail("Exception " + str(e))
Ejemplo n.º 3
0
    def core(self, results_sizes, base_path):

        print("Testing " + str(len(results_sizes)) + " files for " + base_path)

        for i in range(1, len(results_sizes) + 1):
            try:
                plan = None

                handler = DesktopHandler(SPDDesktopService())

                input_program_domain = PDDLInputProgram(PDDLProgramType.DOMAIN)

                input_program_domain.add_files_path(base_path + "domain.pddl")

                inputProgramProblem = PDDLInputProgram(PDDLProgramType.PROBLEM)

                if i < 10:
                    problem = base_path + "p" + "0" + str(i) + ".pddl"
                else:
                    problem = base_path + "p" + str(i) + ".pddl"

                self.assertTrue(os.path.isfile(problem),
                                "File not found: " + problem)

                inputProgramProblem.add_files_path(problem)

                handler.add_program(input_program_domain)

                handler.add_program(inputProgramProblem)

                PDDLMapper.get_instance().register_class(PickUp)

                self.assertIsNone(plan)

                mc = MyCallback()

                handler.start_async(mc)

                mc. await ()

                plan = mc.get_output()

                self.assertIsNotNone(plan)

                tmp = ""
                for action in plan.get_actions():
                    tmp = tmp + action.get_name() + ","
                print(tmp)

                if results_sizes[i - 1] != 0:
                    self.assertTrue(
                        not plan.get_errors(), "Found error in the Plan " +
                        problem + "\n" + plan.get_errors())

                self.assertEqual(results_sizes[i - 1], len(plan.get_actions()))

                for obj in plan.get_actions_objects():
                    if isinstance(obj, PickUp):
                        print(obj.get_block())

                time.sleep(0.5)

            except Exception as e:
                self.fail("Exception " + str(e))
Ejemplo n.º 4
0
            self.lock.wait()
        self.lock.release()

    def callback(self, o):
        if (not isinstance(o, AnswerSets)):
            return
        self.ans = o
        self.__count_down()

    def getOutput(self):
        return self.ans


mc = MyCalback()

handler.start_async(mc)

print("asincrono")

mc. await ()

out = mc.getOutput()

# out = handler.startSync()

if not isinstance(out, Output):
    raise "error"

if (len(out.get_answer_sets()) != 0):
    ans = out.get_answer_sets()[0]
    def core(self, results_sizes, base_path):

        print("Testing " + str(len(results_sizes)) + " files for " + base_path)

        for i in range(1, len(results_sizes) + 1):
            try:
                plan = None

                handler = DesktopHandler(SPDDesktopService())

                input_program_domain = PDDLInputProgram(PDDLProgramType.DOMAIN)

                input_program_domain.add_files_path(base_path + "domain.pddl")

                inputProgramProblem = PDDLInputProgram(PDDLProgramType.PROBLEM)

                if i < 10:
                    problem = base_path + "p" + "0" + str(i) + ".pddl"
                else:
                    problem = base_path + "p" + str(i) + ".pddl"

                self.assertTrue(os.path.isfile(problem),
                                "File not found: " + problem)

                inputProgramProblem.add_files_path(problem)

                handler.add_program(input_program_domain)

                handler.add_program(inputProgramProblem)

                PDDLMapper.get_instance().register_class(PickUp)

                self.assertIsNone(plan)

                mc = MyCallback()

                handler.start_async(mc)

                mc.await()

                plan = mc.get_output()

                self.assertIsNotNone(plan)

                tmp = ""
                for action in plan.get_actions():
                    tmp = tmp + action.get_name() + ","
                print(tmp)

                if results_sizes[i - 1] != 0:
                    self.assertTrue(not plan.get_errors(
                    ), "Found error in the Plan " + problem + "\n" + plan.get_errors())

                self.assertEqual(results_sizes[i - 1], len(plan.get_actions()))

                for obj in plan.get_actions_objects():
                    if isinstance(obj, PickUp):
                        print(obj.get_block())

                time.sleep(0.5)

            except Exception as e:
                self.fail("Exception " + str(e))