예제 #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)
예제 #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)
예제 #3
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
예제 #4
0
파일: io_test.py 프로젝트: yu-peng/cdru
    def assert_tpn_result(self, example_file, expected_result):

        tpn_obj = Tpn.parseTPN(join(self.examples_dir, example_file))
        tpnu_obj = Tpnu.from_tpn_autogen(tpn_obj)

        if tpnu_obj is not None:
            self.assertEqual(expected_result, True)

        if tpnu_obj is None:
            self.assertEqual(expected_result, False)
예제 #5
0
    def assert_tpn_result(self, example_file, expected_result):

        tpn_obj = Tpn.parseTPN(join(self.examples_dir, example_file))
        tpnu_obj = Tpnu.from_tpn_autogen(tpn_obj)

        if tpnu_obj is not None:
            self.assertEqual(expected_result, True)

        if tpnu_obj is None:
            self.assertEqual(expected_result, False)
예제 #6
0
파일: tests.py 프로젝트: yu-peng/cdru
    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
예제 #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
예제 #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
예제 #9
0
파일: tests.py 프로젝트: Optimised/cdru
    def assert_kirk_result(self, example_file, expected_result):
        for solver in DynamicControllability.SOLVERS:
            obj = Tpn.parse(join(self.examples_dir, example_file))
            tpnu = Tpnu.from_tpn_autogen(obj)
            search_problem = SearchProblem(tpnu)
            search_problem.initialize()

            solution = search_problem.next_solution()

            print("----------------------------------------")
            if solution is not None:
                print(example_file)
                solution.pretty_print()
            else:
                print(example_file)
                print(None)
                search_problem.pretty_print()
            is_feasible = solution is not None
            self.assertEqual(is_feasible, expected_result)
예제 #10
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)
예제 #11
0
파일: io_test.py 프로젝트: Optimised/cdru
__author__ = 'yupeng'

from tpn import Tpn
from temporal_network.tpnu import Tpnu

if __name__ == '__main__':
    # Load the tpn from file
    obj = Tpn.parse(r'C:\Users\yupeng\Downloads\document.tpn')
    tpnu = Tpnu.from_tpn_autogen(obj)
예제 #12
0
파일: io_test.py 프로젝트: Optimised/cdru
__author__ = "yupeng"

from tpn import Tpn


if __name__ == "__main__":
    # Load the tpn from file
    obj = Tpn.parse(r"C:\Users\yupeng\Downloads\document.tpn")
    print("TPN parsed successfully")
    Tpn.write(obj, r"C:\Users\yupeng\Downloads\document_out.tpn")
예제 #13
0
__author__ = 'yupeng'

from tpn import Tpn

if __name__ == '__main__':
    # Load the tpn from file
    obj = Tpn.parseTPN(r'C:\Users\yupeng\Downloads\document.tpn')
    print("TPN parsed successfully")
    Tpn.writeTPN(obj, r'C:\Users\yupeng\Downloads\document_out.tpn')
예제 #14
0
파일: tests.py 프로젝트: Optimised/cdru
 def assert_dc_result(self, example_file, expected_result):
     for solver in DynamicControllability.SOLVERS:
         obj = Tpn.parse(join(self.examples_dir, example_file))
         conflict = DynamicControllability.check(obj, solver=solver)
         is_dynamically_controllable = conflict is None
         self.assertEqual(is_dynamically_controllable, expected_result)