Exemple #1
0
 def isBC(self, bc, show_reason = False):
   if type(bc) is str:
     bc = spot.formula(bc)
   c = spot.language_containment_checker()
   #non-triviality
   if not sat_check(bc.to_str('spin')) or not sat_check(spot.formula_Not(bc).to_str('spin')):
     if show_reason:
       print('bc is true or false')
     return False
   not_g = spot.formula_Not(spot.formula_And(self.goals))
   if not sat_check(spot.formula_And([not_g, spot.formula_Not(bc)]).to_str('spin')) and not sat_check(spot.formula_And([spot.formula_Not(not_g), bc]).to_str('spin')):
     if show_reason:
       print('trivial')
     return False
   #logical incosistency
   if sat_check(spot.formula_And(self.doms + self.goals + [bc,]).to_str('spin')):
     if show_reason:
       print('consistency')
     return False
   else:
   #minimality
     for i in range(len(self.goals)):
       if not sat_check(spot.formula_And(self.doms + [goal for goal in self.goals if goal != self.goals[i]] + [bc,]).to_str('spin')):
         if show_reason:
           print('not minimality')
           print(i, self.goals[i].to_str())
         return False
   return True
Exemple #2
0
 def is_not_gd_BC(self):
   not_g_d = spot.formula_Not(spot.formula_And(self.goals + self.doms))
   #logical incosistency
   if sat_check(spot.formula_And(self.doms + self.goals + [not_g_d,]).to_str('spot')):
     return False
   else:
   #minimality
     for i in range(len(self.goals)):
       if not sat_check(spot.formula_And(self.doms + [goal for goal in self.goals if goal != self.goals[i]] + [not_g_d,]).to_str('spin')):
         return False
   return True
def get_pbcs_from_aut(aut):
  pbcs = []
  acc = []
  for s in range(0, aut.num_states()):
    if aut.state_is_accepting(s):
      acc.append(s)

  for acc_i in acc:
    aut_temp = spot.automaton(aut.to_str('hoa', '1.1'))
    for acc_j in acc:
      if acc_j != acc_i:
        for t in aut_temp.out(acc_j):
          t.cond = buddy.bddfalse
    run = aut_temp.accepting_run()
    plist = [p for p in run.prefix]
    pbct = spot.formula_tt()
    step = 0
    for p in plist:
      p_step = spot.bdd_format_formula(aut.get_dict(), p.label)
      p_step = spot.formula(p_step)
      for i in range(step):
        p_step = spot.formula_X(p_step)
      pbct = spot.formula_And([pbct, p_step])
      step += 1
    pbcs.append(pbct)
  return pbcs
Exemple #4
0
 def isGeneral(self, bc1, bc2):
   if type(bc1) is str:
     bc1 = spot.formula(bc1)
   if type(bc2) is str:
     bc2 = spot.formula(bc2)
   if not sat_check(spot.formula_And([bc2, spot.formula_Not(bc1)]).to_str('spin')):
     return True
   else:
     return False
Exemple #5
0
  def isBC_t(self, bc, no_relation_gi):
    if type(bc) is str:
      bc = spot.formula(bc)

    #logical incosistency
    if sat_check(spot.formula_And(self.doms + self.goals + [bc,]).to_str('spin')):
      return -1
    else:
    #minimality
      no_relation_g = []
      for i in range(len(self.goals)):
        if i in no_relation_gi:
          no_relation_g.append(self.goals[i])

      for i in range(len(self.goals)):
        if i in no_relation_gi:
          continue
        if not sat_check(spot.formula_And(self.doms + [goal for goal in self.goals if goal != self.goals[i] and goal not in no_relation_g] + [bc,]).to_str('spin')):
          return i
    return -2
Exemple #6
0
 def isWitness(self, bc1, bc2):
   if type(bc1) is str:
     bc1 = spot.formula(bc1)
   if type(bc2) is str:
     bc2 = spot.formula(bc2)
   # if self.isGeneral(bc1, bc2):
   #   print('just genral')
   #   return False
   if not self.isBC(spot.formula_And([bc2, spot.formula_Not(bc1)])):
     return True
   else:
     return False
Exemple #7
0
  def getNonsenseBC(self):
    # start = time.time()
    f = spot.formula_Not(spot.formula_And(self.goals))
    sim_option = spot.tl_simplifier_options()
    sim_option.reduce_basics = False
    sim = spot.tl_simplifier(sim_option)
    f = sim.simplify(f)
    f = spot.unabbreviate(f, "GFMW^ie")
    print(f.to_str())

    nonsense_bc = []
    for child_i in f:
      if child_i.kind() == spot.op_F:
        nonsense_bc.append(spot.formula_Or([child if child != child_i else child[0] for child in f]))
        nonsense_bc.append(spot.formula_Or([child if child != child_i else spot.formula_X(child[0]) for child in f]))
    # print('get nonsense in: ' + str(time.time()-start))
    return nonsense_bc
Exemple #8
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import spot

lcc = spot.language_containment_checker()

formulas = ['GFa', 'FGa', '(GFa) U b',
            '(a U b) U c', 'a U (b U c)',
            '(a W b) W c', 'a W (b W c)',
            '(a R b) R c', 'a R (b R c)',
            '(a M b) M c', 'a M (b M c)',
            '(a R b) U c', 'a U (b R c)',
            '(a M b) W c', 'a W (b M c)',
            '(a U b) R c', 'a R (b U c)',
            '(a W b) M c', 'a M (b W c)',
            ]

