Exemplo n.º 1
0
def make_interval_product(aut_names, productname):
    coll = collection.Collection()
    auts = load_interval_automata(collection.Collection(), aut_names, False, True)
    product = IntervalSynchronousProduct(auts, coll)
    saver = IntervalAutomatonSaver()
    product.save_as_dot("C.dot")
    saver.save(product, productname)
Exemplo n.º 2
0
def make_weighted_projection(aut_name, evt_names, result_fname):
    """
    Perform projection over a weighted automaton.

    @param aut_name: Filename of the automaton to project.
    @type  aut_name: L{WeightedAutomaton}

    @param evt_names: Comma seperated list of event names to preserve.
    @type  evt_names: C{str}

    @param result_fname: Filename for writing the resulting weighted automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started weighted projection computation (version %s)" %
                      automata.version)
    coll = collection.Collection()

    waut = load_weighted_automaton(coll, aut_name, False, False)
    events = frontend.get_events(coll, evt_names)

    waut2 = weighted_projection.weighted_projection(waut, events)

    frontend.dump_stats("Computed weighted projection", waut2)
    save_weighted_automaton(waut2, "Projected automaton is saved in %s",
                            result_fname)
Exemplo n.º 3
0
def load_test_mult_supervisors(plant_list, supervisors, evt_pairs,
                               comp_mut_ex):
    coll = collection.Collection()
    plant_list = weighted_frontend.load_weighted_automata(
        coll, plant_list, False, True)
    events = coll.events
    C1_events = set([events[evt] for evt in events if evt.startswith("C1")])
    C2_events = set([events[evt] for evt in events if evt.startswith("C2")])
    C3_events = set([events[evt] for evt in events if evt.startswith("C3")])
    plant_list = []
    aut = weighted_structure.WeightedAutomaton(C1_events, coll)
    aut.initial = aut.add_new_state(True, 0)
    for evt in C1_events:
        aut.add_edge_data(aut.initial, aut.initial, evt, 1)
    plant_list.append(aut)
    aut = weighted_structure.WeightedAutomaton(C2_events, coll)
    aut.initial = aut.add_new_state(True, 0)
    for evt in C2_events:
        aut.add_edge_data(aut.initial, aut.initial, evt, 1)
    plant_list.append(aut)
    aut = weighted_structure.WeightedAutomaton(C3_events, coll)
    aut.initial = aut.add_new_state(True, 0)
    for evt in C3_events:
        aut.add_edge_data(aut.initial, aut.initial, evt, 1)
    plant_list.append(aut)
    result = taskresource.compute_custom_eventdata_extended(
        plant_list, evt_pairs, comp_mut_ex)
    supervisors = frontend.load_automata(coll, supervisors, False, True)
    #tau_abstraction.testpath_not_weighted(plant_list, supervisors[0], None)
    eventdata, cliques = result
    for event in eventdata:
        eventdata[event].matHat = maxplus.matrix_to_vector(
            eventdata[event].matHat)
    calcpath_mult(supervisors, eventdata, len(cliques))
Exemplo n.º 4
0
def make_time_optimal_supervisor(comp_names, req_names, evt_pairs, sup_name):
    """
    Compute a time optimal supervisor.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of C{str}

    @param req_names: Available requirements (unweighted automata).
    @type  req_names: C{List} of C{str}

    @param evt_pairs: Additional event pairs (eg "{(a, b), (c, e)}", "type1",
                      or "type2")
    @type  evt_pairs: C{str}

    @param sup_name: Name of resulting supervisor (unweighted automaton).
    @type  sup_name: C{str}
    """
    common.print_line("Started time optimal supervisor computations "
                      "(version %s)" % automata.version)
    coll = collection.Collection()
    comp_list = load_weighted_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)

    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)
    result = compute_weight.compute_time_optimal_supervisor(
        comp_list, req_list, evt_pairs)

    if result is None:
        common.print_line("Time optimal supervisor cannot be computed.")
        return
    else:
        sup, min_weight = result
        common.print_line("Minimum makespan is %d" % min_weight)
        frontend.dump_stats("Computed time optimal supervisor", sup)
        frontend.save_automaton(sup, "Supervisor is saved in %s\n", sup_name)
Exemplo n.º 5
0
def make_nonconflicting_check(aut_fnames, use_heuristic):
    """
    Verify whether the automata do not conflict with each other.

    @param aut_fnames: Comma-seperated list of automata filenames.
    @type  aut_fnames: C{str}

    @param use_heuristic: Compute a smart order for the automata (rather than
                          use the supplied order).
    @type  use_heuristic: C{str}

    @return: Indication that no conflict has been found (all is ok).
    @rtype:  C{bool}
    """
    common.print_line("Started nonconflicting check (version %s)"
                        % automata.version)
    coll = collection.Collection()
    auts = load_automata(coll, aut_fnames, False, False)

    if parse_boolean(use_heuristic):
        auts = abstraction.order_automata(auts)
    # else, user has supplied the automata in the right order.

    result = abstraction.nonconflicting_check(auts)

    if result:
        print "nonconflicting_check: HOLDS"
    else:
        print "nonconflicting_check: CONFLICT FOUND"

    return result
Exemplo n.º 6
0
def make_natural_projection(aut_name, evt_names, result_fname):
    """
    Perform projection over a language.

    @param aut_name: Filename of the automaton to project.
    @type  aut_name: L{Automaton}

    @param evt_names: Comma seperated list of event names to preserve.
    @type  evt_names: C{str}

    @param result_fname: Filename for writing the resulting automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started natural projection computation (version %s)"
                        % automata.version)
    coll = collection.Collection()

    aut = load_automaton(coll, aut_name, False, False)
    events = get_events(coll, evt_names)

    aut2 = supervisor.unweighted_determinization(aut)
    result = supervisor.natural_projection_map(aut2, events)[0]

    dump_stats("Computed projection", result)
    save_automaton(result, "Projected automaton is saved in %s",  result_fname)
Exemplo n.º 7
0
def make_weighted_supervisor(comp_name, req_name, sup_name):
    """
    Compute a weighted supervisor.

    @param comp_name: Available component (weighted automaton).
    @type  comp_name: C{str}

    @param req_name: Available requirement (unweighted automaton).
    @type  req_name: C{str}

    @param sup_name: Name of resulting supervisor (unweighted automaton).
    @type  sup_name: C{str}
    """
    common.print_line("Started weighted supervisor computation "
                      "(version %s)" % automata.version)
    coll = collection.Collection()
    comp = load_weighted_automaton(coll, comp_name, False, True)
    req = frontend.load_automaton(coll, req_name, False, True)

    sup = weighted_supervisor.compute_weighted_supervisor(comp, req)
    if sup is None:
        common.print_line("Weighted supervisor cannot be computed.")
        return
    else:
        frontend.dump_stats("Computed weighted supervisor", sup)
        frontend.save_automaton(sup, "Supervisor is saved in %s\n", sup_name)
Exemplo n.º 8
0
def make_observer_check(aut_name, evt_names):
    """
    Perform observer_check of the automaton stored in L{aut_name}.

    @param aut_name: Filename of the automaton to abstract.
    @type  aut_name: L{Automaton}

    @param evt_names: Comma seperated list of event names to preserve.
    @type  evt_names: C{str}
    """
    common.print_line("Started observer-check computation (version %s)"
                        % automata.version)
    coll = collection.Collection()

    aut = load_automaton(coll, aut_name, True, False)
    events = get_events(coll, evt_names)
    bad_events = abstraction.observer_check(aut, events)

    if len(bad_events) == 0:
        common.print_line("Observer-check property HOLDS")
    else:
        if len(bad_events) == 1:
            evt_text = "event"
        else:
            evt_text = "events"

        evts = ", ".join(event.name for event in bad_events)
        common.print_line("Observer-check property does not hold "
                          "due to %s %s" % (evt_text, evts))
