Exemplo 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
Exemplo 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
Exemplo n.º 3
0
    def assert_consistency_result(self, example_file, expected_result):
        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 = TemporalConsistency.check(tpnu)

        # if conflict is not None:
        #     kirk_conflict = Conflict()
        #     kirk_conflict.add_negative_cycles(conflict,tpnu)
        #     kirk_conflict.pretty_print()

        is_strongly_controllable = conflict is None
        self.assertEqual(is_strongly_controllable, expected_result)