def test_simple_nested_approximated(self): # weights = [AdaptType(1), AdaptType("k"), AdaptType("k"), AdaptType(1)] query = [0, 0, 0, 1, 0, 1] edges = [(0, 4), (1, 2), (1, 3), (2, 3), (3, 2), (3, 3)] weights = [AdaptType("INF")]*len(query) ctl_edges = [(0, 1), (1, 2), (2, 1), (2, 2)] transitions = [ (0, [DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET)], 1, [0]), (1, [DifferenceConstraint("i", None, "1", DifferenceConstraint.DCType.DEC), DifferenceConstraint("j", "i", "0", DifferenceConstraint.DCType.RESET)], 2, [1, 2]), (2, [DifferenceConstraint("j", None, "1", DifferenceConstraint.DCType.DEC)], 2, [3]), (2, [], 1, []) ] bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) bound_infer.attach_weights() print("The Reachability Bounds Expected for Vertices in the Simple Nested While Graph are: [1, k, k, k!] ") print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) adapt_search = AdaptSearchAlgRefined(bound_infer.graph) adapt_search.search_adapt() print("The Adaptivity Expected for Simple Nested While Algorithm is: 2 + k! ") print("The Adaptivity From This Graph is: ", adapt_search.get_adapt())
def seq_multivar(self): query = [1, 1, 1, 1] edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)] weights = [AdaptType("INF")] * len(query) # adapt_search = self.ALG(Graph(edges, weights, query)) ctl_edges = [(2, 3), (1, 2), (0, 1), (3, 4)] transitions = [ (2, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 3, [2]), (1, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0]), (3, [ DifferenceConstraint("w", None, "Q", DifferenceConstraint.DCType.RESET) ], -1, [3]) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) print( "The Reachability Bounds Expected for Vertices in Pure Sequence Graph are: [1,1,1,1] " ) print("The Adaptivity Expected for Simple Seq Algorithm is: 4 ")
def abscfg_parse(self): with open(self.args.abs_cfg, "r") as graphdata: # _ = [graphdata.readline() for _ in range(3)] n = int(graphdata.readline()) edges = [[(n - 1) if int(v) == -1 else int(v) for v in e.split(",")] for e in graphdata.readline().split(";")[:-1]] transitions = [] for l in graphdata.readlines(): l1, dc, l2, v = l.split(";") if dc == "": dc_set = [] v_set = [int(v)] # transitions.append((int(l1), [ ], int(l2), [int(v)])) else: v_set = [int(v)] (var, avar, c, ctype) = dc.split(",") print((var, avar, c, ctype)) dc_type = DifferenceConstraint.DCType.RESET if ctype == "RESET" else DifferenceConstraint.DCType.INC if ctype == "INC" else DifferenceConstraint.DCType.DEC avar = None if avar == "" else avar c = None if c == "" else int(c) if isinstance(c, int) else c dc_set = [DifferenceConstraint(var, avar, c, dc_type)] transitions.append((int(l1), dc_set, int(l2), v_set)) # transitions.append((int(l1), [ DifferenceConstraint(var, avar, c, dc_type) ], int(l2), [int(v)])) print(n, edges, transitions) return TransitionGraph(edges, transitions) pass
def test_nested_while(self): # weights = [AdaptType(1), AdaptType(1), AdaptType("k"), AdaptType("k"), AdaptType("k"), AdaptType("k * k"), AdaptType("k * k")] query = [0, 1, 0, 0, 1, 0, 1] edges = [(0, 2), (1, 4), (1, 6), (2, 2), (2, 3), (3, 5), (5, 5), (6, 4), (6, 6)] weights = [AdaptType("INF")]*len(query) ctl_edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (6, 2), (7, 8), (8, 6)] transitions = [ (0, [DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET)], 1, [0]), (1, [DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET)], 2, [1]), (1, [], 1, []), (1, [DifferenceConstraint("i", None, "1", DifferenceConstraint.DCType.DEC)], 1, [2]), (1, [DifferenceConstraint("j", None, "k", DifferenceConstraint.DCType.RESET)], 1, [3]), (1, [DifferenceConstraint("y", "x", "Q", DifferenceConstraint.DCType.RESET)], 1, [4]), (1, [], 1, []), (1, [], 1, []), (1, [DifferenceConstraint("j", None, "1", DifferenceConstraint.DCType.DEC)], 2, [5]), (1, [DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET)], 2, [6]) ] bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) bound_infer.attach_weights() print("The Reachability Bounds Expected for Vertices in the Simple Nested While Graph are: [1, 1, k, k, k, k^2, k^2] ") print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) adapt_search = AdaptSearchAlgRefined(bound_infer.graph) adapt_search.search_adapt() print("The Adaptivity Expected for Simple Nested While Algorithm is: 2 + k * k ") print("The Adaptivity From This Graph is: ", adapt_search.get_adapt())
def nested_while_multivaldep(self): # weights = [AdaptType(1), AdaptType(1), AdaptType("k"), AdaptType("k"), AdaptType("k"), AdaptType("k * k"), AdaptType("k * k")] query = [0, 1, 1, 0, 1, 0, 0, 1] edges = [(0, 3), (1, 4), (1, 7), (2, 4), (4, 4), (4, 7), (7, 4), (7, 7)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(8, 9), (7, 8), (9, 7), (6, 7), (5, 6), (4, 5), (3, 4), (7, 3), (2, 3), (1, 2), (0, 1), (3, 10)] transitions = [ (7, [ DifferenceConstraint("j", None, " 1 ", DifferenceConstraint.DCType.DEC) ], 8, [6]), (6, [], 7, []), (9, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 7, [7]), (6, [ DifferenceConstraint("j", None, "k", DifferenceConstraint.DCType.RESET) ], 7, [5]), (5, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 6, [4]), (4, [ DifferenceConstraint("i", None, " 1 ", DifferenceConstraint.DCType.DEC) ], 5, [3]), (2, [], 3, []), (6, [], 2, []), (2, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 3, [2]), (1, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET) ], 1, [0]), (2, [], -1, []) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer.attach_weights() print( "The Reachability Bounds Expected for Vertices in the Simple Nested While Graph are: [1, 1, k, k, k, k^2, k^2] " ) print( "The Adaptivity Expected for Simple Nested While Algorithm is: 1 + k + k * k " )
def multiple_round(self): query = [0, 0, 1, 0, 0] edges = [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (2, 3), (3, 2), (3, 3), (4, 4)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(4, 5), (3, 4), (2, 3), (5, 2), (1, 2), (0, 1), (2, 7)] transitions = [ (4, [ DifferenceConstraint("l", None, "INF", DifferenceConstraint.DCType.RESET) ], 5, [3]), (3, [ DifferenceConstraint("a", None, "Q", DifferenceConstraint.DCType.RESET) ], 4, [2]), (2, [], 3, []), (5, [ DifferenceConstraint("i", None, " 1 ", DifferenceConstraint.DCType.DEC) ], 2, [4]), (1, [ DifferenceConstraint("l", None, " 0 ", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("i", None, " k ", DifferenceConstraint.DCType.RESET) ], 1, [0]), (2, [], -1, []) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer.attach_weights() print( "The Reachability Bounds Expected for Vertices in the Multiple Round Graph are: [1, 1, k, k, k] " ) # print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) # adapt_search = AdaptSearchAlgRefined(bound_infer.graph) # adapt_search.search_adapt() print("The Adaptivity Expected for multiple Round Algorithm is: k ")
def test_simple_while(self): weights = [AdaptType(0), AdaptType(0), AdaptType(0), AdaptType(0)] query = [0, 1, 1, 0] edges = [(0, 2), (1, 2), (1, 3)] # adapt_search = self.ALG(Graph(edges, weights, query)) ctl_edges = [(0, 1), (1, 1)] transitions = [(0, [DifferenceConstraint("x", None, "k", DifferenceConstraint.DCType.RESET)], 1, [0]), (1, [DifferenceConstraint("x", None, "1", DifferenceConstraint.DCType.DEC)], 1, [1, 2, 3])] bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) bound_infer.attach_weights() print("The Reachability Bounds Expected for Vertices in Simple while are: [1, k, k,k] ") print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) adapt_search = AdaptSearchAlgRefined(bound_infer.graph) adapt_search.search_adapt() print("The Adaptivity Expected for Simple While Algorithm is: 1 ") print("The Adaptivity From This Graph is: ", adapt_search.get_adapt())
def test_multiple_constriants(self): query = [0, 0, 0, 1, 0, 1] edges = [(0, 2), (1, 2), (1,4), (2,2), (2, 3), (3, 4), (4, 4), (4, 5)] weights = [AdaptType("INF")]*len(query) ctl_edges = [(0, 1), (1, 1), (1, 2)] transitions = [(0, [DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET), DifferenceConstraint("l", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0, 1]), (1, [DifferenceConstraint("i", None, "1", DifferenceConstraint.DCType.DEC), DifferenceConstraint("a", None, "Q", DifferenceConstraint.DCType.RESET), DifferenceConstraint("l", "a", "0", DifferenceConstraint.DCType.INC)], 1, [2, 3, 4]), (1, [DifferenceConstraint("b", "l", "Q", DifferenceConstraint.DCType.RESET)], 2, [5])] bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) bound_infer.attach_weights() print("The Reachability Bounds Expected for Vertices in the Two Round Graph are: [1, 1, k, k, k, 1] ") print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) adapt_search = AdaptSearchAlgRefined(bound_infer.graph) adapt_search.search_adapt() print("The Adaptivity Expected for Two Round Algorithm is: 2 ") print("The Adaptivity From This Graph is: ", adapt_search.get_adapt())
def if_valdep(self): query = [1, 0, 1, 1] edges = [(0, 2), (1, 2), (1, 3)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(0, 1), (1, 2), (2, 3), (2, 4), (3, 5), (4, 5)] transitions = [ (0, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0]), (0, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [1]), (0, [], 1, []), (0, [], 1, []), (0, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [2]), (0, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [3]), ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) print( "The Reachability Bounds Expected for Mutli-path Dependency in If branch Algorithm are: [1,1,1,1] " ) # adapt_search = AdaptSearchAlgRefined(bound_infer.graph) # adapt_search.search_adapt() print( "The Adaptivity Expected for Mutli-path Dependency in If branch Algorithm is: 2 " )
def if_ctldep(self): query = [1, 1, 1, 1] edges = [(0, 1), (1, 2), (1, 3)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(0, 1), (1, 2), (2, 3), (2, 4), (3, 5), (4, 5)] transitions = [ (0, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0]), (0, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [1]), (0, [], 1, []), (0, [], 1, []), (0, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [2]), (0, [ DifferenceConstraint("w", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [3]), ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) # bound_infer.attach_weights() print( "The Reachability Bounds Expected for Vertices in If Branch with Control Dependency Graph are: [1, 1, 1, 1] " ) print( "The Adaptivity Expected for Mutli-path Dependency in If branch Algorithm is: 3 " )
def while_valctldep(self): query = [1, 1, 1, 1] edges = [(0, 2), (0, 3), (1, 2), (2, 3), (3, 2)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(3, 4), (2, 3), (4, 2), (1, 2), (0, 1), (2, 5)] transitions = [ (3, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 4, [2]), (2, [], 3, []), (4, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 2, [3]), (1, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0]), (2, [], -1, []) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) print( "The Reachability Bounds Expected for Vertices in While with Control and Value Dependency Overlapped are: [1, 1, INF, INF] " ) # print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights()) # adapt_search = AdaptSearchAlgRefined(bound_infer.graph) # adapt_search.search_adapt() print( "The Adaptivity Expected for While with Control and Value Dependency Overlapped Algorithm is: INF " )
def while_multivaldep(self): query = [0, 1, 1, 0, 1, 1, 1] edges = [(0, 3), (0, 4), (1, 4), (2, 4), (4, 6), (6, 4), (4, 5), (5, 4)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(6, 7), (5, 6), (4, 5), (3, 4), (7, 3), (2, 3), (1, 2), (0, 1), (3, 8)] transitions = [ (6, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 7, [5]), (5, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 6, [4]), (4, [ DifferenceConstraint("i", None, "1", DifferenceConstraint.DCType.DEC) ], 5, [3]), (3, [], 4, []), (7, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 3, [6]), (2, [ DifferenceConstraint("z", None, "Q", DifferenceConstraint.DCType.RESET) ], 3, [2]), (1, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET) ], 1, [0]), (3, [], -1, []) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) print( "The Reachability Bounds Expected for Vertices in while Multi Variable Dependency: [1, 1, 1, k, k, k, k] " ) print( "The Adaptivity Expected for while with (Multi Variable Dependency) Algorithm is: 1 + 2 * k" )
def while_multipath_ctldep(self): query = [1, 0, 1, 1, 0, 1] edges = [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (2, 2), (2, 5), (3, 3), (3, 5), (4, 4)] weights = [AdaptType("INF")] * len(query) ctl_edges = [(3, 4), (3, 5), (4, 6), (5, 6), (2, 3), (6, 2), (2, 7), (1, 2), (0, 1), (7, 8)] transitions = [ (3, [], 4, []), (3, [], 5, []), (4, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 6, [2]), (5, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], 6, [3]), (2, [], 3, []), (6, [ DifferenceConstraint("x", None, " 1 ", DifferenceConstraint.DCType.DEC) ], 2, [4]), (2, [], 7, []), (1, [ DifferenceConstraint("y", None, " 0 ", DifferenceConstraint.DCType.RESET) ], 2, [1]), (0, [ DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET) ], 1, [0]), (7, [ DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET) ], -1, [5]) ] AdaptEstimate.adapt_estimate(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) print( "The Reachability Bounds Expected for Vertices in while with If Banch inside are: [1, 1, Q, Q, Q, 1] " ) print( "The Adaptivity Expected for while with If Banch (Multi-Path While Loop) Algorithm is: 2 + Q" )
def test_while_multipath_if(self): query = [0, 1, 0, 1, 1, 1] edges = [(0, 4), (1, 2), (1, 3), (2, 3), (3, 2), (3, 3)] weights = [AdaptType("INF")]*len(query) ctl_vertices_num = 4 ctl_edges = [(0, 1), (1, 2), (2, 3), (2, 3), (3, 1)] transitions = [ (0, [DifferenceConstraint("i", None, "k", DifferenceConstraint.DCType.RESET), DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET)], 1, [0, 1]), (1, [DifferenceConstraint("i", None, "1", DifferenceConstraint.DCType.DEC)], 2, [2]), (2, [DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET)], 3, [3]), (2, [DifferenceConstraint("y", None, "Q", DifferenceConstraint.DCType.RESET)], 3, [4]), (3, [DifferenceConstraint("x", None, "Q", DifferenceConstraint.DCType.RESET)], 2, [5]) ] is_scc = [False, True, True, True, True] bound_infer = self.ALG(Graph(edges, weights, query), TransitionGraph(ctl_edges, transitions)) bound_infer.attach_weights() print("The Reachability Bounds Expected for Vertices in the Multiple Path Simple While Graph are: [1, 1, k, k/2, k/2, k] ") print("The Reachability Bounds Calculated for Vertices in This Graph are: ", bound_infer.get_weights())