Exemplo n.º 9
0
def make_sequential_abstraction(aut_fnames, evt_names, result_fname):
    """
    Perform sequential abstraction on a number of automata.

    @param aut_fnames: Comma-seperated list of automata filenames.
    @type  aut_fnames: C{str}

    @param evt_names: Comma seperated list of event names.
    @type  evt_names: C{str}

    @param result_fname: Filename for writing the resulting automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started sequential abstraction computations "
                      "(version %s)" % automata.version)
    coll = collection.Collection()

    auts = load_automata(coll, aut_fnames, True, False)
    auts = abstraction.order_automata(auts)

    events = get_events(coll, evt_names)
    events = ensure_tau(coll, events)

    result = abstraction.sequential_abstraction(auts, events)
    save_automaton(result, "Abstraction is saved in %s",  result_fname)
Exemplo n.º 10
0
def generate_task_resource_use(comp_names, req_names, text_path, plots,
                               usefname):
    """
    Generate a task/resource usage picture for path L{text_path} with
    components L{comp_names} and requirements L{req_names}. Output data in
    L{usefname}.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of L{str}

    @param req_names: Available requirements (unweighted automata).
    @type  req_names: C{list} of L{str}

    @param text_path: Sequence of events on the path (a sequence of event
                      names, comma or white-space seperated).
    @type  text_path: C{string}

    @param plots: Names of automata to plot, if specified.
    @type  plots: C{str}

    @param usefname: Filename for writing task/resource use to.
    @type  usefname: C{str}

    @note: The L{comp_names} and L{req_names} are only used to compute the
           shape of the pieces at the heap. Therefore, for type 1 requirements
           (where the requirements automata are not used in that calculation),
           L{req_names} should be left empty.

    """
    common.print_line('Started generation of task/resource use (version %s)' %
                      automata.version)
    coll = collection.Collection()
    comp_list = load_weighted_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)

    plots = set(plots.replace(',', ' ').split())
    if plots:  # Non-empty set.
        plot_auts = set(aut for aut in comp_list + req_list
                        if aut.name in plots)
    else:
        plot_auts = None  # All automata should be plotted.

    uses = compute_weight.generate_task_resource_use(comp_list, req_list,
                                                     plot_auts, text_path)

    if usefname:
        handle = open(usefname, 'w')
        for use in uses:
            handle.write('%s\t%s\t%s\t%s\n' % use)
        handle.close()
    else:
        for use in uses:
            print '%s\t%s\t%s\t%s' % use
Exemplo n.º 11
0
def make_greedy_time_optimal_supervisor_row_vectors(comp_names, req_names,
                                                    evt_pairs, sup_name,
                                                    row_vectors, operator):
    """
    Compute a greedy time optimal supervisor.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of L{str}

    @param req_names: Available requirements (unweighted automata).
    @type  req_names: C{list} of L{str}

    @param evt_pairs: Additional event pairs (eg "{(a, b), (c, e)}", "type1",
                      or "type2")
    @type  evt_pairs: C{str}

    @param sup_name: Name of the resulting supervisor.
    @type  sup_name: C{str}
    """
    common.print_line("Started greedy time optimal supervisor "
                      "computation (version %s)" % automata.version)
    coll = collection.Collection()
    comp_list = load_weighted_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)

    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)

    result = taskresource.compute_custom_eventdata(comp_list, evt_pairs)
    if result is None:
        common.print_line('Could not compute the event data from the '
                          'components and event pairs\n'
                          'Perhaps they are inconsistent?')
        return

    eventdata, heap_len = result
    result = compute_weight.compute_greedy_time_optimal_supervisor(
        comp_list, req_list, eventdata, heap_len, row_vectors, operator)
    if result is None:
        common.print_line('Could not compute the weighted supervisor')
        return

    wsup, wmap = result
    one = maxplus.make_rowmat(0, heap_len)
    one = maxplus.otimes_mat_mat(one, wmap[wsup.initial])
    biggest = one.get_scalar()
    common.print_line("Sub-optimal makespan is %s" % biggest)

    wsup = weighted_supervisor.reduce_automaton_row_vecors(
        wsup, wmap, eventdata, heap_len, row_vectors)

    frontend.dump_stats("Computed weighted supervisor", wsup)
    save_weighted_automaton(wsup, "Supervisor is saved in %s\n", sup_name)
Exemplo n.º 12
0
def make_get_weighted_size(aut_fname):
    """
    Display size of the weighted automaton.

    @param aut_fname: Filename of the weighted automaton.
    @type  aut_fname: C{str}
    """
    common.print_line("Started calculating size (version %s)" %
                      automata.version)
    coll = collection.Collection()
    aut = load_weighted_automaton(coll, aut_fname, False, False)

    print str(aut)
Exemplo n.º 13
0
def convert_from_ads(ads_fname, aut_fname):
    """
    Convert ADS file to own automaton file format.

    @param ads_fname: Filename of the ADS file to load.
    @type  ads_fname: C{str}

    @param aut_fname: Output filename for the converted automaton.
    @type  aut_fname: C{str}
    """
    coll = collection.Collection()

    aut = read_ads.convert_ads_file(ads_fname, coll)

    dump_stats("Converted automaton", aut)
    save_automaton(aut, "Automaton is saved in %s",  aut_fname)
Exemplo n.º 14
0
def make_trim(aut_fname, out_fname):
    """
    Trim the automaton L{aut} (reduce to reachable and co-reachable states).

    @param aut_fname: Filename of the automaton.
    @type  aut_fname: C{str}

    @param out_fname: Filename of the resulting automaton.
    @type  out_fname: C{str}
    """
    common.print_line("Started trimming (version %s)" % automata.version)
    coll = collection.Collection()
    aut = load_automaton(coll, aut_fname, False, False)
    aut.reduce(True, True)

    dump_stats("Computed result", aut)
    save_automaton(aut, "Result is saved in %s\n", out_fname)
Exemplo n.º 15
0
def make_remove_tau_event(aut_fname, out_fname):
    """
    Remove 'tau' event from the automaton. May fail.

    @param aut_fname: Filename of the automaton.
    @type  aut_fname: C{str}

    @param out_fname: Filename of the resulting automaton.
    @type  out_fname: C{str}
    """
    common.print_line("Started removing 'tau' event (version %s)"
                        % automata.version)
    coll = collection.Collection()
    aut = load_automaton(coll, aut_fname, False, False)
    abstraction.remove_tau(aut) # Does in-place modification.

    dump_stats("Computed result", aut)
    save_automaton(aut, "Result is saved in %s\n", out_fname)
Exemplo n.º 16
0
def make_add_tau_event(aut_fname, out_fname):
    """
    Add 'tau' event to the automaton.

    @param aut_fname: Filename of the automaton.
    @type  aut_fname: C{str}

    @param out_fname: Filename of the resulting automaton.
    @type  out_fname: C{str}
    """
    common.print_line("Started adding 'tau' event (version %s)"
                        % automata.version)
    coll = collection.Collection()
    aut = load_automaton(coll, aut_fname, False, False)
    aut = abstraction.add_tau_event(aut)

    dump_stats("Computed result", aut)
    save_automaton(aut, "Result is saved in %s\n", out_fname)
Exemplo n.º 17
0
def make_weighted_dot(aut_fname, dot_fname):
    """
    Convert automaton to Graphviz format.

    @param aut_fname: Filename of the automaton to convert.
    @type  aut_fname: C{str}

    @param dot_fname: Output filename for the Graphviz data.
    @type  dot_fname: C{str}
    """
    coll = collection.Collection()
    aut = load_weighted_automaton(coll, aut_fname, False, False)

    frontend.make_backup_file(dot_fname)

    dot_handle = open(dot_fname, 'w')
    dot_handle.write(aut.to_dot())
    dot_handle.close()
Exemplo n.º 18
0
def make_minimal_weighted_supervisor(plant, req, new_fname):
    """
    Compute deterministic weighted supervisor for non-deterministic plant and
    deterministic requirements.

    @param plant: Filename of the non-deterministic weighted (but not
                  minimally) automaton.
    @type  plant: C{str}

    @param req: Filename of the requirements as deterministic non-weighted
                automaton.
    @type  req: C{str}

    @param new_fname: Filename of the created deterministic controller.
    @type  new_fname: C{str}
    """
    common.print_line("Started minimal weighted supervisor computations "
                      "(version %s)" % automata.version)
    coll = collection.Collection()

    plant_waut = load_weighted_automaton(coll, plant, False, True)
    req_aut = frontend.load_automaton(coll, req, False, True)
    wsup = compute_weight.compute_weighted_supremal(plant_waut, req_aut)
    if wsup is None:
        new_aut = None
    else:
        observables = set(
            [evt for evt in plant.events.itervalues() if evt.observable])
        check_marking_aware(wsup, observables)
        wsup2 = weighted_projection.weighted_projection(wsup, observables)
        new_aut = compute_weight.minimal_weight_deterministic_controllable(
            wsup2)
    if new_aut is None:
        common.print_line("No minimal weight controller found!")

    else:
        unw_plant = conversion.remove_weights(plant_waut)
        prod = product.n_ary_unweighted_product([unw_plant, new_aut[0]])
        result = supervisor.unweighted_determinization(prod)

        common.print_line("Minimum weight is %s" % new_aut[1])
        frontend.save_automaton(result,
                                "Saving minimal weight controller in %s",
                                new_fname)
Exemplo n.º 19
0
def make_reset_weighted(aut_fname, result_fname):
    """
    Reset the weights in weighted automaton L{aut_fname} to 0, and write the
    result to L{result_fname}.

    @param aut_fname: Filename of weighted automaton to load.
    @type  aut_fname: C{str}

    @param result_fname: Filename for writing the resulting weighted automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started resetting weights (version %s)" %
                      automata.version)
    coll = collection.Collection()

    aut = load_weighted_automaton(coll, aut_fname, False, False)
    aut.reset_weight(0)

    save_weighted_automaton(aut, "Result is saved in %s\n", result_fname)
