Esempio n. 1
0
    def consistent(self,candidate):
        # Check if this candidate results
        # in a consistent temporal network
        # print('------Consistency check')
        # candidate.pretty_print()

        self.implement(candidate)
        # return either a conflict, or None
        # run the dc checking algorithm
        # TODO: fix the conflict extraction code
        conflict = None

        if self.feasibility_type == FeasibilityType.CONSISTENCY:
            conflict = TemporalConsistency.check(self.tpnu)
        elif self.feasibility_type == FeasibilityType.STRONG_CONTROLLABILITY:
            conflict = StrongControllability.check(self.tpnu)
        elif self.feasibility_type == FeasibilityType.DYNAMIC_CONTROLLABILITY:
            conflict = DynamicControllability.check(self.tpnu)
        else:
            raise Exception("Unknown feasibility type: " + str(self.feasibility_type))

        # the conflict is a collection of dictionaries
        # each represents a negative cycle
        if conflict is None:
            return None
        else:
            # reformat the conflict
            kirk_conflict = Conflict()
            kirk_conflict.add_negative_cycles(conflict,self.tpnu)
            # kirk_conflict.pretty_print()
            # print("Conflict size: " + str(len(kirk_conflict.negative_cycles)))
            return kirk_conflict
Esempio n. 2
0
    def consistent(self, candidate):
        # Check if this candidate results
        # in a consistent temporal network
        # print('------Consistency check')
        # candidate.pretty_print()

        self.implement(candidate)
        # return either a conflict, or None
        # run the dc checking algorithm
        # TODO: fix the conflict extraction code
        conflict = None

        if self.feasibility_type == FeasibilityType.CONSISTENCY:
            conflict = TemporalConsistency.check(self.tpnu)
        elif self.feasibility_type == FeasibilityType.STRONG_CONTROLLABILITY:
            conflict = StrongControllability.check(self.tpnu)
        elif self.feasibility_type == FeasibilityType.DYNAMIC_CONTROLLABILITY:
            conflict = DynamicControllability.check(self.tpnu)
        else:
            raise Exception("Unknown feasibility type: " +
                            str(self.feasibility_type))

        # the conflict is a collection of dictionaries
        # each represents a negative cycle
        if conflict is None:
            return None
        else:
            # reformat the conflict
            kirk_conflict = Conflict()
            kirk_conflict.add_negative_cycles(conflict, self.tpnu)
            # kirk_conflict.pretty_print()
            # print("Conflict size: " + str(len(kirk_conflict.negative_cycles)))
            return kirk_conflict
Esempio n. 3
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)
Esempio n. 4
0
 def test_nozeronode(self):
     with self.assertRaises(Exception):
         stnu = Stnu()
         stnu.num_nodes = 1
         stnu.controllable_edges.append(StnuEdge(0, 1, 100, 200, 'my-id'))
         DynamicControllability.check(stnu, solver='morris_n4_dc')
Esempio n. 5
0
 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)
Esempio n. 6
0
 def test_nozeronode(self):
     with self.assertRaises(Exception):
         stnu = Stnu()
         stnu.num_nodes = 1
         stnu.controllable_edges.append(StnuEdge(0, 1, 100, 200, 'my-id'))
         DynamicControllability.check(stnu, solver='morris_n4_dc')