Esempio n. 1
0
    def test_standard_properties(self):
        gspn_parser = stormpy.gspn.GSPNParser()
        gspn = gspn_parser.parse(
            get_example_path("gspn", "philosophers_4.pnpro"))
        assert gspn.get_name() == "Philosophers4"
        assert gspn.get_number_of_timed_transitions() == 12
        assert gspn.get_number_of_immediate_transitions() == 0
        assert gspn.get_number_of_places() == 16

        # Build jani program
        jani_builder = stormpy.gspn.GSPNToJaniBuilder(gspn)
        jani_program = jani_builder.build()

        # Use standard properties
        properties = jani_builder.create_deadlock_properties(jani_program)

        # Instantiate constants
        jani_program, properties = stormpy.preprocess_symbolic_input(
            jani_program, properties, "TIME_BOUND=1")
        jani_program = jani_program.as_jani_model()

        # Build model
        # Leads to incorrect result
        #model = stormpy.build_model(jani_program, properties)
        model = stormpy.build_model(jani_program)

        # Model checking
        initial_state = model.initial_states[0]
        assert initial_state == 0
        result = stormpy.model_checking(model, properties[0])
        assert math.isclose(result.at(initial_state), 1.0)
        result = stormpy.model_checking(model, properties[1])
        assert math.isclose(result.at(initial_state), 0.09123940783)
        result = stormpy.model_checking(model, properties[2])
        assert math.isclose(result.at(initial_state), 5.445544554455446)
Esempio n. 2
0
    def test_custom_property(self):
        gspn_parser = stormpy.gspn.GSPNParser()
        gspn = gspn_parser.parse(
            get_example_path("gspn", "philosophers_4.pnpro"))
        assert gspn.get_name() == "Philosophers4"
        assert gspn.get_number_of_timed_transitions() == 12
        assert gspn.get_number_of_immediate_transitions() == 0
        assert gspn.get_number_of_places() == 16

        # Build jani program
        jani_builder = stormpy.gspn.GSPNToJaniBuilder(gspn)
        jani_program = jani_builder.build()

        # Set properties
        properties = stormpy.parse_properties_for_jani_model(
            'P=? [F<=10 eating1=1]', jani_program)

        # Build model
        model = stormpy.build_model(jani_program, properties)

        # Model checking
        initial_state = model.initial_states[0]
        assert initial_state == 0
        result = stormpy.model_checking(model, properties[0])
        assert math.isclose(result.at(initial_state), 0.4372171069840004)
Esempio n. 3
0
    def test_export_to_pnpro(self, tmpdir):
        builder = stormpy.gspn.GSPNBuilder()
        builder.set_name("gspn_test")

        # add places and transitions
        id_p_0 = builder.add_place()
        id_p_1 = builder.add_place(initial_tokens=3,
                                   name="place_1",
                                   capacity=2)
        id_ti_0 = builder.add_immediate_transition(priority=0,
                                                   weight=0.5,
                                                   name="ti_0")
        id_tt_0 = builder.add_timed_transition(priority=0,
                                               rate=0.5,
                                               num_servers=2,
                                               name="tt_0")

        gspn = builder.build_gspn()

        export_file = os.path.join(str(tmpdir), "gspn.pnpro")

        # export gspn to pnml
        gspn.export_gspn_pnpro_file(export_file)

        # import gspn
        gspn_parser = stormpy.gspn.GSPNParser()
        gspn_import = gspn_parser.parse(export_file)

        # test imported gspn
        assert gspn_import.get_name() == gspn.get_name()
        assert gspn_import.get_number_of_timed_transitions(
        ) == gspn.get_number_of_timed_transitions()
        assert gspn_import.get_number_of_immediate_transitions(
        ) == gspn.get_number_of_immediate_transitions()
        assert gspn_import.get_number_of_places() == gspn.get_number_of_places(
        )

        p_0 = gspn_import.get_place(id_p_0)
        assert p_0.get_id() == id_p_0
        p_1 = gspn_import.get_place(id_p_1)
        assert p_1.get_name() == "place_1"
        # todo capacity info lost
        # assert p_1.get_capacity() == 2
        # assert p_1.has_restricted_capacity() == True
        assert p_1.get_number_of_initial_tokens() == 3

        ti_0 = gspn_import.get_immediate_transition("ti_0")
        assert ti_0.get_id() == id_ti_0
        tt_0 = gspn_import.get_timed_transition("tt_0")
        assert tt_0.get_id() == id_tt_0
