print("NCC") # print(p) print(word) s.add(p) if idx == MAX_DEPTH: # print(word) return words(idx + 1, word + 'a') words(idx + 1, word + 'b') words(0, "") # print("asserted constraints...") # for c in s.assertions(): # print(c) print() print() if s.check() == sat: for item in utils.sorted_model(s): print(item) utils.z3_to_smt2(s, "ass1-q1") else: print("Failed to solve")
And( Or( CHIP_POS[i][0] <= (CHIP_POS[j][0] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][1] - COMPONENT_DIM[i][0])/2.), #left w/o rotation CHIP_POS[j][0] <= (CHIP_POS[i][0] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][1] - COMPONENT_DIM[i][0])/2.), #right CHIP_POS[i][1] <= (CHIP_POS[j][1] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][0] - COMPONENT_DIM[i][1])/2.), #below CHIP_POS[j][1] <= (CHIP_POS[i][1] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][0] - COMPONENT_DIM[i][1])/2.), #above ), And(CHIP_POS[i][2] == 0, CHIP_POS[j][2] == 1) ), And( Or( CHIP_POS[i][0] <= (CHIP_POS[j][0] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][1] - COMPONENT_DIM[i][1])/2.), #left w/o rotation CHIP_POS[j][0] <= (CHIP_POS[i][0] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][1] - COMPONENT_DIM[i][1])/2.), #right CHIP_POS[i][1] <= (CHIP_POS[j][1] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][0] - COMPONENT_DIM[i][0])/2.), #below CHIP_POS[j][1] <= (CHIP_POS[i][1] - POWER_COMPONENTS_DISTANCE - abs(COMPONENT_DIM[j][0] - COMPONENT_DIM[i][0])/2.), #above ), And(CHIP_POS[i][2] == 1, CHIP_POS[j][2] == 1) ) ) ) if s.check() == sat: print(utils.sorted_model(s)) utils.draw_chip_design(CHIP_WIDTH, CHIP_HEIGHT, COMPONENT_DIM, POWER_COMPONENTS, s) utils.z3_to_smt2(s, "ass1-q2") else: print("Failed to solve")
s.add( And(SCHEDULE[11] >= SCHEDULE[8] + JOB_TIMES[8], SCHEDULE[11] >= SCHEDULE[10] + JOB_TIMES[10])) # Jobs 5,7 and 10 mutually exclusive for i in [4, 6, 9]: for j in [4, 6, 9]: if not (i == j): s.add( Or(And(SCHEDULE[i] <= SCHEDULE[j] - JOB_TIMES[i]), And(SCHEDULE[i] >= SCHEDULE[j] + JOB_TIMES[j]))) # Total time restriction for i in range(JOBS): s.add(SCHEDULE[i] <= TIME - JOB_TIMES[i]) # Additional condition for q3-b # Job 6 and 12 need a resource of limited availability # Job 6 can run only when job 12 is running s.add( And(SCHEDULE[5] >= SCHEDULE[11], SCHEDULE[5] <= SCHEDULE[11] + JOB_TIMES[11] - JOB_TIMES[5])) if s.check() == sat: utils.sorted_model(s) utils.z3_to_smt2(s, "ass1-q3-b") utils.draw_schedule(JOBS, TIME, JOB_TIMES, s) else: print("Failed to solve")
truckItem[i][TYPEOF['Prittle']] == 0)) return s while (True): s = RepeatingFuntion(PRITTLES_GLOB) if (s.check() == sat): print("Satisfiable with " + str(PRITTLES_GLOB) + " prittle pallets") PRITTLES_GLOB = PRITTLES_GLOB + 1 prev_solver = s else: print("Unsatisfiable with " + str(PRITTLES_GLOB) + " prittle pallets") print("Best model found:\n") print(utils.sorted_model(prev_solver)) utils.z3_to_smt2(prev_solver, "ass1-q1-b") break # if s.check() == sat: # print(s.model()) # helper_obj = utils.helpers() # helper_obj.z3_to_smt2(s.to_smt2(), "ass1-q1") # else: # print("Failed to solve") # print(s.to_smt2())
var_constraints.append( a[chosen_var][step] == a[chosen_var - 1][step - 1] + a[chosen_var + 1][step - 1]) else: var_constraints.append(a[i][step] == a[i][step - 1]) step_constraints.append(And(var_constraints)) s.add(Or(step_constraints)) # define the stop criteria a3 = a7 # a s.add(a[3 - 1][STEPS - 1] == a[7 - 1][STEPS - 1]) # b s.add(a[2][STEPS - 1] == a[4][STEPS - 1]) if s.check() == sat: step = 0 for var, var_str in utils.sorted_model(s): print(var, var_str) step = step + 1 if step % NUM_VARS == 0: print() utils.z3_to_smt2(s, "ass1-q4-a") else: print("Failed to solve")