How to use remove_taus method in fMBT

Best Python code snippet using fMBT_python

relax2.py

Source:relax2.py Github

copy

Full Screen

...174 """ Min minimizes. Warning: bad and silly.175 It is correct, however. """176 def min(self):177 self.backwards()178 self.remove_taus()179 self.det()180 self.cln()181 self.unreach()182 self.backwards()183 self.remove_taus()184 self.det()185 self.cln()186 self.unreach()187 """ helper method remove_taus removes taus and replaces with188 regular nondeteminism """189 def remove_taus(self):190 init = 0191 foundstates = set([init])192 stack = [init]193 while stack:194 s = stack.pop()195 found2 = set([s])196 stack2 = [s]197 while stack2:198 s2 = stack2.pop()199 if not 0 in self.Trans[s2]:continue200 for s2p in self.Trans[s2][0]:201 if not s2p in found2:202 stack2.append(s2p)203 found2.add(s2p)204 for a in self.Trans[s2p]:205 if a == 0:continue206 if not a in self.Trans[s]:207 self.Trans[s][a] = set([]) 208 self.Trans[s][a].update(self.Trans[s2p][a])209 210 for a in self.Trans[s]:211 if a == 0:212 self.Trans[s][a] = set([])213 continue214 for sp in self.Trans[s][a]:215 if sp in foundstates:continue216 foundstates.add(sp)217 stack.append(sp) 218 """ makes current deterministic.219 warning: may be exponential """220 def det(self):221 init = (0,)222 newstates = {init:0}223 cnum = 0224 stack = [init]225 trel = [{}]226 acc = set([])227 while stack:228 ss = stack.pop()229 for a in xrange(len(self.Sigma)):230 news = set([])231 ac = False232 for s in ss:233 if a in self.Trans[s]: 234 for sp in self.Trans[s][a]:235 news.add(sp)236 if sp in self.acc:237 ac = True238 news = list(news)239 news.sort()240 news = tuple(news)241 if not news in newstates:242 cnum +=1243 newstates[news] = cnum244 trel.append({})245 stack.append(news)246 spp = newstates[news] 247 trel[newstates[ss]][a] = set([spp])248 if ac:acc.add(spp)249 self.Trans = trel250 self.acc = acc251 """ union adds D2, and this is the nondet-252 non-interleaving version """253 def union(self,D2):254 self.addSigma(D2.Sigma)255 cnum = len(self.Trans)256 newstates = {0:0}257 for s in xrange(len(D2.Trans)):258 for a in D2.Sigma:259 ai = D2.Sigma.index(a)260 ni = self.Sigma.index(a)261 if not ai in D2.Trans[s]: continue262 for sp in D2.Trans[s][ai]:263 if not sp in newstates:264 self.Trans.append({})265 newstates[sp] = cnum266 cnum+=1267 ss = newstates[s]268 ssp = newstates[sp]269 if sp in D2.acc:270 self.acc.add(ssp)271 if not ni in self.Trans[ss]:272 self.Trans[ss][ni] = set([])273 self.Trans[ss][ni].add(ssp)274 275 """ 'add' adds another trace to current 276 and returns a new DFA. Safe only for det.277 Interleaves them completely """278 def add(self,D2):279 stnumbering = {(0,0):0} # store for the states280 cnumber = 0 # number for the states new DFA281 acc = set([]) # acc-set for the new DFA282 trans = [{}] # transrel for the new. sigma is union.283 stack = [(0,0)] # going in "pseudoDFS"284 Sg1 = self.Sigma285 Sg2 = D2.Sigma286 Sigma = set(Sg1).union(Sg2) # union of alphabets287 Sigma.remove('tau')288 SL = ['tau']289 SL.extend(list(Sigma))290 while stack:291 (x,y) = stack.pop()292 st = stnumbering[(x,y)] 293 if x in self.acc or y in D2.acc: # union294 acc.add(st)295 for a in Sigma:296 ai = SL.index(a)297 if a in Sg1 and a in Sg2: # this is in joint alp.298 i = self.Sigma.index(a)299 j = D2.Sigma.index(a)300 if x == None or not i in self.Trans[x]:301 Xp = [None]302 else:303 Xp = self.Trans[x][i]304 if y == None or not j in D2.Trans[y]:305 Yp = [None]306 else:307 Yp = D2.Trans[y][j]308 succ = [(xp,yp) for xp in Xp for yp in Yp]309 for xp,yp in succ:310 if not (xp,yp) in stnumbering:311 cnumber += 1312 stnumbering[(xp,yp)] = cnumber313 stack.append((xp,yp))314 trans.append({})315 stp = stnumbering[(xp,yp)]316 if not ai in trans[st]:317 trans[st][ai] = set([])318 trans[st][ai].add(stp)319 elif a in Sg1:320 i = self.Sigma.index(a)321 if x==None or not i in self.Trans[x]: continue322 for xp in self.Trans[x][i]:323 if not (xp,y) in stnumbering:324 cnumber += 1325 stnumbering[(xp,y)] = cnumber326 stack.append((xp,y))327 trans.append({})328 stp = stnumbering[(xp,y)]329 if not ai in trans[st]:330 trans[st][ai] = set([])331 trans[st][ai].add(stp)332 elif a in Sg2:333 j = D2.Sigma.index(a)334 if y==None or not j in D2.Trans[y]: continue335 for yp in D2.Trans[y][j]:336 if not (x,yp) in stnumbering:337 cnumber += 1338 stnumbering[(x,yp)] = cnumber339 stack.append((x,yp))340 trans.append({})341 stp = stnumbering[(x,yp)]342 if not ai in trans[st]:343 trans[st][ai] = set([])344 trans[st][ai].add(stp)345 rr = DFA_lsts()346 rr.Trans = trans347 rr.addSigma(SL)348 rr.acc = acc349 return rr350 351 352 """ Intersection calculates the common language. works only353 for det and makes sense only for relaxed versions """354 def intersect(self,D2):355 D2.t_full()356 self.t_full()357 stnumbering = {(0,0):0} # store for the states358 cnumber = 0 # number for the states new DFA359 acc = set([]) # acc-set for the new DFA360 trans = [{}] # transrel for the new. sigma is union.361 stack = [(0,0)] # going in "pseudoDFS"362 Sg1 = set(self.Sigma)363 Sg2 = set(D2.Sigma)364 SigmaU = Sg1.union(Sg2) # union of alphabets365 SigmaU.remove('tau') # We don't consider them.366 SigmaI = Sg1.intersection(Sg2)367 SigmaI.remove('tau')368 SL = ['tau']369 SL.extend(list(SigmaI))370 while stack:371 (x,y) = stack.pop()372 st = stnumbering[(x,y)] 373 if x in self.acc and y in D2.acc: # union374 acc.add(st)375 for a in SigmaU: #NOTE it dismisses taus. 376 if a in SigmaI: # this is in joint alp.377 ai = SL.index(a)378 i = self.Sigma.index(a)379 j = D2.Sigma.index(a)380 for xp in self.Trans[x][i]:381 for yp in D2.Trans[y][j]:382 if not (xp,yp) in stnumbering:383 cnumber += 1384 stnumbering[(xp,yp)] = cnumber385 stack.append((xp,yp))386 trans.append({})387 stp = stnumbering[(xp,yp)]388 if not ai in trans[st]:389 trans[st][ai] = set([])390 trans[st][ai].add(stp)391 elif a in Sg1: # here only if in Sg1,not sg2392 ai = 0 # Noncommon alphabets are replaced by 0393 i = self.Sigma.index(a)394 for xp in self.Trans[x][i]:395 if not (xp,y) in stnumbering:396 cnumber += 1397 stnumbering[(xp,y)] = cnumber398 stack.append((xp,y))399 trans.append({})400 stp = stnumbering[(xp,y)]401 if not ai in trans[st]:402 trans[st][ai] = set([])403 trans[st][ai].add(stp)404 elif a in Sg2:405 ai = 0406 j = D2.Sigma.index(a)407 for yp in D2.Trans[y][j]:408 if not (x,yp) in stnumbering:409 cnumber += 1410 stnumbering[(x,yp)] = cnumber411 stack.append((x,yp))412 trans.append({})413 stp = stnumbering[(x,yp)]414 if not ai in trans[st]:415 trans[st][ai] = set([])416 trans[st][ai].add(stp)417 rr = DFA_lsts()418 rr.Trans = trans419 rr.addSigma(SL)420 rr.acc = acc421 rr.remove_taus()422 rr.det()423 rr.cln()424 rr.unreach()425 return rr426 """ retain remoces all the actions except those in 'act'427 """428 def retain(self,act):429 Sigma = act430 trns = [{} for i in self.Trans]431 for s,t in enumerate(self.Trans):432 for a in self.Sigma:433 i = self.Sigma.index(a)434 if a in act:435 j = Sigma.index(a)436 trns[s][j] = set([])437 if i in t:438 trns[s][j].update(t[i])439 elif i in t:440 if not 0 in trns[s]:441 trns[s][0] = set([])442 trns[s][0].update(t[i])443 self.Trans = trns444 self.Sigma = Sigma445 self.remove_taus()446 self.det()447 self.cln()448 self.unreach()449 450 451 452 """ Negate is a function that takes another dfa,453 and removes from it all accepting traces that454 this one accepts. Result is nondet, in general.455 Not safe otherwise!! """456 def negate(self,D2):457 self.retain(D2.Sigma) 458 if DEBUG: 459 self.to_LSTS(open('foo.lsts','w')).write()460 self.t_full()461 stnumbering = {(0,0):0} # store for the states462 cnumber = 0 # number for the states new DFA463 acc = set([]) # acc-set for the new DFA464 uacc = set([]) # accset of current;used for negating.465 trans = [{}] # transrel for the new. sigma from D2466 stack = [(0,0)] # going in "pseudoDFS"467 while stack:468 (x,y) = stack.pop()469 st = stnumbering[(x,y)]470 if y in D2.acc:471 acc.add(st) # not the final;must be fixed472 if x in self.acc:473 uacc.add(st)474 for a in self.Trans[x]: ## We follow self.475 if self.Sigma[a] in D2.Sigma: # this is in joint alp.476 b = D2.Sigma.index(self.Sigma[a])477 for xp in self.Trans[x][a]:478 if not b in D2.Trans[y]:479 continue480 for yp in D2.Trans[y][b]:481 if not (xp,yp) in stnumbering:482 cnumber += 1483 stnumbering[(xp,yp)] = cnumber484 stack.append((xp,yp))485 trans.append({})486 stp = stnumbering[(xp,yp)]487 if not b in trans[st]:488 trans[st][b] = set([])489 trans[st][b].add(stp)490 else: # Others become taus. 491 for xp in self.Trans[x][a]:492 if not (xp,y) in stnumbering:493 cnumber += 1494 stnumbering[(xp,y)] = cnumber495 stack.append((xp,y))496 trans.append({})497 stp = stnumbering[(xp,y)]498 if not 0 in trans[st]:499 trans[st][0] = set([])500 trans[st][0].add(stp)501 # Now we clean the acc-sets.502 503 acc.difference_update(uacc)504 rr = DFA_lsts()505 rr.Trans = trans506 rr.addSigma(D2.Sigma)507 rr.acc = acc508 rr.remove_taus()509 rr.det()510 return rr511 def addDistances(self):512 ptrans = [{} for st in self.Trans]513 for st in xrange(len(self.Trans)):514 for a in self.Trans[st]:515 for sp in self.Trans[st][a]:516 if not a in ptrans[sp]:517 ptrans[sp][a] = set([])518 ptrans[sp][a].add(st)519 dist = {}520 for st in self.acc:521 found = set([st])522 dist[st] = 0523 Q = [st]524 while Q:525 s = Q.pop(0)526 for a in ptrans[s]:527 for sp in ptrans[s][a]:528 if sp in found:529 continue530 found.add(sp)531 if not sp in dist or dist[sp] > dist[s] + 1:532 dist[sp] = dist[s] + 1533 Q.append(sp)534 self.dist = dist535class ErrorModel:536 def __init__(self,input_lsts,inst=sys.stdin,outst=sys.stdout):537 if input_lsts: self.A = DFA_lsts(input_lsts)538 else: self.A = None539 self.B = None540 self.inp = inst541 self.out = outst542 def handle_tr(self,tr,N):543 global i544 A = DFA_lsts()545 T = [{}]546 acc = set([])547 cnum = 0548 Sigma = ['tau']549 for name in tr:550 if not name in Sigma:551 Sigma.append(name)552 index = Sigma.index(name)553 T[cnum][index] = set([cnum+1])554 T.append({})555 cnum+=1556 acc.add(cnum)557 A.Trans= T558 A.acc = acc559 A.Sigma = Sigma560 A.relax()561 A.det()562 if N == 'B':563 if not self.A:564 x = Exception('first trace should be an error\n')565 self.A = A.negate(self.A)566 if N == 'A':567 if self.A:568 self.A = self.A.intersect(A)569 else:570 self.A = A571 # reduce from A all (true) prefixes of tr that end with572 # the triggering action tr[-1]573 for index, name in enumerate(tr[:-1]):574 if name == tr[-1]: self.handle_tr(tr[:index+1], 'B')575 def read_tr(self):576 toproc = []577 a = self.inp.readline().rstrip()578 while a:579 if a in ['pass', 'inconclusive']:580 self.handle_tr(toproc,'B')581 toproc = []582 elif a == 'fail':583 self.handle_tr(toproc,'A')584 toproc = []585 else:586 toproc.append(a)587 a = self.inp.readline().rstrip()588 589 def output(self):590 if self.B and self.A:591 if self.A :592 X = self.B.negate(self.A)593 X.remove_taus()594 elif self.A:595 X = self.A596 else:597 raise Exception('no A-traces, man\n')598 X.min()599 X.addDistances()600 out = X.to_LSTS(self.out)601 out.write()602 def go_online(self): 603 self.read_tr()604 self.output()605if __name__=="__main__":606 if len(sys.argv) > 1:607 input_lsts_file = file(sys.argv[1])...