Esempio n. 4
0
    def test_build_gspn(self):
        gspn_name = "gspn_test"
        builder = stormpy.gspn.GSPNBuilder()

        id_p_0 = builder.add_place()
        id_p_1 = builder.add_place(initial_tokens=1)
        id_p_2 = builder.add_place(initial_tokens=0, name="place_2")
        id_p_3 = builder.add_place(capacity=2,
                                   initial_tokens=3,
                                   name="place_3")
        p_layout = stormpy.gspn.LayoutInfo(1, 2)
        builder.set_place_layout_info(id_p_0, p_layout)

        id_ti_0 = builder.add_immediate_transition(priority=1,
                                                   weight=0.5,
                                                   name="ti_0")
        id_ti_1 = builder.add_immediate_transition()

        id_tt_0 = builder.add_timed_transition(priority=2,
                                               rate=0.4,
                                               name="tt_0")
        id_tt_1 = builder.add_timed_transition(priority=0,
                                               rate=0.5,
                                               num_servers=2,
                                               name="tt_1")

        t_layout = stormpy.gspn.LayoutInfo(1, 2)
        builder.set_transition_layout_info(id_ti_0, t_layout)

        # add arcs
        builder.add_input_arc(id_p_0, id_ti_1, multiplicity=2)
        builder.add_input_arc("place_2", "ti_0", multiplicity=2)

        builder.add_output_arc(id_ti_1, id_p_2, multiplicity=2)
        builder.add_output_arc("tt_0", "place_3", multiplicity=2)

        builder.add_inhibition_arc(id_p_2, id_tt_0, multiplicity=2)
        builder.add_inhibition_arc("place_3", "tt_0", multiplicity=2)

        builder.add_normal_arc("place_3", "tt_0", multiplicity=2)
        builder.add_normal_arc("tt_0", "place_3", multiplicity=2)

        # test gspn composition
        builder.set_name(gspn_name)
        gspn = builder.build_gspn()

        assert gspn.get_name() == gspn_name
        assert gspn.is_valid()
        assert gspn.get_number_of_immediate_transitions() == 2
        assert gspn.get_number_of_timed_transitions() == 2
        assert gspn.get_number_of_places() == 4

        assert len(gspn.get_places()) == 4
        assert len(gspn.get_immediate_transitions()) == 2
        assert len(gspn.get_timed_transitions()) == 2

        # test places
        p_0 = gspn.get_place(id_p_0)
        assert p_0.get_id() == id_p_0

        p_1 = gspn.get_place(id_p_1)
        assert p_1.get_id() == id_p_1
        assert p_1.get_number_of_initial_tokens() == 1

        p_2 = gspn.get_place(id_p_2)
        assert p_2.get_id() == id_p_2
        assert p_2.get_name() == "place_2"

        p_3 = gspn.get_place(id_p_3)
        assert p_3.get_name() == "place_3"
        assert p_3.get_capacity() == 2
        assert p_3.get_number_of_initial_tokens() == 3
        assert p_3.has_restricted_capacity()

        # test transitions
        ti_0 = gspn.get_immediate_transition("ti_0")
        assert ti_0.get_id() == id_ti_0
        assert ti_0.get_weight() == 0.5
        assert ti_0.get_priority() == 1

        tt_0 = gspn.get_timed_transition("tt_0")
        assert tt_0.get_id() == id_tt_0
        assert tt_0.get_rate() == 0.4
        assert tt_0.get_priority() == 2

        tt_1 = gspn.get_timed_transition("tt_1")
        assert tt_1.get_id() == id_tt_1
        assert tt_1.get_number_of_servers() == 2

        # test new name
        gspn_new_name = "new_name"
        gspn.set_name(gspn_new_name)
        assert gspn.get_name() == gspn_new_name