示例#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
    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()))
示例#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))
示例#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
    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)
示例#6
0
#  tpnu = Tpnu.from_tpn_autogen()

print(tpnu)
print(tpnu.decision_variables)
print(tpnu.num_nodes)
print(tpnu.temporal_constraints)
print(tpnu.chance_constraints)
print(tpnu.node_number_to_id)
print(tpnu.start_node)

f_type = FeasibilityType.DYNAMIC_CONTROLLABILITY
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))