Full Screen

Full Screen

fmbt-traces2dfa

Source:fmbt-traces2dfa Github

copy

Full Screen

...167 168 """ Min minimizes. Warning: bad and silly. """169 def min(self):170 self.backwards()171 self.remove_taus()172 self.det()173 self.cln()174 self.unreach()175 self.backwards()176 self.remove_taus()177 self.det()178 self.cln()179 self.unreach()180 """ helper method remove_taus removes taus and replaces with181 regular nondeteminism """182 def remove_taus(self):183 init = 0184 foundstates = set([init])185 stack = [init]186 while stack:187 s = stack.pop()188 found2 = set([s])189 stack2 = [s]190 while stack2:191 s2 = stack2.pop()192 if not 0 in self.Trans[s2]:continue193 for s2p in self.Trans[s2][0]:194 if not s2p in found2:195 stack2.append(s2p)196 found2.add(s2p)197 for a in self.Trans[s2p]:198 if a == 0:continue199 if not a in self.Trans[s]:200 self.Trans[s][a] = set([]) 201 self.Trans[s][a].update(self.Trans[s2p][a])202 203 for a in self.Trans[s]:204 if a == 0:205 self.Trans[s][a] = set([])206 continue207 for sp in self.Trans[s][a]:208 if sp in foundstates:continue209 foundstates.add(sp)210 stack.append(sp) 211 """ makes current deterministic.212 warning: may be exponential """213 def det(self):214 init = (0,)215 newstates = {init:0}216 cnum = 0217 stack = [init]218 trel = [{}]219 acc = set([])220 while stack:221 ss = stack.pop()222 for a in xrange(len(self.Sigma)):223 news = set([])224 ac = False225 for s in ss:226 if a in self.Trans[s]: 227 for sp in self.Trans[s][a]:228 news.add(sp)229 if sp in self.acc:230 ac = True231 news = list(news)232 news.sort()233 news = tuple(news)234 if not news in newstates:235 cnum +=1236 newstates[news] = cnum237 trel.append({})238 stack.append(news)239 spp = newstates[news] 240 trel[newstates[ss]][a] = set([spp])241 if ac:acc.add(spp)242 self.Trans = trel243 self.acc = acc244 """ union adds D2, and this is the nondet-245 non-interleaving version """246 def union(self,D2):247 self.addSigma(D2.Sigma)248 cnum = len(self.Trans)249 newstates = {0:0}250 for s in xrange(len(D2.Trans)):251 for a in D2.Sigma:252 ai = D2.Sigma.index(a)253 ni = self.Sigma.index(a)254 if not ai in D2.Trans[s]: continue255 for sp in D2.Trans[s][ai]:256 if not sp in newstates:257 self.Trans.append({})258 newstates[sp] = cnum259 cnum+=1260 ss = newstates[s]261 ssp = newstates[sp]262 if sp in D2.acc:263 self.acc.add(ssp)264 if not ni in self.Trans[ss]:265 self.Trans[ss][ni] = set([])266 self.Trans[ss][ni].add(ssp)267 268 """ 'add' adds another trace to current 269 and returns a new DFA. Safe only for det.270 Interleaves them completely """271 def add(self,D2):272 stnumbering = {(0,0):0} # store for the states273 cnumber = 0 # number for the states new DFA274 acc = set([]) # acc-set for the new DFA275 trans = [{}] # transrel for the new. sigma is union.276 stack = [(0,0)] # going in "pseudoDFS"277 Sg1 = self.Sigma278 Sg2 = D2.Sigma279 Sigma = set(Sg1).union(Sg2) # union of alphabets280 Sigma.remove('tau')281 SL = ['tau']282 SL.extend(list(Sigma))283 while stack:284 (x,y) = stack.pop()285 st = stnumbering[(x,y)] 286 if x in self.acc or y in D2.acc: # union287 acc.add(st)288 for a in Sigma:289 ai = SL.index(a)290 if a in Sg1 and a in Sg2: # this is in joint alp.291 i = self.Sigma.index(a)292 j = D2.Sigma.index(a)293 if x == None or not i in self.Trans[x]:294 Xp = [None]295 else:296 Xp = self.Trans[x][i]297 if y == None or not j in D2.Trans[y]:298 Yp = [None]299 else:300 Yp = D2.Trans[y][j]301 succ = [(xp,yp) for xp in Xp for yp in Yp]302 for xp,yp in succ:303 if not (xp,yp) in stnumbering:304 cnumber += 1305 stnumbering[(xp,yp)] = cnumber306 stack.append((xp,yp))307 trans.append({})308 stp = stnumbering[(xp,yp)]309 if not ai in trans[st]:310 trans[st][ai] = set([])311 trans[st][ai].add(stp)312 elif a in Sg1:313 i = self.Sigma.index(a)314 if x==None or not i in self.Trans[x]: continue315 for xp in self.Trans[x][i]:316 if not (xp,y) in stnumbering:317 cnumber += 1318 stnumbering[(xp,y)] = cnumber319 stack.append((xp,y))320 trans.append({})321 stp = stnumbering[(xp,y)]322 if not ai in trans[st]:323 trans[st][ai] = set([])324 trans[st][ai].add(stp)325 elif a in Sg2:326 j = D2.Sigma.index(a)327 if y==None or not j in D2.Trans[y]: continue328 for yp in D2.Trans[y][j]:329 if not (x,yp) in stnumbering:330 cnumber += 1331 stnumbering[(x,yp)] = cnumber332 stack.append((x,yp))333 trans.append({})334 stp = stnumbering[(x,yp)]335 if not ai in trans[st]:336 trans[st][ai] = set([])337 trans[st][ai].add(stp)338 rr = DFA_lsts()339 rr.Trans = trans340 rr.addSigma(SL)341 rr.acc = acc342 return rr343 344 345 """ Intersection calculates the common language. works only346 for det and makes sense only for relaxed versions """347 def intersect(self,D2):348 D2.t_full()349 self.t_full()350 stnumbering = {(0,0):0} # store for the states351 cnumber = 0 # number for the states new DFA352 acc = set([]) # acc-set for the new DFA353 trans = [{}] # transrel for the new. sigma is union.354 stack = [(0,0)] # going in "pseudoDFS"355 Sg1 = set(self.Sigma)356 Sg2 = set(D2.Sigma)357 SigmaU = Sg1.union(Sg2) # union of alphabets358 SigmaU.remove('tau') # We don't consider them.359 SigmaI = Sg1.intersection(Sg2)360 SigmaI.remove('tau')361 SL = ['tau']362 SL.extend(list(SigmaI))363 while stack:364 (x,y) = stack.pop()365 st = stnumbering[(x,y)] 366 if x in self.acc and y in D2.acc: # union367 acc.add(st)368 for a in SigmaU: #NOTE it dismisses taus. 369 if a in SigmaI: # this is in joint alp.370 ai = SL.index(a)371 i = self.Sigma.index(a)372 j = D2.Sigma.index(a)373 for xp in self.Trans[x][i]:374 for yp in D2.Trans[y][j]:375 if not (xp,yp) in stnumbering:376 cnumber += 1377 stnumbering[(xp,yp)] = cnumber378 stack.append((xp,yp))379 trans.append({})380 stp = stnumbering[(xp,yp)]381 if not ai in trans[st]:382 trans[st][ai] = set([])383 trans[st][ai].add(stp)384 elif a in Sg1: # here only if in Sg1,not sg2385 ai = 0 # Noncommon alphabets are replaced by 0386 i = self.Sigma.index(a)387 for xp in self.Trans[x][i]:388 if not (xp,y) in stnumbering:389 cnumber += 1390 stnumbering[(xp,y)] = cnumber391 stack.append((xp,y))392 trans.append({})393 stp = stnumbering[(xp,y)]394 if not ai in trans[st]:395 trans[st][ai] = set([])396 trans[st][ai].add(stp)397 elif a in Sg2:398 ai = 0399 j = D2.Sigma.index(a)400 for yp in D2.Trans[y][j]:401 if not (x,yp) in stnumbering:402 cnumber += 1403 stnumbering[(x,yp)] = cnumber404 stack.append((x,yp))405 trans.append({})406 stp = stnumbering[(x,yp)]407 if not ai in trans[st]:408 trans[st][ai] = set([])409 trans[st][ai].add(stp)410 rr = DFA_lsts()411 rr.Trans = trans412 rr.addSigma(SL)413 rr.acc = acc414 rr.remove_taus()415 rr.det()416 rr.cln()417 rr.unreach()418 return rr419 def retain(self,act):420 Sigma = act421 trns = [{} for i in self.Trans]422 for s,t in enumerate(self.Trans):423 for a in self.Sigma:424 i = self.Sigma.index(a)425 if a in act:426 j = Sigma.index(a)427 trns[s][j] = set([])428 if i in t:429 trns[s][j].update(t[i])430 elif i in t:431 if not 0 in trns[s]:432 trns[s][0] = set([])433 trns[s][0].update(t[i])434 self.Trans = trns435 self.Sigma = Sigma436 self.remove_taus()437 self.det()438 self.cln()439 self.unreach()440 441 442 443 """ Negate is a function that takes another dfa,444 and removes from it all accepting traces that445 this one accepts. Result is nondet, in general.446 Not safe otherwise!! """447 def negate(self,D2):448 self.retain(D2.Sigma) 449 if DEBUG:450 self.to_LSTS(open('foo.lsts','w')).write()451 self.t_full()452 stnumbering = {(0,0):0} # store for the states453 cnumber = 0 # number for the states new DFA454 acc = set([]) # acc-set for the new DFA455 uacc = set([]) # accset of current;used for negating.456 trans = [{}] # transrel for the new. sigma from D2457 stack = [(0,0)] # going in "pseudoDFS"458 while stack:459 (x,y) = stack.pop()460 st = stnumbering[(x,y)]461 if y in D2.acc:462 acc.add(st) # not the final;must be fixed463 if x in self.acc:464 uacc.add(st)465 for a in self.Trans[x]: ## We follow self.466 if self.Sigma[a] in D2.Sigma: # this is in joint alp.467 b = D2.Sigma.index(self.Sigma[a])468 for xp in self.Trans[x][a]:469 if not b in D2.Trans[y]:470 continue471 for yp in D2.Trans[y][b]:472 if not (xp,yp) in stnumbering:473 cnumber += 1474 stnumbering[(xp,yp)] = cnumber475 stack.append((xp,yp))476 trans.append({})477 stp = stnumbering[(xp,yp)]478 if not b in trans[st]:479 trans[st][b] = set([])480 trans[st][b].add(stp)481 else: # Others become taus. 482 for xp in self.Trans[x][a]:483 if not (xp,y) in stnumbering:484 cnumber += 1485 stnumbering[(xp,y)] = cnumber486 stack.append((xp,y))487 trans.append({})488 stp = stnumbering[(xp,y)]489 if not 0 in trans[st]:490 trans[st][0] = set([])491 trans[st][0].add(stp)492 # Now we clean the acc-sets.493 494 acc.difference_update(uacc)495 rr = DFA_lsts()496 rr.Trans = trans497 rr.addSigma(D2.Sigma)498 rr.acc = acc499 rr.remove_taus()500 rr.det()501 return rr502class ErrorModel:503 def __init__(self,inst=sys.stdin,outst=sys.stdout):504 self.A = None505 self.B = None506 self.inp = inst507 self.out = outst508 def handle_tr(self,tr,N):509 global i510 A = DFA_lsts()511 T = [{}]512 acc = set([])513 cnum = 0514 Sigma = ['tau']515 for name in tr:516 if not name in Sigma:517 Sigma.append(name)518 index = Sigma.index(name)519 T[cnum][index] = set([cnum+1])520 T.append({})521 cnum+=1522 acc.add(cnum)523 A.Trans= T524 A.acc = acc525 A.Sigma = Sigma526 A.relax()527 A.det()528 if N == 'B':529 if not self.A:530 x = Exception('first trace should be an error\n')531 self.A = A.negate(self.A)532 if N == 'A':533 if self.A:534 self.A = self.A.intersect(A)535 else:536 self.A = A537 # reduce from A all (true) prefixes of tr that end with538 # the triggering action tr[-1]539 for index, name in enumerate(tr[:-1]):540 if name == tr[-1]: self.handle_tr(tr[:index+1], 'B')541 def read_tr(self):542 toproc = []543 a = self.inp.readline().rstrip()544 while a:545 if a == 'pass':546 self.handle_tr(toproc,'B')547 toproc = []548 elif a == 'fail':549 self.handle_tr(toproc,'A')550 toproc = []551 else:552 toproc.append(a)553 a = self.inp.readline().rstrip()554 555 def output(self):556 if self.B and self.A:557 if self.A :558 X = self.B.negate(self.A)559 X.remove_taus()560 elif self.A:561 X = self.A562 else:563 raise Exception('no A-traces, man\n')564 X.min()565 out = X.to_LSTS(self.out)566 out.write()567 def go_online(self): 568 self.read_tr()569 self.output()570if __name__=="__main__":571 X = ErrorModel()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful