예제 #1
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)
예제 #2
0
  def initialize(self):
      if type(self.network) == ParseTpnClass:
          self.network = Tpnu.from_tpn_autogen(self.network)
      elif type(self.network) == Tpnu:
          pass
      else:
          raise Exception("Wrong type of network passed to MIP encode")
      self.network.initialize()
      self.num_nodes = self.network.num_nodes
      self.l = {}  # lower bounds
      self.u = {}  # upper bounds
      self.w = {}  # wait
      self.b = {}  # binary variables
      self.x = {}  # binary variables
 
      self.calc_distance()
      
      if self.objective_type == ObjectiveType.MIN_COST:
          self.rl = {}
          self.ru = {}
          self.tl = {}
          self.tu = {}
      for e in self.network.temporal_constraints.values():
          #if e.activated:
              self.l[(e.fro, e.to)] = LinExpr()
              self.u[(e.fro, e.to)] = LinExpr()
예제 #3
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)
예제 #4
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
예제 #5
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
예제 #6
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)
예제 #7
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)
예제 #8
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
예제 #9
0
    def check(network):
        if type(network) == ParseTpnClass:
            network = Tpnu.from_tpn_autogen(network)
        elif type(network) == Tpnu:
            pass
        else:
            raise Exception("Wrong type of network passed to temporal consistency checking")

        network.initialize()
        alg = NrgativeCycleDetection()

        return alg.check(network)
예제 #10
0
    def check(network):
        if type(network) == ParseTpnClass:
            network = Tpnu.from_tpn_autogen(network)
        elif type(network) == Tpnu:
            pass
        else:
            raise Exception("Wrong type of network passed to strong controllability checking")

        network.initialize()
        alg = Vidal99Reduction()

        return alg.check(network)
예제 #11
0
    def check(network):
        if type(network) == ParseTpnClass:
            network = Tpnu.from_tpn_autogen(network)
        elif type(network) == Tpnu:
            pass
        else:
            raise Exception(
                "Wrong type of network passed to strong controllability checking"
            )

        network.initialize()
        alg = Vidal99Reduction()

        return alg.check(network)
예제 #12
0
    def check(network):
        if type(network) == ParseTpnClass:
            network = Tpnu.from_tpn_autogen(network)
        elif type(network) == Tpnu:
            pass
        else:
            raise Exception(
                "Wrong type of network passed to temporal consistency checking"
            )

        network.initialize()
        alg = NrgativeCycleDetection()

        return alg.check(network)
예제 #13
0
    def check(network, solver='morris_n4_dc'):
        if solver == 'morris_n4_dc':
            alg = MorrisN4Dc()
            if type(network) == ParseTpnClass:
                network = Tpnu.from_tpn_autogen(network)
            elif type(network) == Tpnu:
                pass
            else:
                raise Exception("Wrong type of network passed to dc checking")

            network.initialize()
            return alg.check(network)

        else:
            raise Exception('Unknown dynamic controllability solver')
예제 #14
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
예제 #15
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)
예제 #16
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)
예제 #17
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)