Exemple #1
0
    def calculateCore(self):
        # Don't let simultaneous calculations occur if events are triggered too fast
        if not self.coreCalculationLock.acquire(False):
            print "WARNING: Skipping core calculation because already busy with one."
            return

        # TODO: actually cache trans CNF
        # TODO: support SLURP parser

        ltl_current = fsa.stateToLTL(self.env_aut.current_state, swap_io=True).strip()
        next_state = copy.deepcopy(self.env_aut.current_state.transitions[0])
        next_state.inputs.update(self.actuatorStates)
        next_state.inputs.update(self.regionToBitEncoding(self.dest_region))
        ltl_next = fsa.stateToLTL(next_state, use_next=True, swap_io=True).strip()
        ltl_topo = self.spec['Topo'].replace('\n','').replace('\t','').strip()
        ltl_trans = [s.strip() for s in self.spec['SysTrans'].split('\n')]
        # note: strip()s make canonical (i.e. terminate in &, no whitespace on either side)
        guilty_ltl = self.compiler.unsatCores(self.compiler._getPicosatCommand(), ltl_topo, ltl_current, [ltl_next] + ltl_trans, 1, 1)
        print "Guilty LTL: ", guilty_ltl

        guilty_spec = []
        if self.proj.compile_options["parser"] == "structured":
            if guilty_ltl is not None:
                for ltl_frag, line_num in self.compiler.LTL2SpecLineNumber.iteritems():
                    ltl_frags_canonical = [s.strip() for s in ltl_frag.replace("\t","").split('\n')]
                    if not set(guilty_ltl).isdisjoint(ltl_frags_canonical):
                        guilty_spec.append(self.compiler.proj.specText.split("\n")[line_num-1])
        elif self.proj.compile_options["parser"] == "slurp":
            for ltl_frag in guilty_ltl:
                canonical_ltl_frag = ltl_frag.lstrip().rstrip("\n\t &")
                try:
                    guilty_clean = self.compiler.reversemapping[canonical_ltl_frag]
                except KeyError:
                    print "WARNING: LTL fragment {!r} not found in canon_ltl->LTL mapping".format(canonical_ltl_frag)
                    continue

                chunks = line_to_chunks(guilty_clean, self.tracebackChunks)
                if chunks:
                    guilty_spec.append('{} (Because you said "{}")'.format(chunks[0].explanation.replace("'",""), chunks[0].input))
                else:
                    print "WARNING: Canonical LTL fragment {!r} not found in spec->LTL mapping".format(guilty_clean)

        if self.spec['Topo'].replace('\n','').replace('\t','').strip() in guilty_ltl:
            guilty_spec.append("(topological constraints)")
    
        print "Guilty Spec: ", guilty_spec

        self.coreCalculationLock.release()

        return guilty_spec
Exemple #2
0
    def getCurrentStateAsLTL(self, include_env=False):
        """ Return a boolean formula (as a string) capturing the current discrete state of the system (and, optionally, the environment as well) """

        if self.aut:
            # If we have current state in the automaton, use it (since it can capture
            # state of internal propositions).
            return fsa.stateToLTL(self.aut.current_state, include_env=include_env)
        else:
            # If we have no automaton yet, determine our state manually
            # TODO: support env
            # TODO: look at self.hsub.executing_config.initial_truths and pose
            return ""
Exemple #3
0
    def getCurrentStateAsLTL(self, include_env=False):
        """ Return a boolean formula (as a string) capturing the current discrete state of the system (and, optionally, the environment as well) """

        if self.aut:
            # If we have current state in the automaton, use it (since it can capture
            # state of internal propositions).
            return fsa.stateToLTL(self.aut.current_state, include_env=include_env)
        else:
            # If we have no automaton yet, determine our state manually
            # TODO: support env
            # TODO: look at self.proj.currentConfig.initial_truths and pose
            return ""
Exemple #4
0
    def calculateCore(self):
        # Don't let simultaneous calculations occur if events are triggered too fast
        if not self.coreCalculationLock.acquire(False):
            print "WARNING: Skipping core calculation because already busy with one."
            return

        # TODO: actually cache trans CNF
        # TODO: support SLURP parser

        ltl_current = fsa.stateToLTL(self.env_aut.current_state,
                                     swap_io=True).strip()
        next_state = copy.deepcopy(self.env_aut.current_state.transitions[0])
        next_state.inputs.update(self.actuatorStates)
        next_state.inputs.update(self.regionToBitEncoding(self.dest_region))
        ltl_next = fsa.stateToLTL(next_state, use_next=True,
                                  swap_io=True).strip()
        ltl_topo = self.spec['Topo'].replace('\n', '').replace('\t',
                                                               '').strip()
        ltl_trans = [s.strip() for s in self.spec['SysTrans'].split('\n')]
        # note: strip()s make canonical (i.e. terminate in &, no whitespace on either side)
        guilty_ltl = self.compiler.unsatCores(
            self.compiler._getPicosatCommand(), ltl_topo, ltl_current,
            [ltl_next] + ltl_trans, 1, 1)
        print "Guilty LTL: ", guilty_ltl

        guilty_spec = []
        if self.proj.compile_options["parser"] == "structured":
            if guilty_ltl is not None:
                for ltl_frag, line_num in self.compiler.LTL2SpecLineNumber.iteritems(
                ):
                    ltl_frags_canonical = [
                        s.strip()
                        for s in ltl_frag.replace("\t", "").split('\n')
                    ]
                    if not set(guilty_ltl).isdisjoint(ltl_frags_canonical):
                        guilty_spec.append(
                            self.compiler.proj.specText.split("\n")[line_num -
                                                                    1])
        elif self.proj.compile_options["parser"] == "slurp":
            for ltl_frag in guilty_ltl:
                canonical_ltl_frag = ltl_frag.lstrip().rstrip("\n\t &")
                try:
                    guilty_clean = self.compiler.reversemapping[
                        canonical_ltl_frag]
                except KeyError:
                    print "WARNING: LTL fragment {!r} not found in canon_ltl->LTL mapping".format(
                        canonical_ltl_frag)
                    continue

                chunks = line_to_chunks(guilty_clean, self.tracebackChunks)
                if chunks:
                    guilty_spec.append('{} (Because you said "{}")'.format(
                        chunks[0].explanation.replace("'", ""),
                        chunks[0].input))
                else:
                    print "WARNING: Canonical LTL fragment {!r} not found in spec->LTL mapping".format(
                        guilty_clean)

        if self.spec['Topo'].replace('\n',
                                     '').replace('\t',
                                                 '').strip() in guilty_ltl:
            guilty_spec.append("(topological constraints)")

        print "Guilty Spec: ", guilty_spec

        self.coreCalculationLock.release()

        return guilty_spec