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)
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
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)
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)
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
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)
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
def enhanced_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 = do_n_ary_product_map(comp_list) for comp in comp_list: comp.clear() del comp_list wsup = plant.get_automaton() if wsup is None: return None row_zero_mat = maxplus.make_rowmat(0, 1) row_epsilon_mat = maxplus.make_rowmat(maxplus.INFINITE, 1) marker_valfn = lambda state: row_zero_mat nonmarker_valfn = lambda state: row_epsilon_mat row_vecs = enhance_compute_state_row_vector(wsup, marker_valfn, nonmarker_valfn, eventdata, operator_class) return row_vecs