def execute_script():
    log = pm4py.read_xes(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    net, im, fm = inductive_miner.apply(
        log, variant=inductive_miner.Variants.IM_CLEAN)
    idx = 0
    # try to resolve the marking equation to find an heuristics and possible a vector of transitions
    # leading from im to fm
    sync_net, sync_im, sync_fm = pm4py.construct_synchronous_product_net(
        log[idx], net, im, fm)
    me_solver = marking_equation.build(sync_net, sync_im, sync_fm)
    h, x = me_solver.solve()
    firing_sequence, reach_fm1, explained_events = me_solver.get_firing_sequence(
        x)
    print("for trace at index " + str(idx) + ": marking equation h = ", h)
    print("x vector reaches fm = ", reach_fm1)
    print("firing sequence = ", firing_sequence)
    # it fails and the value of heuristics is low
    #
    # now let's try with extended marking equation to find the heuristics and the vector!
    eme_solver = extended_marking_equation.build(log[idx], sync_net, sync_im,
                                                 sync_fm)
    h, x = eme_solver.solve()
    # the heuristics is much better
    firing_sequence, reach_fm2, explained_events = eme_solver.get_firing_sequence(
        x)
    print(
        "for trace at index " + str(idx) + ": extended marking equation h = ",
        h)
    print("x vector reaches fm = ", reach_fm2)
    print("firing sequence = ", firing_sequence)
Exemple #2
0
def solve_marking_equation(petri_net: PetriNet, initial_marking: Marking,
                           final_marking: Marking, cost_function: Dict[PetriNet.Transition, float] = None) -> float:
    """
    Solves the marking equation of a Petri net.
    The marking equation is solved as an ILP problem.
    An optional transition-based cost function to minimize can be provided as well.

    Parameters
    ---------------
    petri_net
        Petri net
    initial_marking
        Initial marking
    final_marking
        Final marking
    cost_function
        optional cost function to use when solving the marking equation.

    Returns
    ----------------
    h_value
        Heuristics value calculated resolving the marking equation
    """
    from pm4py.algo.analysis.marking_equation import algorithm as marking_equation

    if cost_function is None:
        cost_function = dict()
        for t in petri_net.transitions:
            cost_function[t] = 1

    me = marking_equation.build(petri_net, initial_marking, final_marking, parameters={'costs': cost_function})
    return marking_equation.get_h_value(me)