Exemplo n.º 20
0
def make_remove_weighted(waut_fname, result_fname):
    """
    Remove the weights of weighted automaton L{waut_fname}, and write the
    result to L{result_fname}.

    @param waut_fname: Filename of weighted automaton to load.
    @type  waut_fname: C{str}

    @param result_fname: Filename of the resulting unweighted automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started removing weights (version %s)" %
                      automata.version)
    coll = collection.Collection()

    waut = load_weighted_automaton(coll, waut_fname, False, False)
    aut = conversion.remove_weights(waut)

    frontend.save_automaton(aut, "Result is saved in %s\n", result_fname)
Exemplo n.º 21
0
def make_unweight_time_optimal_supervisor(comp_names, req_names, evt_pairs,
                                          sup_name):
    """
    Compute a non weighted time optimal supervisor.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of L{str}

    @param req_names: Available requirements (unweighted automata).
    @type  req_names: C{list} of L{str}

    @param evt_pairs: Additional event pairs (eg "{(a, b), (c, e)}", "type1",
                      or "type2")
    @type  evt_pairs: C{str}

    @param sup_name: Name of the resulting supervisor.
    @type  sup_name: C{str}
    """
    common.print_line("Started time unweight optimal supervisor computations "
                      "(version %s)" % automata.version)
    coll = collection.Collection()
    comp_list = load_unweight_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)
    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)

    result = compute_weight.compute_unweight_time_optimal_supervisor(
        comp_list, req_list, evt_pairs)
    if result is None:
        common.print_line('Could not compute the weighted supervisor')
        return

    wsup = result
    #one = maxplus.make_rowmat(0, heap_len)
    #one = maxplus.otimes_mat_mat(one, wmap[wsup.initial])
    #biggest = one.get_scalar()
    #common.print_line("Sub-optimal makespan is %s" % biggest)

    #wsup = weighted_supervisor.reduce_automaton(wsup, wmap, eventdata,
    #                                            heap_len)

    frontend.dump_stats("Computed unweighted supervisor", wsup)
    save_weighted_automaton(wsup, "Supervisor is saved in %s\n", sup_name)
Exemplo n.º 22
0
def make_minimized(aut_name, result_fname):
    """
    Perform minimization of the automaton stored in L{aut_name}, and write the
    result to L{result_fname}.

    @param aut_name: Filename of the automaton to.
    @type  aut_name: L{Automaton}

    @param result_fname: Filename for writing the resulting automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started minimization computation (version %s)"
                        % automata.version)
    coll = collection.Collection()

    aut = load_automaton(coll, aut_name, False, False)
    result = abstraction.abstraction(aut, aut.alphabet)

    dump_stats("Computed minimized result", result)
    save_automaton(result, "Minimized automaton is saved in %s",  result_fname)
