예제 #1
0
    def assert_cdru_result(self, example_file, f_type, o_type, c_type,
                           expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        startTime = datetime.now()
        search_problem = SearchProblem(tpnu, f_type, o_type, c_type)
        search_problem.initialize()
        # pr = cProfile.Profile()
        # pr.enable()
        solution = search_problem.next_solution()
        # pr.disable()
        # # after your program ends
        # pr.print_stats(sort="cumtime")

        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(),
                                    search_problem.candidates_dequeued))

            print("Conflicts " + str(len(search_problem.known_conflicts)))
            print("Candidates " + str(search_problem.candidates_dequeued))
        else:
            print(example_file)
            print(None)
            search_problem.pretty_print()
        is_feasible = solution is not None
        self.assertEqual(is_feasible, expected_result)
예제 #2
0
파일: tests.py 프로젝트: yu-peng/cdru
    def assert_cdru_result(self, example_file, f_type, o_type, c_type, expected_result):
        path = join(self.examples_dir, example_file)
        tpnu = self.getProblemFromFile(path)

        startTime = datetime.now()
        search_problem = SearchProblem(tpnu,f_type,o_type,c_type)
        search_problem.initialize()
        # pr = cProfile.Profile()
        # pr.enable()
        solution = search_problem.next_solution()
        # pr.disable()
        # # after your program ends
        # pr.print_stats(sort="cumtime")

        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(),search_problem.candidates_dequeued))

            print("Conflicts " + str(len(search_problem.known_conflicts)))
            print("Candidates " + str(search_problem.candidates_dequeued))
        else:
            print(example_file)
            print(None)
            search_problem.pretty_print()
        is_feasible = solution is not None
        self.assertEqual(is_feasible, expected_result)
예제 #3
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)
예제 #4
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)
예제 #5
0
파일: tests.py 프로젝트: yu-peng/cdru
    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)
예제 #6
0
o_type = ObjectiveType.MIN_COST
c_type = ChanceConstrained.OFF

startTime = datetime.now()
search_problem = SearchProblem(tpnu, f_type, o_type, c_type)
search_problem.initialize()

# Find all solutions
solution = search_problem.next_solution()
while solution is not None:
    runtime = datetime.now() - startTime
    print("----------------------------------------")
    print("Solution found")
    #  print(example_file)
    solution.pretty_print()
    print(
        solution.json_print("example-tpnu", "CDRU+PuLP",
                            runtime.total_seconds(),
                            search_problem.candidates_dequeued))

    print("Conflicts " + str(len(search_problem.known_conflicts)))
    print("Candidates " + str(search_problem.candidates_dequeued))

    solution = search_problem.next_solution()

print("==========================================")
print("Solution not found")
#  print(example_file)
print(None)
search_problem.pretty_print()