Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
def process_system(automata, output_dir, explicitly_disable, cranes):
  #explicitly_disable = False
  if not os.path.exists(output_dir + "\\before_removal\\"):
    os.makedirs(output_dir + "\\before_removal\\")
  for aut in automata:
    aut.save_as_dot(output_dir + "\\before_removal\\" + aut.name + ".dot")
  remove_always_disabled_events(automata)
  if not os.path.exists(output_dir + "\\after_removal\\"):
    os.makedirs(output_dir + "\\after_removal\\")
  for aut in automata:
    print aut.name
    aut.save_as_dot(output_dir + "\\after_removal\\" + aut.name + ".dot")
  tick = automata[0].collection.make_event("tick", True, True, False)
  tau = automata[0].collection.make_event("tau", False, False, False)
  #automata.append(make_move_order([aut for aut in automata if aut.name.startswith("SC")], \
  #                                automata[0].collection, "move_order"))
  #remove_always_disabled_events(automata)
  #for i, aut in enumerate(automata):
  #  if aut.name.startswith("D"):
  #    move_events = [aut.collection.events[evt] for evt in aut.collection.events if "mov" in evt and evt[1] == aut.name[1]]
  #    add_move_events_to_crane(aut, move_events)
  #    aut.alphabet.add(tau)
  #    automata[i] = tau_abstraction.convert_weighted_to_tick(aut, tick)
  #if explicitly_disable:
  #  for aut in automata:
  #    if aut.name.startswith("CS"):
  #      explicitly_disable_events(aut, cranes, int(aut.name[2:]))
  #if explicitly_disable:
  #  evts = set()
  #  for aut in automata:
  #    if aut.name.startswith("SC"):
  #      evts.update(aut.alphabet) 
  #  for aut in list(automata):
  #    if aut.name.startswith("CS"):
  #      explicitly_disable_events2(aut, cranes, evts)
  #for i, aut in enumerate(automata):
  #  if aut.name.startswith("CS"):
  #    aut.alphabet.add(tau)
  #    automata[i] = tau_abstraction.convert_weighted_to_tick(aut, tick)
  sc_order = output_crane_order(automata, output_dir)
  #sc_order = output_crane_order_track_first(automata, output_dir)
  if explicitly_disable:
    for i, aut in enumerate(sc_order):
      print aut.name
      explicitly_disable_events_container(aut, cranes, sc_order[i+1:])
  if not os.path.exists(output_dir + "\\after_disable\\"):
    os.makedirs(output_dir + "\\after_disable\\")
  for aut in automata:
    aut.save_as_dot(output_dir + "\\after_disable\\" + aut.name + ".dot")
  if not os.path.exists(output_dir + "\\weighted\\"):
    os.makedirs(output_dir + "\\weighted\\")
  if not os.path.exists(output_dir + "\\unweighted\\"):
    os.makedirs(output_dir + "\\unweighted\\")
  if not os.path.exists(output_dir + "\\unweightedtau\\"):
    os.makedirs(output_dir + "\\unweightedtau\\")
  for aut in automata:
    save_weighted_automaton(aut, "", output_dir + "\\weighted\\" + aut.name + ".cfg")
    save_automaton(aut, "", output_dir + "\\unweighted\\" + aut.name + ".cfg")
    new_init = aut.add_new_state(False)
    aut.alphabet.add(tau)
    aut.add_edge_data(new_init, aut.initial, tau, 1)
    aut.initial = new_init
    save_automaton(aut, "", output_dir + "\\unweightedtau\\" + aut.name + ".cfg")
  string_unweighted = "\"C:\Users\sware\swareaug12\\aug5\Latest version2\Latest version\make_aggregated_supervisor.py\" -d "
  string_weighted = "\"C:\Users\sware\swareaug12\\aug5\Latest version2\Latest version\make_tau_abstracted_supervisor.py\" -d "
  for i, aut in enumerate(automata):
    if i != 0:
      string_unweighted += ","
      string_weighted += ","
    string_unweighted += aut.name + ".cfg"
    string_weighted += aut.name + ".cfg"
  string_unweighted += " req.cfg "
  string_weighted += " req.cfg {} sup.cfg"
  handle = file(output_dir + "\\unweighted\\cranetau.bat", 'w')
  handle.write(string_unweighted + " steps")
  handle.close()
  handle = file(output_dir + "\\unweightedtau\\cranetau.bat", 'w')
  handle.write(string_unweighted + " steps")
  handle.close()
  handle = file(output_dir + "\\unweighted\\cranetau_full_track.bat", 'w')
  handle.write(string_unweighted + " steps_full_track")
  handle.close()
  handle = file(output_dir + "\\unweighted\\cranetau_segments.bat", 'w')
  handle.write(string_unweighted + " steps_segments")
  handle.close()
  handle = file(output_dir + "\\weighted\\cranetau.bat", 'w')
  handle.write(string_unweighted)
  handle.close()
  #output_crane_order(automata, output_dir)
  output_crane_order_compose_segments(automata, output_dir)
  output_crane_order_compose_full_track(automata, output_dir)
Esempio n. 6
0
  eventlist = []
  pathstate = path.initial
  while not pathstate.marked:
    for edge in pathstate.get_outgoing():
      pathstate = edge.succ
      eventlist.append(edge.label)
  return eventlist

common.print_line("Calculating product...")
path_found = False
plant = heap_unfold_product(comp_list, eventdata, heap_len, distances_to_marker, shortest_path)
if path_found:
    plant.reduce(True, True)
    common.print_line("Path found, outputting to file...")
    plant.save_as_dot("test_plant_as_dot.dot")
    frontend.save_automaton(plant, "saving", "epuckpath.cfg")
    trace = extract_trace(plant)
    string = ""
    for (i, event) in enumerate(trace):
      if i != 0:
        string += ", "
      string += event.name 
    handle = file("epuckevents.txt", 'w')
    handle.write(string)
    handle.close()
else:
    common.print_line("No path could be found...")