Exemplo n.º 23
0
def make_controllability_check(plant_fname, sup_fname):
    """
    Verify whether the plant is controllable with the supervisor.

    @param plant_fname: Filename of the plant automaton.
    @type  plant_fname: C{str}

    @param sup_fname: Filename of the supervisor.
    @type  sup_fname: C{str}
    """
    common.print_line("Started controllability check (version %s)"
                        % automata.version)
    coll = collection.Collection()
    sup_aut = load_automaton(coll, sup_fname, False, False)
    plant_aut = load_automaton(coll, plant_fname, False, False)

    contr_disableds, uncontr_disableds = \
                                find_disabled_events(sup_aut, plant_aut)

    if len(contr_disableds) > 0:
        print "States with disabled controllable events:"
        for sup_s, plant_s, dis_e in contr_disableds:
            print "    (%d, %d): {%s}" % (plant_s.number, sup_s.number,
                                          ", ".join([e.name for e in dis_e]))

        print

    if len(uncontr_disableds) > 0:
        print "States with disabled uncontrollable events:"
        for sup_s, plant_s, dis_e, sup_p, plant_p in uncontr_disableds:
            print "    (%d, %d): {%s}" % (plant_s.number, sup_s.number,
                                          ", ".join([e.name for e in dis_e]))
            print "        Supervisor path: " + make_path_string(sup_p)
            print "        Plant path: " + make_path_string(plant_p)
            print

        print "Supervisor is INCORRECT (has disabled uncontrollable events)"
        sys.exit(1)

    else:
        print "Supervisor is correct (no disabled uncontrollable events)"
