def test_tangiblereachabilitygraph_calc(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     input_log = os.path.join(INPUT_DATA_DIR, "running-example.xes")
     log = xes_importer.import_log(input_log)
     net, initial_marking, final_marking = alpha_miner.apply(log)
     s_map = stochastic_map.get_map_from_log_and_net(log, net, initial_marking, final_marking)
     reachab_graph = construct_reachability_graph(net, initial_marking)
     tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(reachab_graph,
                                                                                          s_map)
     viz = ts_vis_factory.apply(tang_reach_graph, parameters={"format": "svg", "show_labels": True})
     del viz
     # gets the Q matrix assuming exponential distributions
     q_matrix = ctmc.get_q_matrix_from_tangible_exponential(tang_reach_graph, s_map)
     # pick a state to start from
     states = sorted(list(tang_reach_graph.states), key=lambda x: x.name)
     state = states[0]
     transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix,
                                                                                        state, 86400)
     del transient_result
     transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix,
                                                                                        state, 864000)
     del transient_result
     steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix(tang_reach_graph, q_matrix)
     del steady_state
Ejemplo n.º 2
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.xes")
    log = xes_importer.apply(log_path)
    # obtain Petri net through Alpha Miner
    net, initial_marking, final_marking = alpha_miner.apply(log)
    # obtain stochastic information for transitions in the model
    s_map = stochastic_map.get_map_from_log_and_net(
        log,
        net,
        initial_marking,
        final_marking,
        force_distribution="EXPONENTIAL")
    # export the current stochastic Petri net
    petri_exporter.export_net(net,
                              initial_marking,
                              "example.pnml",
                              final_marking=final_marking,
                              stochastic_map=s_map)
    # re-import the current stochastic Petri net from file
    net, initial_marking, final_marking, s_map = petri_importer.import_net(
        "example.pnml", return_stochastic_information=True)
    # remove temporary file
    os.remove("example.pnml")
    # gets the reachability graph from the Petri net
    reachab_graph = construct_reachability_graph(net, initial_marking)
    # get the tangible reachability graph from the reachability graph and the stochastic map
    tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(
        reachab_graph, s_map)
    # visualize the tangible reachability graph on the screen
    viz = ts_vis_factory.apply(tang_reach_graph,
                               parameters={
                                   "format": "svg",
                                   "show_labels": True,
                                   "show_names": True
                               })
    ts_vis_factory.view(viz)
    # gets the Q matrix assuming exponential distributions
    q_matrix = ctmc.get_q_matrix_from_tangible_exponential(
        tang_reach_graph, s_map)
    # pick a state to start from
    states = sorted(list(tang_reach_graph.states), key=lambda x: x.name)
    state = states[0]
    print("\n\nstarting from state = ", state.name)
    # do transient analysis after 1 day
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(
        tang_reach_graph, q_matrix, state, 86400)
    print("\nprobability for each state after 1 day = ", transient_result)
    # do transient analysis after 10 days
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(
        tang_reach_graph, q_matrix, state, 864000)
    print("\nprobability for each state after 10 days = ", transient_result)
    # do transient analysis after 100 days
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(
        tang_reach_graph, q_matrix, state, 8640000)
    print("\nprobability for each state after 100 days = ", transient_result)
    steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix(
        tang_reach_graph, q_matrix)
    print("\nsteady state = ", steady_state)
Ejemplo n.º 3
0
def transient_analysis_from_petri_net_and_smap(net,
                                               im,
                                               s_map,
                                               delay,
                                               parameters=None):
    """
    Gets the transient analysis from a Petri net, a stochastic map and a delay

    Parameters
    -------------
    log
        Event log
    delay
        Time delay
    parameters
        Parameters of the algorithm

    Returns
    -------------
    transient_result
        Transient analysis result
    """
    if parameters is None:
        parameters = {}
    # gets the reachability graph from the Petri net
    reachab_graph = construct_reachability_graph(net, im)
    states_reachable_from_start = set()
    for trans in reachab_graph.transitions:
        if str(trans.from_state) == "start1":
            states_reachable_from_start.add(trans.to_state)
    # get the tangible reachability graph from the reachability graph and the stochastic map
    tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(
        reachab_graph, s_map)
    # gets the Q matrix assuming exponential distributions
    q_matrix = get_q_matrix_from_tangible_exponential(tang_reach_graph, s_map)
    states = sorted(list(tang_reach_graph.states), key=lambda x: x.name)
    states_vector = np.zeros((1, len(states)))

    for state in states_reachable_from_start:
        states_vector[
            0, states.index(state)] = 1.0 / len(states_reachable_from_start)

    probabilities = transient_analysis_from_tangible_q_matrix_and_states_vector(
        tang_reach_graph, q_matrix, states_vector, delay)

    color_dictionary = get_color_from_probabilities(probabilities)

    return tang_reach_graph, probabilities, color_dictionary
Ejemplo n.º 4
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.csv")
    dataframe = pandas_df_imp.import_dataframe_from_path(log_path)
    activities_count = dict(dataframe.groupby("concept:name").size())
    [dfg_frequency, dfg_performance] = df_statistics.get_dfg_graph(dataframe, measure="both",
                                                                   perf_aggregation_key="mean")
    net, initial_marking, final_marking = alpha_miner.apply_dfg(dfg_frequency)
    spaths = get_shortest_paths(net)
    aggregated_statistics = get_decorations_from_dfg_spaths_acticount(net, dfg_performance,
                                                                      spaths,
                                                                      activities_count,
                                                                      variant="performance")
    # obtain stochastic information for transitions in the model
    s_map = stochastic_map.get_map_exponential_from_aggstatistics(aggregated_statistics)
    # gets the reachability graph from the Petri net
    reachab_graph = construct_reachability_graph(net, initial_marking)
    # get the tangible reachability graph from the reachability graph and the stochastic map
    tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(reachab_graph, s_map)
    # visualize the tangible reachability graph on the screen
    viz = ts_vis_factory.apply(tang_reach_graph, parameters={"format": "svg", "show_labels": True, "show_names": True})
    ts_vis_factory.view(viz)
    # gets the Q matrix assuming exponential distributions
    q_matrix = ctmc.get_q_matrix_from_tangible_exponential(tang_reach_graph, s_map)
    # pick a state to start from
    states = sorted(list(tang_reach_graph.states), key=lambda x: x.name)
    state = states[0]
    print("\n\nstarting from state = ", state.name)
    # do transient analysis after 1 day
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix,
                                                                                       state, 86400)
    print("\nprobability for each state after 1 day = ", transient_result)
    # do transient analysis after 10 days
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix,
                                                                                       state, 864000)
    print("\nprobability for each state after 10 days = ", transient_result)
    # do transient analysis after 100 days
    transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix,
                                                                                       state, 8640000)
    print("\nprobability for each state after 100 days = ", transient_result)
    steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix(tang_reach_graph, q_matrix)
    print("\nsteady state = ", steady_state)