Beispiel #1
0
    def test_hoa(self):
        """Test that the HOA automaton is correct."""
        hoa_header = HOAHeader(
            identifier("v1"),
            Acceptance(Fin(0), identifier("co-Buchi")),
            nb_states=4,
            start_states={frozenset([0, 2]), frozenset([3])},
            propositions=(string("a"), string("b"), string("c")),
            name=string("(Fa & G(b&Xc)) | c"),
        )

        state_edges_dict = OrderedDict({})
        state_edges_dict[State(0, name=string("Fa"))] = [
            Edge([0], label=TRUE, acc_sig=frozenset({0})),
            Edge([1], label=LabelAtom(0)),
        ]
        state_edges_dict[State(1, name=string("true"))] = [Edge([1], label=TRUE)]
        state_edges_dict[State(2, name=string("G(b&Xc)"))] = [
            Edge([2, 3], label=LabelAtom(1))
        ]
        state_edges_dict[State(3, name=string("c"))] = [Edge([1], label=LabelAtom(2))]
        hoa_body = HOABody(state_edges_dict)

        hoa_obj = HOA(hoa_header, hoa_body)
        assert self.hoa_obj == hoa_obj
Beispiel #2
0
    def test_hoa(self):
        """Test that the HOA automaton is correct."""
        hoa_header = HOAHeader(
            identifier("v1"),
            Acceptance(Inf(0), identifier("Buchi")),
            nb_states=3,
            start_states={frozenset([0])},
            propositions=(string("a"),),
        )

        state_edges_dict = OrderedDict({})
        state_edges_dict[State(0)] = [
            Edge([1], label=LabelAtom(0)),
            Edge([2], label=~(LabelAtom(0))),
        ]
        state_edges_dict[State(1)] = [
            Edge([1], label=LabelAtom(0), acc_sig=frozenset({0})),
            Edge(
                [2],
                label=~(LabelAtom(0)),
                acc_sig=frozenset({0}),
            ),
        ]
        state_edges_dict[State(2)] = [
            Edge([1], label=LabelAtom(0)),
            Edge([2], label=~LabelAtom(0)),
        ]
        hoa_body = HOABody(state_edges_dict)

        hoa_obj = HOA(hoa_header, hoa_body)
        assert self.hoa_obj == hoa_obj
Beispiel #3
0
 def test_hoa_header(self):
     """Test that the HOA header is correct."""
     hoa_header = HOAHeader(
         identifier("v1"),
         Acceptance(Inf(0), identifier("Buchi")),
         nb_states=2,
         start_states={frozenset([0]), frozenset([1])},
         propositions=(string("a"),),
         name=string("GFa"),
     )
     assert self.hoa_header == hoa_header
Beispiel #4
0
 def test_hoa_header(self):
     """Test that the HOA header is correct."""
     hoa_header = HOAHeader(
         identifier("v1"),
         Acceptance(Inf(0) & Inf(1), identifier("generalized-Buchi"), (2,)),
         nb_states=1,
         start_states={frozenset([0])},
         propositions=(string("a"), string("b")),
         name=string("GFa & GFb"),
     )
     assert self.hoa_header == hoa_header
Beispiel #5
0
    def test_hoa(self):
        """Test that the HOA automaton is correct."""
        hoa_header = HOAHeader(
            identifier("v1"),
            Acceptance(Inf(0), identifier("Buchi")),
            start_states={frozenset([0])},
            propositions=(string("a"), string("b")),
            name=string("GFa | G(b <-> Xa)"),
            properties=[
                identifier("explicit-labels"),
                identifier("trans-labels"),
                identifier("trans-acc"),
            ],
        )

        state_edges_dict = OrderedDict({})
        state_edges_dict[State(0)] = [
            Edge([1], label=TRUE),
            Edge([2], label=LabelAtom(1)),
            Edge([3], label=~(LabelAtom(1))),
        ]
        state_edges_dict[State(1, name=string("GFa"))] = [
            Edge([1], label=LabelAtom(0), acc_sig=frozenset({0})),
            Edge([1], label=~(LabelAtom(0))),
        ]
        state_edges_dict[State(2, name=string("a & G(b <-> Xa)"))] = [
            Edge(
                [2],
                label=LabelAtom(0) & LabelAtom(1),
                acc_sig=frozenset({0}),
            ),
            Edge(
                [3],
                label=LabelAtom(0) & ~LabelAtom(1),
                acc_sig=frozenset({0}),
            ),
        ]
        state_edges_dict[State(3, name=string("!a & G(b <-> Xa)"))] = [
            Edge(
                [2],
                label=~LabelAtom(0) & LabelAtom(1),
                acc_sig=frozenset({0}),
            ),
            Edge(
                [3],
                label=~LabelAtom(0) & ~LabelAtom(1),
                acc_sig=frozenset({0}),
            ),
        ]
        hoa_body = HOABody(state_edges_dict)

        hoa_obj = HOA(hoa_header, hoa_body)
        assert self.hoa_obj == hoa_obj