Exemplo n.º 24
0
def create_local_automaton(aut, local_alphabet, start_state, end_state):
    # creating temporary automaton
    temp_coll = collection.Collection()
    temp_automaton = weighted_structure.WeightedAutomaton(
        local_alphabet, temp_coll)
    for state in aut.get_states():
        ns = temp_automaton.add_new_state(state == end_state, state.number)
    for state in aut.get_states():
        for edge in state.get_outgoing():
            if edge.label in local_alphabet:
                new_edge = edge.copy(
                    temp_automaton.get_state(edge.pred.number),
                    temp_automaton.get_state(edge.succ.number))
                temp_automaton.add_edge(new_edge)

    temp_automaton.initial = temp_automaton.get_state(start_state.number)
    temp_automaton.reduce(True, True)
    if temp_automaton.get_num_states() == 0:
        return None
    else:
        return temp_automaton
Exemplo n.º 25
0
def make_weighted_product(aut_fnames, result_fname):
    """
    Multiply the weighthed automata in the L{aut_fnames} list, and write the
    result to L{result_fname}.

    @param aut_fnames: Comma-seperated list of weighted automata filenames.
    @type  aut_fnames: C{str}

    @param result_fname: Filename for writing the resulting weighted automaton.
    @type  result_fname: C{str}
    """
    common.print_line("Started weighted product computations (version %s)" %
                      automata.version)
    coll = collection.Collection()

    aut_list = load_weighted_automata(coll, aut_fnames, False, False)
    result = weighted_product.n_ary_weighted_product(
        aut_list, algorithm.SUM_EDGE_WEIGHTS, True, True)

    frontend.dump_stats("Computed product", result)
    save_weighted_automaton(result, "Product is saved in %s\n", result_fname)
Exemplo n.º 26
0
def make_system2(num_cranes, num_slots, init_crane, num_containers):
  filenames = []
  coll = collection.Collection()
  automata = []
  for i in range(1, num_cranes + 1):
    stnum = str(i)
    name = "D" + stnum
    filenames.append(name)
    automata.append(make_crane(i, num_slots, num_containers, coll, name))
  defaultinit = "1"
  craneslot = {}
  inits = {}
  for (crane, slot) in init_crane:
    inits[slot] = str(crane + 1)
    craneslot[crane] = slot
  for i in range(1, num_slots + 1):
    stnum = str(i).zfill(3)
    name = "CS" + stnum
    filenames.append(name)
    init = defaultinit if i not in inits else inits[i]
    automata.append(make_crane_location(num_cranes, i, num_containers, i == num_slots, init, coll, name))
  for i in range(1, num_slots):
    for c in range(1, num_cranes + 1):
      crane = "C" + str(c)
      name = "E" + str(c) + "_" + str(i).zfill(3)
      filenames.append(name)
      init = 1 if craneslot[c] <= i else 2
      automata.append(make_crane_restriction(crane, i, init, coll, name))
  picks = generate_containers4(num_containers, num_slots)
  num = 0
  for pick in picks:
    drops = picks[pick]
    for i in range(len(drops)):
      drop, num = drops[i]
      num += 1
      stnum = str(num)
      name = "SC" + stnum
      filenames.append(name)
      automata.append(make_container(num, pick, drop, None, num_cranes, num_slots, coll, name))
  process_system(automata, "cranes", True, num_cranes)
Exemplo n.º 27
0
def row_vector_compute(plant, req_names, evt_pairs, row_vector_names,
                       operator_class):
    coll = collection.Collection()
    comp_list = weighted_frontend.load_weighted_automata(
        coll, plant, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)
    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)
    result = taskresource.compute_custom_eventdata(comp_list, evt_pairs)
    if result is None:
        common.print_line('Could not compute the event data from the '
                          'components and event pairs\n'
                          'Perhaps they are inconsistent?')
        return

    eventdata, heap_len = result

    plant = weighted_product.n_ary_weighted_product(
        comp_list, algorithm.EQUAL_WEIGHT_EDGES)
    requirement = product.n_ary_unweighted_product(req_list)

    for comp in comp_list:
        comp.clear()
    del comp_list

    wsup = compute_weight.compute_weighted_supremal(plant, requirement)
    if wsup is None:
        return None
    requirement.clear()
    del requirement

    row_zero_mat = maxplus.make_rowmat(0, heap_len)
    row_epsilon_mat = maxplus.make_rowmat(maxplus.INFINITE, heap_len)

    marker_valfn = lambda state: row_zero_mat
    nonmarker_valfn = lambda state: row_epsilon_mat

    row_vecs = compute_state_row_vector(wsup, marker_valfn, nonmarker_valfn,
                                        eventdata, operator_class)

    return row_vecs
Exemplo n.º 28
0
def make_supervisor(plant_fnames, spec_fnames, sup_fname):
    """
    Construct a supervisor for controlling a plant within its specification.

    Function aborts if supervisor construction fails.


    @param plant_fnames: Filenames of the plant automata.
    @type  plant_fnames: C{str}

    @param spec_fnames: Filenames of the specification automata.
    @type  spec_fnames: C{str}

    @param sup_fname: Filename for the resulting supervisor.
    @type  sup_fname: C{str}

    @todo: Supervisor computation should set the automaton kind by itself.
    """
    common.print_line("Started supervisor computations (version %s)"
                        % automata.version)
    coll = collection.Collection()

    plants = load_automata(coll, plant_fnames, False, True)
    specs  = load_automata(coll, spec_fnames, False, True)

    sup = supervisor.make_supervisor(plants, specs)
    if sup is None:
        print "Supervisor is empty"
        sys.exit(1)
    else:
        # FIXME: This is the wrong place for setting the result kind
        npl = sum(1 for plant in plants if plant.aut_kind == 'plant')
        nsp = sum(1 for spec in specs   if spec.aut_kind == 'requirement')
        if npl == len(plants) and nsp == len(specs):
            if sup.aut_kind == 'unknown':
                sup.set_kind('supervisor')

        dump_stats("Computed supervisor", sup)
        save_automaton(sup, "Supervisor saved in %s", sup_fname)
Exemplo n.º 29
0
def compute_shortest_path(comp_names, req_names, evt_pairs):
    """
    Compute shortest path with A* algorithm and type 1 requirements.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of L{str}

    @param req_names: Name of the requirement automata (unweighted automata).
    @type  req_names: C{list} of L{str}

    @param evt_pairs: Additional event pairs (eg "{(a, b), (c, e)}", "type1",
                      or "type2")
    @type  evt_pairs: C{str}
    """
    common.print_line('Started shortest path type 1 computation (version %s)' %
                      automata.version)
    coll = collection.Collection()
    comp_list = load_weighted_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)

    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)
    compute_weight.compute_shortest_path(comp_list, req_list, evt_pairs)
Exemplo n.º 30
0
def FK_row_vector(comp_names, req_names, evt_pairs):
    """
    Compute a LBE greedy time optimal supervisor.

    @param comp_names: Available components (weighted automata).
    @type  comp_names: C{list} of L{str}

    @param req_names: Available requirements (unweighted automata).
    @type  req_names: C{list} of L{str}

    @param evt_pairs: Additional event pairs (eg "{(a, b), (c, e)}", "type1",
                      or "type2")
    @type  evt_pairs: C{str}

    @param sup_name: Name of the resulting supervisor.
    @type  sup_name: C{str}
    """
    common.print_line("Started greedy time optimal supervisor "
                      "computation (version %s)" % automata.version)
    coll = collection.Collection()
    comp_list = load_weighted_automata(coll, comp_names, False, True)
    req_list = frontend.load_automata(coll, req_names, False, True)

    evt_pairs = taskresource.process_event_pairs(coll, req_list, evt_pairs)

    result = taskresource.compute_custom_eventdata(comp_list, evt_pairs)
    if result is None:
        common.print_line('Could not compute the event data from the '
                          'components and event pairs\n'
                          'Perhaps they are inconsistent?')
        return

    eventdata, heap_len = result
    result = compute_weight.FK_row_vector(comp_list, req_list, eventdata,
                                          heap_len)
    if result is None:
        common.print_line('Could not compute the row vector')
        return