Created
March 22, 2017 17:25
-
-
Save 5nizza/da35bb1b9769364c8e24c8b56e4b008a to your computer and use it in GitHub Desktop.
Generate SMT define-fun from graph edges list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the main function | |
def get_edges_as_smt(function_name:str, a1:str, a2:str, node_type:str, graph): | |
or_components = [] | |
for s, d_list in graph.items(): | |
for d in d_list: | |
or_components.append('(and (= {a1} {s}) (= {a2} {d}))'.format(a1=a1,a2=a2,s=node_type+str(s),d=node_type+str(d))) | |
or_smt = '(or %s)' % (' '.join(or_components)) | |
return '(define-fun {function_name} (({a1} {node_type}) ({a2} {node_type})) Bool {body})'.format( | |
a1=a1, a2=a2, node_type=node_type, function_name=function_name, body=or_smt) | |
graph = { 0: [1, 4], | |
1: [0, 2], | |
2: [1, 3], | |
3: [4, 2], | |
4: [0, 3] } | |
# for convenience printing the dot graph | |
print("digraph module {") | |
for src, dst_list in graph.items(): | |
for dst in dst_list: | |
print("{src} -> {dst}".format_map(locals())) | |
print("}") | |
get_edges_as_smt('is_edge', 's', 'd', 'V', graph) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment