Example #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)
Example #2
0
    def solve(tpnu,solver,objType,startTime,filename,container):
        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
        container.update(solution.json_description(filename,BenchmarkMBTA.getSolveName(solver),runtime.total_seconds()))
Example #3
0
    def solve(tpnu,solver,objType,feaType,ccType,startTime,filename,container):
        if solver == SolverType.CDRU:
            search_problem = SearchProblem(tpnu,feaType,objType,ccType)
            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
        container.update(solution.json_description(filename,BenchmarkAUV.getSolveName(solver),runtime.total_seconds(),search_problem.candidates_dequeued))
Example #4
0
    def solve(tpnu, solver, objType, startTime, filename, container):
        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
        container.update(
            solution.json_description(filename, BenchmarkMBTA.getSolveName(solver), runtime.total_seconds())
        )
Example #5
0
    def solve(tpnu, solver, objType, feaType, ccType, startTime, filename,
              container):
        if solver == SolverType.CDRU:
            search_problem = SearchProblem(tpnu, feaType, objType, ccType)
            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
        container.update(
            solution.json_description(filename,
                                      BenchmarkAUV.getSolveName(solver),
                                      runtime.total_seconds(),
                                      search_problem.candidates_dequeued))
Example #6
0
    def compare_cdru_mip(self, example_file, f_type, o_type, c_type,
                         expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        search_problem = SearchProblem(tpnu, f_type, o_type, c_type)
        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)

        # test mip_encode

        tpnu = self.getProblemFromFile(path)
        mip_solver = MipEncode(tpnu, o_type)
        solution2 = mip_solver.mip_solver()
        diff = 0
        if fabs(solution.utility - solution2.utility) >= 1e-2 and not (
                solution.utility >= 100 and solution2.utility >= 100):
            diff = round(solution.utility - solution2.utility, 4)
        self.ofile = open('output.txt', 'a')
        self.ofile.write('%s    %s    %s    %s\n' %
                         (path, solution2.utility, solution.utility, diff))
        self.ofile.close()
        print("----------------------------------------")
        if solution2 is not None:
            print(example_file)
            solution2.pretty_print()
        else:
            print(example_file)
            print(None)
Example #7
0
    def assert_mip_result(self, example_file, o_type, expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        startTime = datetime.now()
        mip_solver = MipEncode(tpnu, o_type)
        solution = mip_solver.mip_solver()

        runtime = datetime.now() - startTime

        print("----------------------------------------")
        if solution is not None:
            print(example_file)
            solution.pretty_print()
            # print(solution.json_print(example_file,"CDRU+PuLP",runtime.total_seconds()))
        else:
            print(example_file)
            print(None)
            #search_problem.pretty_print()
        is_feasible = solution is not None
        self.assertEqual(is_feasible, expected_result)
Example #8
0
    def assert_mip_result(self, example_file, o_type, expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        startTime = datetime.now()
        mip_solver = MipEncode(tpnu,o_type)
        solution = mip_solver.mip_solver()

        runtime = datetime.now() - startTime

        print("----------------------------------------")
        if solution is not None:
            print(example_file)
            solution.pretty_print()
            # print(solution.json_print(example_file,"CDRU+PuLP",runtime.total_seconds()))
        else:
            print(example_file)
            print(None)
            #search_problem.pretty_print()
        is_feasible = solution is not None
        self.assertEqual(is_feasible, expected_result)
Example #9
0
    def compare_cdru_mip(self, example_file, f_type, o_type, c_type, expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        search_problem = SearchProblem(tpnu,f_type,o_type,c_type)
        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)

        # test mip_encode

        tpnu = self.getProblemFromFile(path)
        mip_solver = MipEncode(tpnu,o_type)
        solution2 = mip_solver.mip_solver()
        diff = 0
        if fabs(solution.utility - solution2.utility) >= 1e-2 and not(solution.utility >= 100 and solution2.utility >= 100):
            diff = round(solution.utility - solution2.utility,4)
        self.ofile = open('output.txt','a')
        self.ofile.write('%s    %s    %s    %s\n'%(path, solution2.utility, solution.utility, diff))
        self.ofile.close()
        print("----------------------------------------")
        if solution2 is not None:
            print(example_file)
            solution2.pretty_print()
        else:
            print(example_file)
            print(None)
Example #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)