Beispiel #6
0
 def test_acceptance(self):
     """Test that the acceptance condition is correct."""
     assert nb_accepting_sets(self.hoa_header.acceptance.condition) == 2
     assert self.hoa_header.acceptance == Acceptance(
         Fin(0) & Inf(1) & TRUE, identifier("Rabin"), (1,)
     )
Beispiel #7
0
    def header(self, args):
        """Parse the 'header' node.

        The header is a list of header-items (a HEADERNAME followed by some data).
        Except for the "HOA:" item, which should always come first,
        the items may occur in any order. Some HEADERNAMEs have predefined
        semantics (and might be mandatory) as specified below. This format also
        makes provision of additional (unspecified) header names to be used.

        Any given HEADERNAME should occur at most once, except for Start:, Alias:, and properties:.
        The case of the HEADERNAME's initial is used to specify whether tools may
        safely ignore a header item they do not support: header items whose name
        start with an upper-case letter are expected to influence the semantic of
        the automaton: tools should at least warn about any such HEADERNAME they do not understand.
        A HEADERNAME whose initial is lowercase may be safely ignored without affecting the semantics.

        Headers items HOA:, and Acceptance: must always be present.
        """
        format_version = identifier(args[0])

        headertype2value: Dict[HeaderItemType, Any] = {}
        custom_headers: Optional[Dict[identifier,
                                      List[HEADER_VALUES]]] = dict()
        for header_item_type, value in args[1:]:
            if header_item_type in {
                    HeaderItemType.ALIAS,
                    HeaderItemType.PROPERTIES,
            }:
                headertype2value.setdefault(
                    header_item_type,
                    []).extend(value if isinstance(value, list) else [value])
            elif header_item_type == HeaderItemType.START_STATES:
                headertype2value.setdefault(header_item_type, set()).add(value)
            elif header_item_type != HeaderItemType.HEADERNAME:
                assert (
                    header_item_type not in headertype2value
                ), f"Header {header_item_type.value} occurred more than once."
                headertype2value[header_item_type] = value
            else:
                key, arg_list = value
                assert (key not in custom_headers
                        ), f"Custom header {key} occurred more than once."
                custom_headers[key] = list(
                    map(hoa_header_value.to_header_value, arg_list))

        assert (HeaderItemType.ACCEPTANCE
                in headertype2value), "'Acceptance:' must always be present."
        acceptance_condition = headertype2value[HeaderItemType.ACCEPTANCE]
        acceptance_args = headertype2value.get(HeaderItemType.ACCEPTANCE_NAME,
                                               None)
        if acceptance_args is not None:
            acceptance = Acceptance(
                acceptance_condition,
                acceptance_args[0],
                tuple(
                    map(acceptance_parameter.to_parameter_value,
                        acceptance_args[1:])),
            )
        else:
            acceptance = Acceptance(acceptance_condition)

        return HOAHeader(
            format_version,
            acceptance=acceptance,
            nb_states=headertype2value.get(HeaderItemType.NUM_STATES, None),
            start_states=headertype2value.get(HeaderItemType.START_STATES,
                                              None),
            aliases=headertype2value.get(HeaderItemType.ALIAS, None),
            propositions=headertype2value.get(HeaderItemType.PROPOSITIONS,
                                              None),
            tool=headertype2value.get(HeaderItemType.TOOL, None),
            name=headertype2value.get(HeaderItemType.NAME, None),
            properties=headertype2value.get(HeaderItemType.PROPERTIES, None),
            headernames=custom_headers if custom_headers else None,
        )