示例#1
0
def tighten_guarantees(tlsf_file: str) -> Tuple[str, Atom]:
    tlsf = open(tlsf_file).read()
    matches = re.findall(r"(GUARANTEES( |\n)*?\{(.|\n)*?\})", tlsf, re.M)
    if len(matches) > 1:
        "Multiple guarantees clauses. Not doing anything in this case."
    if len(matches) == 0:
        "No guarantees clauses. Not doing anything in this case."

    # TODO
    print("Assuming tlsf file does not use definitions in guarantees.")

    match: str = matches[0][0]
    without_header = match.replace("GUARANTEES", "").replace("{", "").replace(
        "}", "").strip().strip(";")
    guarantee = "(" + without_header.replace(";", ") & (") + ")"
    to_LTL = string_to_ltl(guarantee)
    (tightened, new_out, end_act) = tighten_ltl(to_LTL)
    tightened_str = str(tightened)

    tightened_tlsf = tlsf.replace(without_header, tightened_str)
    tightened_tlsf = re.sub(
        r"OUTPUTS( |\n*?)\{", "OUTPUTS {\n\t" +
        ";\n\n\t".join(map(lambda o: str(o), new_out)) + ";\n", tightened_tlsf,
        re.M)

    path = tlsf_file.replace(".tlsf", "") + "-tightened" + ".tlsf"
    tightened_tlsf_file = open(path, "w+")
    tightened_tlsf_file.seek(0)
    tightened_tlsf_file.write(tightened_tlsf)
    tightened_tlsf_file.truncate()
    ## TODO Need to add end events to outputs
    return (path, end_act)
示例#2
0
 def test_tighten_ltl_0(self):
     ltl = eventually(Atom("a"))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is None:
         self.fail()
示例#3
0
 def test_tighten_ltl_6(self):
     ltl = orr(next(Atom("a")), Atom("b"))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is None:
         self.fail()
示例#4
0
 def test_tighten_ltl_5(self):
     ltl = nott(next(Atom("a")))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is not None:
         self.fail()
示例#5
0
 def test_tighten_ltl_2(self):
     ltl = next(Atom("a"))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is None:
         self.fail()
示例#6
0
 def test_tighten_ltl_1(self):
     ltl = andd(Atom("a"), Atom("b"))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is None:
         self.fail()
示例#7
0
 def test_tighten_ltl_1(self):
     ltl = globally(Atom("a"))
     tightened = tighten_ltl(ltl)
     print(tightened)
     if tightened is not None:
         self.fail()