# The rewriting assume the atomic proposition will not change
# once we reache the non-alive part.
cst = spot.formula('G(X!alive => ((a <=> Xa) && (b <=> Xb) && (c <=> Xc)))')

for f in formulas:
    f1 = spot.formula(f)
    f2 = f1.unabbreviate()
    f3 = spot.formula_And([spot.from_ltlf(f1), cst])
    f4 = spot.formula_And([spot.from_ltlf(f2), cst])
    print("{}\t=>\t{}".format(f1, f3))
    print("{}\t=>\t{}".format(f2, f4))
    assert lcc.equal(f3, f4)
    print()
Exemple #9
0
 def dandng_aut(self):
   return spot.translate(spot.formula_And([spot.formula_Not(spot.formula_And(self.goals))] + self.doms), 'ba', 'det')
Exemple #10
0
 def ngd_aut(self):
   return spot.translate(spot.formula_Not(spot.formula_And(self.goals + self.doms)), 'ba', 'det')
Exemple #11
0
 def showdg(self):
   print(spot.formula_And(self.doms+self.goals).to_str())
Exemple #12
0
  def quickSolution(self):
    start_time = time.time()
    BCs = []
    for goal_i in self.goals:
      G_minusi = spot.formula_And([g for g in self.goals if g != goal_i])
      
      sim_option = spot.tl_simplifier_options()
      sim_option.reduce_basics = False
      sim = spot.tl_simplifier(sim_option)
      regular_goal_i = sim.simplify(spot.formula_Not(goal_i))
      regular_goal_i = spot.unabbreviate(regular_goal_i, "FMW^ie")
      # print(regular_goal_i.to_str())

      all_ap = spot.atomic_prop_collect(spot.formula_And(self.doms+self.goals))
      gi_ap = spot.atomic_prop_collect(goal_i)
      none_relation_ap = [ap for ap in all_ap if ap not in gi_ap]

      # special case
      special_cases = []
      if regular_goal_i.kind() == spot.op_ap:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_tt:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_Not:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_And:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_G:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_Or:
        a = regular_goal_i[0]
        b = regular_goal_i[1]
        special_cases = [a,b]
      elif regular_goal_i.kind() == spot.op_X:
        for ap in none_relation_ap:
          special_cases.append(spot.formula_And([regular_goal_i,ap]))
      elif regular_goal_i.kind() == spot.op_R:
        a = regular_goal_i[0]
        b = regular_goal_i[1]
        special_cases = [a,spot.formula_And([b,spot.formula_X(a)])]
      elif regular_goal_i.kind() == spot.op_U:
        a = regular_goal_i[0]
        b = regular_goal_i[1]
        special_cases = [b,spot.formula_And([a,spot.formula_X(b)])]
      else:
        continue

      # check sc
      for sc in special_cases:
        f = spot.formula_And([sc, G_minusi] + self.doms).to_str()
        pbc = spot.formula_Or([sc, spot.formula_Not(G_minusi)])
        if sat_check(f):
          BCs.append(pbc)
        
    gen_time = time.time()
    # for bc in BCs:
    #   print(bc.to_str())
    #   print(self.isBC(bc))
    BCs_real = []
    for bc in BCs:
      if self.isBC(bc):
        BCs_real.append(bc)

    BCg = BCs_real.copy()

    for bc in BCs_real:
      if not self.isBC(bc):
        BCs_real.remove(bc)
      for bc1 in BCs_real:
        if bc != bc1:
          a = self.isWitness(bc, bc1)
          b = self.isWitness(bc1, bc)
          if a and b:
            if len(bc.to_str()) < len(bc1.to_str()):
              BCs_real.remove(bc1)
          if a and not b:
            BCs_real.remove(bc1)
    
    # for bc in BCs:
    #   print(bc.to_str())
    return BCg, BCs_real, gen_time-start_time, time.time()-gen_time
Exemple #13
0
 def its_impossible(self):
   for i in range(len(self.goals)):
     if not sat_check( spot.formula_And( self.doms + [goal if goal != self.goals[i] else spot.formula_Not(goal) for goal in self.goals ] ).to_str('spin') ):
       print('why')
       print(str(i), self.goals[i].to_str())
Exemple #14
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import spot

lcc = spot.language_containment_checker()

formulas = ['GFa', 'FGa', '(GFa) U b',
            '(a U b) U c', 'a U (b U c)',
            '(a W b) W c', 'a W (b W c)',
            '(a R b) R c', 'a R (b R c)',
            '(a M b) M c', 'a M (b M c)',
            '(a R b) U c', 'a U (b R c)',
            '(a M b) W c', 'a W (b M c)',
            '(a U b) R c', 'a R (b U c)',
            '(a W b) M c', 'a M (b W c)',
           ]

# The rewriting assume the atomic proposition will not change
# once we reache the non-alive part.
cst = spot.formula('G(X!alive => ((a <=> Xa) && (b <=> Xb) && (c <=> Xc)))')

for f in formulas:
    f1 = spot.formula(f)
    f2 = f1.unabbreviate()
    f3 = spot.formula_And([spot.from_ltlf(f1), cst])
    f4 = spot.formula_And([spot.from_ltlf(f2), cst])
    print("{}\t=>\t{}".format(f1, f3))
    print("{}\t=>\t{}".format(f2, f4))
    assert lcc.equal(f3, f4)
    print()