def solution(map_num): inp = read_inputfile(path.format(map_num=map_num)) initial_state = get_initial_state(inp) res = backtrack( initial_state, initial_state[1], inp, smart.order_domain_values, dum.assignment_complete, dum.is_consistant, lambda *args: 1, smart.get_var ) point_list = coord_dict_to_point(res) return jsonify(point_list)
def map(map_num): ''' suported maps: - 10101 - 10102 - 1212 - 1214 - 1414 - 55 - 77 - 88 - 991 ''' inp = read_inputfile(path.format(map_num=map_num)) height = len(inp) width = len(inp[0]) return jsonify(height=height, width=width)
def solution_animated(request): # make sure no other session is running if dump_sesssion['solver_state'] == solver_state.locked: dump_sesssion['in_demand'] = True while dump_sesssion['solver_state'] == solver_state.locked: sleep(0.3) dump_sesssion['in_demand'] = False # hold current session dump_sesssion['solver_state'] = solver_state.locked inp = read_inputfile(path.format(map_num=request["map_id"])) initial_state = get_initial_state(inp) if request["method"] == 'smart': res = backtrack( initial_state, initial_state[1], inp, smart.order_domain_values, dum.assignment_complete, dum.is_consistant, lambda assignments, variables_domain, var, value: draw_with_delay( assignments, variables_domain, var, value, .1), smart.get_var ) else: res = backtrack( initial_state, initial_state[1], inp, dum.order_domain_values, dum.assignment_complete, dum.is_consistant, lambda assignments, variables_domain, var, value: draw_with_delay( assignments, variables_domain, var, value, .1), dum.get_var ) socketio.emit('done', 'done') # free session dump_sesssion['solver_state'] = solver_state.free
import time seed(0) paths = [ "../input/input55.txt", "../input/input77.txt", "../input/input88.txt", "../input/input991.txt", "../input/input10101.txt", "../input/input10102.txt", "../input/input1212.txt", "../input/input1214.txt", "../input/input1414.txt", ] for path in paths: inp = read_inputfile(path) # print(inp) initial_state = get_initial_state(inp) # print(initial_state[1]) # def debug_print(assignments,domain,var,val): # print(f'{var} ,{val}') # print(f'domain {domain[var]}') # formatter(assignments,len(inp[0]), len(inp),init="_") c=[0] def increase(c,*args): c[0]+=1 start = time.time() res = backtrack(