def generate_assignments(thresh = 2): # create the initial z3 solver solver = z3.Solver() # declare a block block_1 = {'b1_1': 'move', 'b1_2': 'turn_left', 'b1_3': 'move', 'b1_4': 'turn_right', 'b1_5': 'move'} block_1_obj = SMT_Block(block_1, thresh) # declare the values that each of the variables can take X = [ele.var for ele in block_1_obj.block_z3_vars] values = block_1_obj.block_values constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [type_to_str[VariableType(model[ele.var].as_long())] for ele in block_1_obj.block_z3_vars ] assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2): solver = z3.Solver() # declare a block block_1 = { 'b1_1': 'move', 'b1_2': 'turn_left', 'b1_3': 'move', 'b1_4': 'turn_right' } block_1_obj = SMT_Block(block_1, thresh) # declare the values that each of the variables can take X = [ele.var for ele in block_1_obj.block_z3_vars] # declare the values that each of the variables can take values = block_1_obj.block_values # additional empty block added in the end of the code block_2 = {'b2_1': 'phi'} block_2_obj = SMT_Block(block_2, thresh) values.extend(block_2_obj.block_values) # all block objects block_objs = [block_1_obj, block_2_obj] # declare the values that each of the variables can take X.extend([ele.var for ele in block_2_obj.block_z3_vars]) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars] # declare the constraints on the variables constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + block_2_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = ['repeat_until_goal (bool_goal)'] a.extend( [type_to_str[VariableType(model[ele].as_long())] for ele in X]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_2_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2): solver = z3.Solver() # declare the SMT variables for the specific code block_1 = {'b1_1': 'turn_right'} block_1_obj = SMT_Block(block_1, thresh) values = block_1_obj.block_values c1 = z3.Int('c1') # 5 (repeat) values.append(z3.Or(c1 == 4, c1 == 5, c1 == 6), ) block_2 = {'b2_1': 'move'} block_2_obj = SMT_Block(block_2, thresh) values.extend(block_2_obj.block_values) # additional empty block added in the end of the code block_3 = {'b3_1': 'phi'} block_3_obj = SMT_Block(block_3, thresh) values.extend(block_3_obj.block_values) # all block objects block_objs = [block_1_obj, block_2_obj, block_3_obj] X = [ele.var for ele in block_1_obj.block_z3_vars ] # added the variables for block 1 X.append(c1) # added the conditional variable X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars] X.extend(block_3_vars) # added the variables for block 3 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints \ + block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + block_2_obj.block_elimination_constraints \ + block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + block_3_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [ type_to_str[VariableType(model[ele].as_long())] for ele in X[:block_1_obj.size] ] a.append(str(model[c1].as_long())) b = [ type_to_str[VariableType(model[ele].as_long())] for ele in X[block_2_obj.size + 1:] ] a.extend(b) c = [ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ] a.extend(c) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2): solver = z3.Solver() # Block 1 block_1 = {'b1_1': 'move'} block_1_obj = SMT_Block(block_1, thresh) values = block_1_obj.block_values block_1_vars = [ele.var for ele in block_1_obj.block_z3_vars ] # for the conditional constraints c1 = z3.Int('c1') # bool_path_left (if_only) values.append(z3.Or(c1 == 8, c1 == 9)) block_2 = {'b2_1': 'turn_left'} block_2_obj = SMT_Block(block_2, thresh) values.extend(block_2_obj.block_values) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars ] # for the conditional constraints block_3 = {'b3_1': 'phi'} block_3_obj = SMT_Block(block_3, thresh) values.extend(block_3_obj.block_values) block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars ] # for the conditional constraints # all block objects block_objs = [block_1_obj, block_2_obj, block_3_obj] X = [ele.var for ele in block_1_obj.block_z3_vars ] # added the variables for block 1 X.append(c1) # added the conditional variable X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 X.extend([ele.var for ele in block_3_obj.block_z3_vars ]) # added the variables for block 3 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + block_2_obj.block_elimination_constraints + \ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + block_3_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) constraints.extend([ # conditional constraints: if(path_left) z3.Implies(c1 == 8, z3.Or(block_2_vars[0] == 2, block_2_vars[1] == 2, block_2_vars[2] == 2, block_2_vars[3] == 2, block_2_vars[4] == 2, )), z3.Implies(z3.And(c1 == 8, block_2_vars[1] == 2, block_2_vars[0] != 2), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 3 )), z3.Implies(z3.And(c1 == 8, block_2_vars[2] == 2, block_2_vars[0] != 2, block_2_vars[1] != 2), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 3, block_2_vars[1] != 1, block_2_vars[1] != 3)), z3.Implies(z3.And(c1 == 8, block_2_vars[3] == 2, block_2_vars[0] != 2, block_2_vars[1] != 2, block_2_vars[2] != 2), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 3, block_2_vars[1] != 1, \ block_2_vars[1] != 3, block_2_vars[2] != 1, block_2_vars[2] != 3)), z3.Implies(z3.And(c1 == 8, block_2_vars[4] == 2, block_2_vars[0] != 2, block_2_vars[1] != 2, block_2_vars[2] != 2, block_2_vars[3] != 2), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 3, block_2_vars[1] != 1, block_2_vars[1] != 3, block_2_vars[2] != 1, block_2_vars[2] != 3, block_2_vars[3] != 1, block_2_vars[3] != 3)), # conditional constraints: if(path_right) z3.Implies(c1 == 9, z3.Or(block_2_vars[0] == 3, block_2_vars[1] == 3, block_2_vars[2] == 3, block_2_vars[3] == 3, block_2_vars[4] == 3, )), z3.Implies(z3.And(c1 == 9, block_2_vars[1] == 3, block_2_vars[0] != 3, ), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 2)), z3.Implies(z3.And(c1 == 9, block_2_vars[2] == 3, block_2_vars[0] != 3, block_2_vars[1] != 3), z3.And(block_2_vars[0]!= 1, block_2_vars[0] != 2, block_2_vars[1] != 1, block_2_vars[1] != 2)), z3.Implies(z3.And(c1 == 9, block_2_vars[3] == 3, block_2_vars[0] != 3, block_2_vars[1] != 3, block_2_vars[2] != 3), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 2, block_2_vars[1] != 1, block_2_vars[1] != 2, block_2_vars[2] != 1, block_2_vars[2] != 2)), z3.Implies(z3.And(c1 == 9, block_2_vars[4] == 3, block_2_vars[0] != 3, block_2_vars[1] != 3, block_2_vars[2] != 3, block_2_vars[3] != 3 ), z3.And(block_2_vars[0] != 1, block_2_vars[0] != 2, block_2_vars[1] != 1, block_2_vars[1] != 2, block_2_vars[2] != 1, block_2_vars[2] != 2, block_2_vars[3] != 1, block_2_vars[3] != 2)), ]) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = ['repeat_until_goal(bool_goal)'] a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in X[:block_1_obj.size] ]) a.append(type_to_str[ConditionalType(model[c1].as_long())]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in X[block_1_obj.size + 1:] ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2, id='karel'): solver = z3.Solver() # declare the SMT variables for the specific code # Block 1 block_1 = {'b1_1': 'put_marker'} block_1_obj = SMT_Block(block_1, thresh, id=id) values = block_1_obj.block_values block_1_vars = [ele.var for ele in block_1_obj.block_z3_vars ] # for the conditional constraints c1 = z3.Int('c1') # bool_path_ahead (while) values.append(z3.Or(c1 == 7, c1 == 12)) # bool_path_ahead, bool_no_path_ahead block_2 = { 'b2_1': 'move', 'b2_2': 'turn_left', 'b2_3': 'move', 'b2_4': 'turn_right', 'b2_5': 'put_marker' } block_2_obj = SMT_Block(block_2, thresh, id=id) values.extend(block_2_obj.block_values) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars ] # for the conditional constraints block_3 = {'b3_1': 'phi'} block_3_obj = SMT_Block(block_3, thresh, id=id) values.extend(block_3_obj.block_values) block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars ] # for the conditional constraints # all block objects block_objs = [block_1_obj, block_2_obj, block_3_obj] X = [c1] X.extend([ele.var for ele in block_1_obj.block_z3_vars ]) # added the variables for block 1 X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 X.extend([ele.var for ele in block_3_obj.block_z3_vars ]) # added the variables for block 3 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.flip_marker_constraints+ \ block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + \ block_2_obj.flip_marker_constraints + block_2_obj.block_elimination_constraints +\ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + \ block_3_obj.flip_marker_constraints + block_3_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) constraints.extend([ # conditional constraints: while(bool_path_ahead)---while block constraints z3.Implies( c1 == 7, z3.Or( block_2_vars[0] == 1, block_2_vars[1] == 1, block_2_vars[2] == 1, block_2_vars[3] == 1, block_2_vars[4] == 1, block_2_vars[5] == 1, block_2_vars[6] == 1, block_2_vars[7] == 1, block_2_vars[8] == 1, block_2_vars[9] == 1, block_2_vars[10] == 1, block_2_vars[11] == 1, block_2_vars[12] == 1, )), z3.Implies(z3.And(c1 == 7, block_2_vars[1] == 1, block_2_vars[0] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[2] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[3] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[4] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[5] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[6] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[7] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[8] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3, block_2_vars[7] != 2, block_2_vars[7] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[9] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3, block_2_vars[7] != 2, block_2_vars[7] != 3, block_2_vars[8] != 2, block_2_vars[8] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[10] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3, block_2_vars[7] != 2, block_2_vars[7] != 3, block_2_vars[8] != 2, block_2_vars[8] != 3, block_2_vars[9] != 2, block_2_vars[9] != 3)), # # ################################################ THRESH = 2 z3.Implies( z3.And(c1 == 7, block_2_vars[11] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1, block_2_vars[10] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3, block_2_vars[7] != 2, block_2_vars[7] != 3, block_2_vars[8] != 2, block_2_vars[8] != 3, block_2_vars[9] != 2, block_2_vars[9] != 3, block_2_vars[10] != 2, block_2_vars[10] != 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[12] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1, block_2_vars[10] != 1, block_2_vars[11] != 1), z3.And(block_2_vars[0] != 2, block_2_vars[0] != 3, block_2_vars[1] != 2, block_2_vars[1] != 3, block_2_vars[2] != 2, block_2_vars[2] != 3, block_2_vars[3] != 2, block_2_vars[3] != 3, block_2_vars[4] != 2, block_2_vars[4] != 3, block_2_vars[5] != 2, block_2_vars[5] != 3, block_2_vars[6] != 2, block_2_vars[6] != 3, block_2_vars[7] != 2, block_2_vars[7] != 3, block_2_vars[8] != 2, block_2_vars[8] != 3, block_2_vars[9] != 2, block_2_vars[9] != 3, block_2_vars[10] != 2, block_2_vars[10] != 3, block_2_vars[11] != 2, block_2_vars[11] != 3)), # # conditional constraints: while(bool_no_path_ahead)---while block constraints z3.Implies(c1 == 12, block_2_vars[0] != 1), z3.Implies( z3.And(c1 == 12, block_2_vars[1] == 1, block_2_vars[0] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[2] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[3] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[4] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[5] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[6] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[7] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[8] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3, block_2_vars[7] == 2, block_2_vars[7] == 3)), z3.Implies( z3.And(c1 == 12, block_2_vars[9] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3, block_2_vars[7] == 2, block_2_vars[7] == 3, block_2_vars[8] == 2, block_2_vars[8] == 3)), z3.Implies( z3.And( c1 == 12, block_2_vars[10] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1, ), z3.Or( block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3, block_2_vars[7] == 2, block_2_vars[7] == 3, block_2_vars[8] == 2, block_2_vars[8] == 3, block_2_vars[9] == 2, block_2_vars[9] == 3, )), z3.Implies( z3.And(c1 == 12, block_2_vars[11] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1, block_2_vars[10] != 1), z3.Or( block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3, block_2_vars[7] == 2, block_2_vars[7] == 3, block_2_vars[8] == 2, block_2_vars[8] == 3, block_2_vars[9] == 2, block_2_vars[9] == 3, block_2_vars[10] == 2, block_2_vars[10] == 3, )), z3.Implies( z3.And(c1 == 12, block_2_vars[12] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1, block_2_vars[4] != 1, block_2_vars[5] != 1, block_2_vars[6] != 1, block_2_vars[7] != 1, block_2_vars[8] != 1, block_2_vars[9] != 1, block_2_vars[10] != 1, block_2_vars[11] != 1), z3.Or( block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3, block_2_vars[4] == 2, block_2_vars[4] == 3, block_2_vars[5] == 2, block_2_vars[5] == 3, block_2_vars[6] == 2, block_2_vars[6] == 3, block_2_vars[7] == 2, block_2_vars[7] == 3, block_2_vars[8] == 2, block_2_vars[8] == 3, block_2_vars[9] == 2, block_2_vars[9] == 3, block_2_vars[10] == 2, block_2_vars[10] == 3, block_2_vars[11] == 2, block_2_vars[11] == 3, )), ]) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [ type_to_str[VariableType(model[ele].as_long())] for ele in block_1_vars ] a.append(type_to_str[ConditionalType(model[c1].as_long())]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_2_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh = 2, id = 'karel'): # create the initial z3 solver solver = z3.Solver() # declare a block block_1 = {'b1_1': 'put_marker', 'b1_2': 'move', 'b1_3': 'turn_left'} block_1_obj = SMT_Block(block_1, thresh, id =id ) values = block_1_obj.block_values c1 = z3.Int('c1') # 4 (repeat) values.append( z3.Or(c1 == 3, c1 == 4, c1 == 5), ) # declare a block block_2 = {'b2_1': 'phi'} block_2_obj = SMT_Block(block_2, thresh, id=id) values.extend(block_2_obj.block_values) # declare a block block_3 = {'b3_1': 'phi'} block_3_obj = SMT_Block(block_3, thresh, id=id) values.extend(block_3_obj.block_values) block_objs = [block_1_obj, block_2_obj, block_3_obj] # declare the values that each of the variables can take X = [ele.var for ele in block_1_obj.block_z3_vars] X.append(c1) X.extend([ele.var for ele in block_2_obj.block_z3_vars]) X.extend([ele.var for ele in block_3_obj.block_z3_vars]) constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + \ block_1_obj.flip_marker_constraints + block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + \ block_2_obj.flip_marker_constraints + block_2_obj.block_elimination_constraints + \ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + \ block_3_obj.flip_marker_constraints + block_3_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [str(model[c1].as_long())] a.extend([type_to_str[VariableType(model[ele.var].as_long())] for ele in block_1_obj.block_z3_vars ]) a.extend([type_to_str[VariableType(model[ele.var].as_long())] for ele in block_2_obj.block_z3_vars ]) a.extend([type_to_str[VariableType(model[ele.var].as_long())] for ele in block_3_obj.block_z3_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2, id='karel'): solver = z3.Solver() # declare the SMT variables for the specific code # Block 1 c0 = z3.Int('c0') # repeat (8) c1 = z3.Int('c1') # bool_no_marker (if_else) block_1 = {'b1_1': 'put_marker'} block_1_obj = SMT_Block(block_1, thresh, id=id) values = block_1_obj.block_values block_1_vars = [ele.var for ele in block_1_obj.block_z3_vars ] # for the conditional constraints block_2 = {'b2_1': 'pick_marker'} block_2_obj = SMT_Block(block_2, thresh, id=id) values.extend(block_2_obj.block_values) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars ] # for the conditional constraints values.append(z3.Or(c0 == 7, c0 == 8, c0 == 9)) values.append(z3.Or(c1 == 10, c1 == 11)) # bool_no_marker, bool_marker block_3 = {'b3_1': 'move'} block_3_obj = SMT_Block(block_3, thresh, id=id) values.extend(block_3_obj.block_values) block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars ] # for the conditional constraints block_4 = {'b4_1': 'phi'} block_4_obj = SMT_Block(block_4, thresh, id=id) values.extend(block_4_obj.block_values) block_4_vars = [ele.var for ele in block_4_obj.block_z3_vars ] # for the conditional constraints block_5 = {'b5_1': 'phi'} block_5_obj = SMT_Block(block_5, thresh, id=id) values.extend(block_5_obj.block_values) block_5_vars = [ele.var for ele in block_5_obj.block_z3_vars ] # for the conditional constraints # all block objects block_objs = [ block_1_obj, block_2_obj, block_3_obj, block_4_obj, block_5_obj ] X = [c0, c1] X.extend([ele.var for ele in block_1_obj.block_z3_vars ]) # added the variables for block 1 X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 X.extend([ele.var for ele in block_3_obj.block_z3_vars ]) # added the variables for block 3 X.extend([ele.var for ele in block_4_obj.block_z3_vars ]) # added the variables for block 4 X.extend([ele.var for ele in block_5_obj.block_z3_vars ]) # added the variables for block 5 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.flip_marker_constraints+ \ block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + \ block_2_obj.flip_marker_constraints+block_2_obj.block_elimination_constraints + \ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + \ block_3_obj.flip_marker_constraints+block_3_obj.block_elimination_constraints + \ block_4_obj.block_append_constraints + block_4_obj.flip_turns_constraints + \ block_4_obj.flip_marker_constraints + block_4_obj.block_elimination_constraints + \ block_5_obj.block_append_constraints + block_5_obj.flip_turns_constraints + \ block_5_obj.flip_marker_constraints + block_5_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) constraints.extend([ # conditional constraints: if_else(bool_no_marker)---if block constraints z3.Implies(c1 == 11, block_1_vars[0] != 4), z3.Implies( z3.And(c1 == 11, block_1_vars[1] == 4, block_1_vars[0] != 4), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 5)), z3.Implies( z3.And(c1 == 11, block_1_vars[2] == 4, block_1_vars[0] != 4, block_1_vars[1] != 4), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 5, block_1_vars[1] == 1, block_1_vars[1] == 5)), z3.Implies( z3.And(c1 == 11, block_1_vars[3] == 4, block_1_vars[0] != 4, block_1_vars[1] != 4, block_1_vars[2] != 4), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 5, block_1_vars[1] == 1, block_1_vars[1] == 5, block_1_vars[2] == 1, block_1_vars[2] == 5)), z3.Implies( z3.And(c1 == 11, block_1_vars[4] == 4, block_1_vars[0] != 4, block_1_vars[1] != 4, block_1_vars[2] != 4, block_1_vars[3] != 4), z3.And(block_1_vars[0] == 1, block_1_vars[0] == 5, block_1_vars[1] == 1, block_1_vars[1] == 5, block_1_vars[2] == 1, block_1_vars[2] == 5, block_1_vars[3] == 1, block_1_vars[3] == 5)), # else block constraints z3.Implies(c1 == 11, block_2_vars[0] != 5), z3.Implies( z3.And(c1 == 11, block_2_vars[1] == 5, block_2_vars[0] != 5), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 4)), z3.Implies( z3.And(c1 == 11, block_2_vars[2] == 5, block_2_vars[0] != 5, block_2_vars[1] != 5), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 4, block_2_vars[1] == 1, block_2_vars[1] == 4)), z3.Implies( z3.And(c1 == 11, block_2_vars[3] == 5, block_2_vars[0] != 5, block_2_vars[1] != 5, block_2_vars[2] != 5), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 4, block_2_vars[1] == 1, block_2_vars[1] == 4, block_2_vars[2] == 1, block_2_vars[2] == 4)), z3.Implies( z3.And(c1 == 11, block_2_vars[4] == 5, block_2_vars[0] != 5, block_2_vars[1] != 5, block_2_vars[2] != 5, block_2_vars[3] != 5), z3.And(block_2_vars[0] == 1, block_2_vars[0] == 4, block_2_vars[1] == 1, block_2_vars[1] == 4, block_2_vars[2] == 1, block_2_vars[2] == 4, block_2_vars[3] == 1, block_2_vars[3] == 4)), # conditional constraints: if_else(bool_marker)---if block constraints z3.Implies(c1 == 10, block_1_vars[0] != 5), z3.Implies( z3.And(c1 == 10, block_1_vars[1] == 5, block_1_vars[0] != 5), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 4)), z3.Implies( z3.And(c1 == 10, block_1_vars[2] == 5, block_1_vars[0] != 5, block_1_vars[1] != 5), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 4, block_1_vars[1] == 1, block_1_vars[1] == 4)), z3.Implies( z3.And(c1 == 10, block_1_vars[3] == 5, block_1_vars[0] != 5, block_1_vars[1] != 5, block_1_vars[2] != 5), z3.Or(block_1_vars[0] == 1, block_1_vars[0] == 4, block_1_vars[1] == 1, block_1_vars[1] == 4, block_1_vars[2] == 1, block_1_vars[2] == 4)), z3.Implies( z3.And(c1 == 10, block_1_vars[4] == 5, block_1_vars[0] != 5, block_1_vars[1] != 5, block_1_vars[2] != 5, block_1_vars[3] != 5), z3.And(block_1_vars[0] == 1, block_1_vars[0] == 4, block_1_vars[1] == 1, block_1_vars[1] == 4, block_1_vars[2] == 1, block_1_vars[2] == 4, block_1_vars[3] == 1, block_1_vars[3] == 4)), # else block constraints z3.Implies(c1 == 10, block_2_vars[0] != 4), z3.Implies( z3.And(c1 == 10, block_2_vars[1] == 4, block_2_vars[0] != 4), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 5)), z3.Implies( z3.And(c1 == 10, block_2_vars[2] == 4, block_2_vars[0] != 4, block_2_vars[1] != 4), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 5, block_2_vars[1] == 1, block_2_vars[1] == 5)), z3.Implies( z3.And(c1 == 10, block_2_vars[3] == 4, block_2_vars[0] != 4, block_2_vars[1] != 4, block_2_vars[2] != 4), z3.Or(block_2_vars[0] == 1, block_2_vars[0] == 5, block_2_vars[1] == 1, block_2_vars[1] == 5, block_2_vars[2] == 1, block_2_vars[2] == 5)), z3.Implies( z3.And(c1 == 10, block_2_vars[4] == 4, block_2_vars[0] != 4, block_2_vars[1] != 4, block_2_vars[2] != 4, block_2_vars[3] != 4), z3.And(block_2_vars[0] == 1, block_2_vars[0] == 5, block_2_vars[1] == 1, block_2_vars[1] == 5, block_2_vars[2] == 1, block_2_vars[2] == 5, block_2_vars[3] == 1, block_2_vars[3] == 5)), ]) unequal_blocks_con = block_unequal_constraint(block_1_obj, block_2_obj) constraints.extend(unequal_blocks_con) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [ str(model[c0].as_long()), type_to_str[ConditionalType(model[c1].as_long())] ] a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_1_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_2_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_4_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_5_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2): solver = z3.Solver() # declare the SMT variables for the specific code # Block 1 block_1 = {'b1_1': 'move'} block_1_obj = SMT_Block(block_1, thresh) values = block_1_obj.block_values block_1_vars = [ele.var for ele in block_1_obj.block_z3_vars ] # for the conditional constraints c1 = z3.Int('c1') # bool_path_ahead (if_else) block_2 = {'b2_1': 'turn_left'} block_2_obj = SMT_Block(block_2, thresh) values.extend(block_2_obj.block_values) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars ] # for the conditional constraints values.append(c1 == 7) # same conditional value block_3 = {'b3_1': 'phi'} block_3_obj = SMT_Block(block_3, thresh) values.extend(block_3_obj.block_values) block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars ] # for the conditional constraints # all block objects block_objs = [block_1_obj, block_2_obj, block_3_obj] X = [c1] X.extend([ele.var for ele in block_1_obj.block_z3_vars ]) # added the variables for block 1 X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 X.extend([ele.var for ele in block_3_obj.block_z3_vars ]) # added the variables for block 2 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + block_2_obj.block_elimination_constraints + \ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + block_3_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) constraints.extend([ # conditional constraints: if_else(bool_path_ahead)---if block constraints z3.Implies( c1 == 7, z3.Or( block_1_vars[0] == 1, block_1_vars[1] == 1, block_1_vars[2] == 1, block_1_vars[3] == 1, block_1_vars[4] == 1, )), z3.Implies(z3.And(c1 == 7, block_1_vars[1] == 1, block_1_vars[0] != 1), z3.And(block_1_vars[0] != 2, block_1_vars[0] != 3)), z3.Implies( z3.And(c1 == 7, block_1_vars[2] == 1, block_1_vars[0] != 1, block_1_vars[1] != 1), z3.And(block_1_vars[0] != 2, block_1_vars[0] != 3, block_1_vars[1] != 2, block_1_vars[1] != 3)), z3.Implies( z3.And(c1 == 7, block_1_vars[3] == 1, block_1_vars[0] != 1, block_1_vars[1] != 1, block_1_vars[2] != 1), z3.And(block_1_vars[0] != 2, block_1_vars[0] != 3, block_1_vars[1] != 2, block_1_vars[1] != 3, block_1_vars[2] != 2, block_1_vars[2] != 3)), z3.Implies( z3.And(c1 == 7, block_1_vars[4] == 1, block_1_vars[0] != 1, block_1_vars[1] != 1, block_1_vars[2] != 1, block_1_vars[3] != 1), z3.And(block_1_vars[0] != 2, block_1_vars[0] != 3, block_1_vars[1] != 2, block_1_vars[1] != 3, block_1_vars[2] != 2, block_1_vars[2] != 3, block_1_vars[3] != 2, block_1_vars[3] != 3)), # else block constraints z3.Implies(c1 == 7, block_2_vars[0] != 1), z3.Implies(z3.And(c1 == 7, block_2_vars[1] == 1, block_2_vars[0] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[2] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[3] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3)), z3.Implies( z3.And(c1 == 7, block_2_vars[4] == 1, block_2_vars[0] != 1, block_2_vars[1] != 1, block_2_vars[2] != 1, block_2_vars[3] != 1), z3.Or(block_2_vars[0] == 2, block_2_vars[0] == 3, block_2_vars[1] == 2, block_2_vars[1] == 3, block_2_vars[2] == 2, block_2_vars[2] == 3, block_2_vars[3] == 2, block_2_vars[3] == 3)), ]) unequal_blocks_con = block_unequal_constraint(block_1_obj, block_2_obj) constraints.extend(unequal_blocks_con) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [ 'repeat_until_goal(bool_goal)', type_to_str[ConditionalType(model[c1].as_long())] ] a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in X[1:block_1_obj.size + 1] ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in X[block_1_obj.size + 1:block_2_obj.size + block_1_obj.size + 1] ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments
def generate_assignments(thresh=2): solver = z3.Solver() # declare the SMT variables for the specific code block_1 = {'b1_1': 'move'} block_1_obj = SMT_Block(block_1, thresh) values = block_1_obj.block_values block_1_vars = [ele.var for ele in block_1_obj.block_z3_vars ] # for the conditional constraints c1 = z3.Int('c1') # 4 (repeat) values.append(z3.Or(c1 == 3, c1 == 4, c1 == 5), ) block_2 = {'b2_1': 'turn_left'} block_2_obj = SMT_Block(block_2, thresh) values.extend(block_2_obj.block_values) block_2_vars = [ele.var for ele in block_2_obj.block_z3_vars ] # for the conditional constraints c2 = z3.Int('c2') # 5 (repeat) values.append(z3.Or(c2 == 4, c2 == 5, c2 == 6), ) block_3 = {'b3_1': 'move'} block_3_obj = SMT_Block(block_3, thresh) values.extend(block_3_obj.block_values) block_3_vars = [ele.var for ele in block_3_obj.block_z3_vars ] # for the conditional constraints # add another block in the beginning of the code block_4 = {'b4_1': 'phi'} block_4_obj = SMT_Block(block_4, thresh) values.extend(block_4_obj.block_values) block_4_vars = [ele.var for ele in block_4_obj.block_z3_vars] # add another block in the end of the code block_5 = {'b5_1': 'phi'} block_5_obj = SMT_Block(block_5, thresh) values.extend(block_5_obj.block_values) block_5_vars = [ele.var for ele in block_5_obj.block_z3_vars] # all block objects block_objs = [ block_1_obj, block_2_obj, block_3_obj, block_4_obj, block_5_obj ] X = [ele.var for ele in block_1_obj.block_z3_vars ] # added the variables for block 1 X.append(c1) # added the conditional variable X.extend([ele.var for ele in block_2_obj.block_z3_vars ]) # added the variables for block 2 X.append(c2) # added the conditional variable X.extend([ele.var for ele in block_3_obj.block_z3_vars ]) # added the variables for block 3 X.extend([ele.var for ele in block_4_obj.block_z3_vars ]) # added the variables for block 4 X.extend([ele.var for ele in block_5_obj.block_z3_vars ]) # added the variables for block 5 constraints = block_1_obj.block_append_constraints + block_1_obj.flip_turns_constraints + block_1_obj.block_elimination_constraints + \ block_2_obj.block_append_constraints + block_2_obj.flip_turns_constraints + block_2_obj.block_elimination_constraints + \ block_3_obj.block_append_constraints + block_3_obj.flip_turns_constraints + block_3_obj.block_elimination_constraints + \ block_4_obj.block_append_constraints + block_4_obj.flip_turns_constraints + block_4_obj.block_elimination_constraints + \ block_5_obj.block_append_constraints + block_5_obj.flip_turns_constraints + block_5_obj.block_elimination_constraints single_block_change_cons = single_block_change(block_objs) constraints.extend(single_block_change_cons) # add the values and the constraints solver.add(values + constraints) # generate all the assignments models = gen_all(solver, X) assignments = [] for model in models: a = [str(model[c1].as_long())] a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_1_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_2_vars ]) a.append(str(model[c2].as_long())) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_3_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_4_vars ]) a.extend([ type_to_str[VariableType(model[ele].as_long())] for ele in block_5_vars ]) assignments.append(a) #print(a) #print('Found #{} SAT values'.format(len(models))) return assignments