def test_intersection_union(verbose=False, show=False): props = ['A', 'B', 'C'] dfa1 = hold(props, prop='A', duration=1, negation=False) dfa1 = within(dfa1, low=1, high=5) dfa2 = hold(props, prop='B', duration=2, negation=False) dfa2 = within(dfa2, low=0, high=4) for operation in [union]: #intersection, union]: if verbose: print 'Operation:', operation.__name__ dfa = operation(dfa1, dfa2) if verbose: for fsa in [dfa1, dfa2, dfa]: print fsa print fsa.tree print fsa.counters print for u, v, d in fsa.g.edges_iter(data=True): print (u, v), d if show: dfa1.visualize(draw='matplotlib') plt.show() dfa2.visualize(draw='matplotlib') plt.show() dfa.visualize(draw='matplotlib') plt.show()
def test_intersection_union(verbose=False, show=False): props = ['A', 'B', 'C'] dfa1 = hold(props, prop='A', duration=1, negation=False) dfa1 = within(dfa1, low=1, high=5) dfa2 = hold(props, prop='B', duration=2, negation=False) dfa2 = within(dfa2, low=0, high=4) for operation in [union]: #intersection, union]: if verbose: print 'Operation:', operation.__name__ dfa = operation(dfa1, dfa2) if verbose: for fsa in [dfa1, dfa2, dfa]: print fsa print fsa.tree print fsa.counters print for u, v, d in fsa.g.edges_iter(data=True): print (u, v), d if show: dfa1.visualize(draw='matplotlib') plt.show() dfa2.visualize(draw='matplotlib') plt.show() dfa.visualize(draw='matplotlib') plt.show()
def test_repeat(verbose=False, show=False): setDFAType(DFAType.Normal) props = ['A', 'B', 'C'] dfa = hold(props, prop='A', duration=2, negation=False) dfa = repeat(dfa, low=2, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with low zero dfa = hold(props, prop='A', duration=2, negation=False) dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with trap state dfa = hold(props, prop='A', duration=2, negation=False) dfa.add_trap_state() dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with truncated dfa dfa1 = hold(props, prop='A', duration=2, negation=False) dfa2 = hold(props, prop='B', duration=3, negation=False) dfa = union(dfa1, dfa2) if verbose: print '[test_within] Preprocessing:' print dfa1 print dfa2 print 'Union' print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show()
def test_repeat(verbose=False, show=False): setDFAType(DFAType.Normal) props = ['A', 'B', 'C'] dfa = hold(props, prop='A', duration=2, negation=False) dfa = repeat(dfa, low=2, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with low zero dfa = hold(props, prop='A', duration=2, negation=False) dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with trap state dfa = hold(props, prop='A', duration=2, negation=False) dfa.add_trap_state() dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show() # Test with truncated dfa dfa1 = hold(props, prop='A', duration=2, negation=False) dfa2 = hold(props, prop='B', duration=3, negation=False) dfa = union(dfa1, dfa2) if verbose: print '[test_within] Preprocessing:' print dfa1 print dfa2 print 'Union' print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d dfa = repeat(dfa, low=0, high=4) if verbose: print dfa for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize() plt.show()
def test_eventually(verbose=False, show=False): setDFAType(DFAType.Infinity) props = ['A', 'B', 'C'] dfa = hold(props, prop='A', duration=2, negation=False) dfa = eventually(dfa, low=2, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show() # Test with low zero dfa = hold(props, prop='A', duration=2, negation=False) dfa = eventually(dfa, low=0, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show() # Test with trap state dfa = hold(props, prop='A', duration=2, negation=False) dfa.add_trap_state() dfa = eventually(dfa, low=0, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show()
def test_eventually(verbose=False, show=False): setDFAType(DFAType.Infinity) props = ['A', 'B', 'C'] dfa = hold(props, prop='A', duration=2, negation=False) dfa = eventually(dfa, low=2, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show() # Test with low zero dfa = hold(props, prop='A', duration=2, negation=False) dfa = eventually(dfa, low=0, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show() # Test with trap state dfa = hold(props, prop='A', duration=2, negation=False) dfa.add_trap_state() dfa = eventually(dfa, low=0, high=5) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa.visualize(draw='matplotlib') plt.show()
def test_hold(verbose=False, show=False): props = ['A', 'B', 'C'] for kwargs in [{'prop':'A', 'duration':2, 'negation':False}, {'prop':'B', 'duration':2, 'negation':True}]: dfa = hold(props, **kwargs) if verbose: print dfa if show: dfa.visualize(draw='matplotlib') plt.show()
def test_hold(verbose=False, show=False): props = ['A', 'B', 'C'] for kwargs in [{'prop':'A', 'duration':2, 'negation':False}, {'prop':'B', 'duration':2, 'negation':True}]: dfa = hold(props, **kwargs) if verbose: print dfa if show: dfa.visualize(draw='matplotlib') plt.show()
def test_concatenation(verbose=False, show=False): props = ['A', 'B', 'C'] dfa1 = hold(props, prop='A', duration=2, negation=False) dfa1 = eventually(dfa1, low=1, high=5) dfa2 = hold(props, prop='B', duration=3, negation=False) dfa2 = eventually(dfa2, low=0, high=4) dfa = concatenation(dfa1, dfa2) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa1.visualize(draw='matplotlib') plt.show() dfa2.visualize(draw='matplotlib') plt.show() dfa.visualize(draw='matplotlib') plt.show()
def test_concatenation(verbose=False, show=False): props = ['A', 'B', 'C'] dfa1 = hold(props, prop='A', duration=2, negation=False) dfa1 = eventually(dfa1, low=1, high=5) dfa2 = hold(props, prop='B', duration=3, negation=False) dfa2 = eventually(dfa2, low=0, high=4) dfa = concatenation(dfa1, dfa2) if verbose: print dfa print dfa.tree print dfa.counters print for u, v, d in dfa.g.edges_iter(data=True): print (u, v), d if show: dfa1.visualize(draw='matplotlib') plt.show() dfa2.visualize(draw='matplotlib') plt.show() dfa.visualize(draw='matplotlib') plt.show()
def formula(self, ): dfa = None p = None low = None high = None INT2 = None INT3 = None PROP4 = None a = None b = None phi = None try: try: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:65:5: ( ^( OR a= formula b= formula ) | ^( AND a= formula b= formula ) | ^( NOT a= formula ) | ^( CONCAT a= formula b= formula ) | ^( HOLD INT p= PROP ) | ^( HOLD INT ^( NOT p= PROP ) ) | ^( WITHIN phi= formula low= INT high= INT ) | PROP | TRUE | FALSE ) alt1 = 10 alt1 = self.dfa1.predict(self.input) if alt1 == 1: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:65:9: ^( OR a= formula b= formula ) pass self.match(self.input, OR, self.FOLLOW_OR_in_formula88) self.match(self.input, DOWN, None) self._state.following.append( self.FOLLOW_formula_in_formula93) a = self.formula() self._state.following.pop() self._state.following.append( self.FOLLOW_formula_in_formula97) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = union(a, b) #action end elif alt1 == 2: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:66:9: ^( AND a= formula b= formula ) pass self.match(self.input, AND, self.FOLLOW_AND_in_formula112) self.match(self.input, DOWN, None) self._state.following.append( self.FOLLOW_formula_in_formula116) a = self.formula() self._state.following.pop() self._state.following.append( self.FOLLOW_formula_in_formula120) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = intersection(a, b) #action end elif alt1 == 3: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:67:9: ^( NOT a= formula ) pass self.match(self.input, NOT, self.FOLLOW_NOT_in_formula135) self.match(self.input, DOWN, None) self._state.following.append( self.FOLLOW_formula_in_formula139) a = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = complement(a) #action end elif alt1 == 4: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:68:9: ^( CONCAT a= formula b= formula ) pass self.match(self.input, CONCAT, self.FOLLOW_CONCAT_in_formula164) self.match(self.input, DOWN, None) self._state.following.append( self.FOLLOW_formula_in_formula168) a = self.formula() self._state.following.pop() self._state.following.append( self.FOLLOW_formula_in_formula172) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = concatenation(a, b) #action end elif alt1 == 5: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:69:9: ^( HOLD INT p= PROP ) pass self.match(self.input, HOLD, self.FOLLOW_HOLD_in_formula187) self.match(self.input, DOWN, None) INT2 = self.match(self.input, INT, self.FOLLOW_INT_in_formula189) p = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula193) self.match(self.input, UP, None) #action start dfa = hold(self.props, p.text, int(INT2.text), negation=False) #action end elif alt1 == 6: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:72:9: ^( HOLD INT ^( NOT p= PROP ) ) pass self.match(self.input, HOLD, self.FOLLOW_HOLD_in_formula207) self.match(self.input, DOWN, None) INT3 = self.match(self.input, INT, self.FOLLOW_INT_in_formula209) self.match(self.input, NOT, self.FOLLOW_NOT_in_formula212) self.match(self.input, DOWN, None) p = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula216) self.match(self.input, UP, None) self.match(self.input, UP, None) #action start dfa = hold(self.props, p.text, int(INT3.text), negation=True) #action end elif alt1 == 7: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:75:9: ^( WITHIN phi= formula low= INT high= INT ) pass self.match(self.input, WITHIN, self.FOLLOW_WITHIN_in_formula231) self.match(self.input, DOWN, None) self._state.following.append( self.FOLLOW_formula_in_formula235) phi = self.formula() self._state.following.pop() low = self.match(self.input, INT, self.FOLLOW_INT_in_formula239) high = self.match(self.input, INT, self.FOLLOW_INT_in_formula243) self.match(self.input, UP, None) #action start dfa = within(phi, int(low.text), int(high.text)) #action end elif alt1 == 8: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:78:9: PROP pass PROP4 = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula256) #action start dfa = accept_prop(self.props, prop=PROP4) #action end elif alt1 == 9: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:79:9: TRUE pass self.match(self.input, TRUE, self.FOLLOW_TRUE_in_formula291) #action start dfa = accept_prop(self.props, boolean=True) #action end elif alt1 == 10: # C:\\Users\\Cristian\\Dropbox\\work\\workspace\\TWTL\\src\\twtl2dfa.g:80:9: FALSE pass self.match(self.input, FALSE, self.FOLLOW_FALSE_in_formula326) #action start dfa = accept_prop(self.props, boolean=False) #action end except RecognitionException, re: self.reportError(re) self.recover(self.input, re) finally: pass return dfa
def formula(self, ): dfa = None p = None low = None high = None INT2 = None INT3 = None PROP4 = None a = None b = None phi = None try: try: # twtl2dfa.g:66:5: ( ^( OR a= formula b= formula ) | ^( AND a= formula b= formula ) | ^( NOT a= formula ) | ^( CONCAT a= formula b= formula ) | ^( HOLD INT p= PROP ) | ^( HOLD INT ^( NOT p= PROP ) ) | ^( WITHIN phi= formula low= INT high= INT ) | PROP | TRUE | FALSE ) alt1 = 10 LA1 = self.input.LA(1) if LA1 == OR: alt1 = 1 elif LA1 == AND: alt1 = 2 elif LA1 == NOT: alt1 = 3 elif LA1 == CONCAT: alt1 = 4 elif LA1 == HOLD: LA1_5 = self.input.LA(2) if (LA1_5 == 2) : LA1_10 = self.input.LA(3) if (LA1_10 == INT) : LA1_11 = self.input.LA(4) if (LA1_11 == PROP) : alt1 = 5 elif (LA1_11 == NOT) : alt1 = 6 else: nvae = NoViableAltException("", 1, 11, self.input) raise nvae else: nvae = NoViableAltException("", 1, 10, self.input) raise nvae else: nvae = NoViableAltException("", 1, 5, self.input) raise nvae elif LA1 == WITHIN: alt1 = 7 elif LA1 == PROP: alt1 = 8 elif LA1 == TRUE: alt1 = 9 elif LA1 == FALSE: alt1 = 10 else: nvae = NoViableAltException("", 1, 0, self.input) raise nvae if alt1 == 1: # twtl2dfa.g:66:9: ^( OR a= formula b= formula ) pass self.match(self.input, OR, self.FOLLOW_OR_in_formula88) self.match(self.input, DOWN, None) self._state.following.append(self.FOLLOW_formula_in_formula93) a = self.formula() self._state.following.pop() self._state.following.append(self.FOLLOW_formula_in_formula97) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = union(a, b) #action end elif alt1 == 2: # twtl2dfa.g:67:9: ^( AND a= formula b= formula ) pass self.match(self.input, AND, self.FOLLOW_AND_in_formula112) self.match(self.input, DOWN, None) self._state.following.append(self.FOLLOW_formula_in_formula116) a = self.formula() self._state.following.pop() self._state.following.append(self.FOLLOW_formula_in_formula120) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = intersection(a, b) #action end elif alt1 == 3: # twtl2dfa.g:68:9: ^( NOT a= formula ) pass self.match(self.input, NOT, self.FOLLOW_NOT_in_formula135) self.match(self.input, DOWN, None) self._state.following.append(self.FOLLOW_formula_in_formula139) a = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = complement(a) #action end elif alt1 == 4: # twtl2dfa.g:69:9: ^( CONCAT a= formula b= formula ) pass self.match(self.input, CONCAT, self.FOLLOW_CONCAT_in_formula164) self.match(self.input, DOWN, None) self._state.following.append(self.FOLLOW_formula_in_formula168) a = self.formula() self._state.following.pop() self._state.following.append(self.FOLLOW_formula_in_formula172) b = self.formula() self._state.following.pop() self.match(self.input, UP, None) #action start dfa = concatenation(a, b) #action end elif alt1 == 5: # twtl2dfa.g:70:9: ^( HOLD INT p= PROP ) pass self.match(self.input, HOLD, self.FOLLOW_HOLD_in_formula187) self.match(self.input, DOWN, None) INT2 = self.match(self.input, INT, self.FOLLOW_INT_in_formula189) p = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula193) self.match(self.input, UP, None) #action start dfa = hold(self.props, p.text, int(INT2.text), negation=False) #action end elif alt1 == 6: # twtl2dfa.g:73:9: ^( HOLD INT ^( NOT p= PROP ) ) pass self.match(self.input, HOLD, self.FOLLOW_HOLD_in_formula207) self.match(self.input, DOWN, None) INT3 = self.match(self.input, INT, self.FOLLOW_INT_in_formula209) self.match(self.input, NOT, self.FOLLOW_NOT_in_formula212) self.match(self.input, DOWN, None) p = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula216) self.match(self.input, UP, None) self.match(self.input, UP, None) #action start dfa = hold(self.props, p.text, int(INT3.text), negation=True) #action end elif alt1 == 7: # twtl2dfa.g:76:9: ^( WITHIN phi= formula low= INT high= INT ) pass self.match(self.input, WITHIN, self.FOLLOW_WITHIN_in_formula231) self.match(self.input, DOWN, None) self._state.following.append(self.FOLLOW_formula_in_formula235) phi = self.formula() self._state.following.pop() low = self.match(self.input, INT, self.FOLLOW_INT_in_formula239) high = self.match(self.input, INT, self.FOLLOW_INT_in_formula243) self.match(self.input, UP, None) #action start dfa = within(phi, int(low.text), int(high.text)) #action end elif alt1 == 8: # twtl2dfa.g:79:9: PROP pass PROP4 = self.match(self.input, PROP, self.FOLLOW_PROP_in_formula256) #action start dfa = accept_prop(self.props, prop=PROP4) #action end elif alt1 == 9: # twtl2dfa.g:80:9: TRUE pass self.match(self.input, TRUE, self.FOLLOW_TRUE_in_formula291) #action start dfa = accept_prop(self.props, boolean=True) #action end elif alt1 == 10: # twtl2dfa.g:81:9: FALSE pass self.match(self.input, FALSE, self.FOLLOW_FALSE_in_formula326) #action start dfa = accept_prop(self.props, boolean=False) #action end except RecognitionException, re: self.reportError(re) self.recover(self.input, re) finally: pass return dfa