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 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 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
with open("EPUCK-mut_ex_" + str(num_comp) + "_plants.txt", "r") as mut_ex_list_file: mut_ex_list = mut_ex_list_file.read() # comp_string = "plant1 plant2" # mut_ex_list = "{}" ####### Program ####### # Generate component data coll = collection.Collection() common.print_line("Loading automata...") comp_names = tools.convert(comp_string) comp_list = weighted_frontend.load_weighted_automata(coll, comp_names, False, True) common.print_line("Computing event data...") evt_pairs = taskresource.process_event_pairs(coll, None, mut_ex_list) eventdata, heap_len = taskresource.compute_custom_eventdata(comp_list, evt_pairs) def find_distances_to_marker(comp_list): distances_structure = {} for comp in comp_list: distances_to_marker = {} # Find marker state # Maybe edit this part to work for automata with multiple marker states? end_state = None while end_state == None: for state in comp.get_states(): if state.marked: end_state = state distances_to_marker[end_state] = 0