Esempio n. 1
0
    def runTest(directory,file,solver,objType):
        path = join(directory, file)

        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path + " is neither a CCTP nor a TPN")

        startTime = datetime.now()
        if solver == SolverType.CDRU:
            search_problem = SearchProblem(tpnu,FeasibilityType.DYNAMIC_CONTROLLABILITY,objType)
            search_problem.initialize()
            solution = search_problem.next_solution()
        elif solver == SolverType.MIP:
            mip_solver = MipEncode(tpnu,objType)
            solution = mip_solver.mip_solver()
        else:
            raise Exception('Unknown solver type')

        runtime = datetime.now() - startTime

        print("----------------------------------------")
        if solution is not None:
            print(file + " solved in " + str(runtime))
        else:
            print(file + " not solved in " + str(runtime))

        return solution.json_description(file,BenchmarkRCPSP.getSolveName(solver),runtime.total_seconds(),search_problem.candidates_dequeued)
Esempio n. 2
0
    def assert_dc_result(self, example_file, expected_result):
        for solver in DynamicControllability.SOLVERS:

            path = join(self.examples_dir, example_file)

            if Tpnu.isCCTP(path):
                tpnu = Tpnu.parseCCTP(path)
            elif Tpnu.isTPN(path):
                obj = Tpn.parseTPN(join(self.examples_dir, example_file))
                tpnu = Tpnu.from_tpn_autogen(obj)
            else:
                raise Exception("Input file " + path +
                                " is neither a CCTP nor a TPN")

            # for tc in tpnu.temporal_constraints:
            #     tpnu.temporal_constraints[tc].pretty_print()

            conflict = DynamicControllability.check(tpnu, solver=solver)

            # if conflict is not None:
            #     kirk_conflict = Conflict()
            #     kirk_conflict.add_negative_cycles(conflict,tpnu)
            #     kirk_conflict.pretty_print()

            is_dynamically_controllable = conflict is None
            self.assertEqual(is_dynamically_controllable, expected_result)
Esempio n. 3
0
    def assert_cctp_result(self, example_file, expected_result):

        obj = Tpnu.parseCCTP(join(self.examples_dir, example_file))
        if obj is not None:
            self.assertEqual(expected_result, True)

        if obj is None:
            self.assertEqual(expected_result, False)
Esempio n. 4
0
    def assert_cctp_result(self, example_file, expected_result):

        obj = Tpnu.parseCCTP(join(self.examples_dir, example_file))
        if obj is not None:
            self.assertEqual(expected_result, True)

        if obj is None:
            self.assertEqual(expected_result, False)
Esempio n. 5
0
    def runTest(directory, file, solver, objType, feaType, ccType):
        path = join(directory, file)
        print("----------------------------------------")
        print("Solving: " + file)

        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path +
                            " is neither a CCTP nor a TPN")

        startTime = datetime.now()

        manager = Manager()
        container = manager.SolutionContainer()

        p = Process(target=BenchmarkAUV.solve,
                    name="Solve",
                    args=(
                        tpnu,
                        solver,
                        objType,
                        feaType,
                        ccType,
                        startTime,
                        file,
                        container,
                    ))
        p.start()
        p.join(30)
        if p.is_alive():
            print("Solver is running... No solution found in time limit...")
            # Terminate foo
            p.terminate()
            p.join()

        solution = container.get_value()
        runtime = datetime.now() - startTime

        if solution is not None:
            print(file + " solved in " + str(runtime))
        else:
            print(file + " not solved in " + str(runtime))

        if solution is not None:
            return solution
        else:
            result = {}
            result["TestName"] = file
            result["Solver"] = BenchmarkAUV.getSolveName(solver)
            result["Runtime"] = runtime.total_seconds()
            result["Error"] = "No Solution Found"

            return result
Esempio n. 6
0
    def getProblemFromFile(self, path):
        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path + " is neither a CCTP nor a TPN")

        return tpnu
Esempio n. 7
0
    def getProblemFromFile(self, path):
        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path +
                            " is neither a CCTP nor a TPN")

        return tpnu
Esempio n. 8
0
    def runTest(directory,file,solver,objType,feaType,ccType):
        path = join(directory, file)
        print("----------------------------------------")
        print("Solving: " + file)

        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path + " is neither a CCTP nor a TPN")

        startTime = datetime.now()

        manager = Manager()
        container = manager.SolutionContainer()

        p = Process(target=BenchmarkAUV.solve, name="Solve", args=(tpnu,solver,objType,feaType,ccType,startTime,file,container,))
        p.start()
        p.join(30)
        if p.is_alive():
            print("Solver is running... No solution found in time limit...")
            # Terminate foo
            p.terminate()
            p.join()

        solution = container.get_value()
        runtime = datetime.now() - startTime

        if solution is not None:
            print(file + " solved in " + str(runtime))
        else:
            print(file + " not solved in " + str(runtime))

        if solution is not None:
            return solution
        else:
            result = {}
            result["TestName"] = file
            result["Solver"] = BenchmarkAUV.getSolveName(solver)
            result["Runtime"] = runtime.total_seconds()
            result["Error"] = "No Solution Found"

            return result
Esempio n. 9
0
    def runTest(directory, file, solver, objType):
        path = join(directory, file)

        if Tpnu.isCCTP(path):
            tpnu = Tpnu.parseCCTP(path)
        elif Tpnu.isTPN(path):
            obj = Tpn.parseTPN(path)
            tpnu = Tpnu.from_tpn_autogen(obj)
        else:
            raise Exception("Input file " + path +
                            " is neither a CCTP nor a TPN")

        startTime = datetime.now()
        if solver == SolverType.CDRU:
            search_problem = SearchProblem(
                tpnu, FeasibilityType.DYNAMIC_CONTROLLABILITY, objType)
            search_problem.initialize()
            solution = search_problem.next_solution()
        elif solver == SolverType.MIP:
            mip_solver = MipEncode(tpnu, objType)
            solution = mip_solver.mip_solver()
        else:
            raise Exception('Unknown solver type')

        runtime = datetime.now() - startTime

        print("----------------------------------------")
        if solution is not None:
            print(file + " solved in " + str(runtime))
        else:
            print(file + " not solved in " + str(runtime))

        return solution.json_description(file,
                                         BenchmarkRCPSP.getSolveName(solver),
                                         runtime.total_seconds(),
                                         search_problem.candidates_dequeued)