def calculate_and_solve(framework): ### calculate each position array### v_poss = f.list_verticle_framework(framework) h_poss = f.list_horizontal_framework(framework) b_poss = f.list_box_framework(framework) framework_with_positional_element = f.generate_positional_array(framework) ### solve #### status, remain_possible = f.solve(framework_with_positional_element, framework, 1, v_poss, h_poss, b_poss) return [framework, status, remain_possible]
def main(): with open('input.txt') as file_object: contents = file_object.read().splitlines() start = time.time() result = functions.solve(contents) print("Part 1 solution (area of overlapping claims): " + str(result) + " found in " + str(time.time() - start)) start = time.time() result = functions.solve_part2(contents) print("Part 2 solution (single non-overlapping claim): " + str(result) + " found in " + str(time.time() - start))
if __name__ == '__main__': # starting parallel workers multiprocessing.set_start_method('spawn', True) workers = Pool(functions.num_workers) # training phase (Tensorflow graph activation, performing CMA-ES optimisation) with functions.sess.as_default(): functions.sess.run(tf.compat.v1.global_variables_initializer()) saver = tf.compat.v1.train.Saver() cma = CMAES(functions.NPARAMS, sigma_init=functions.sigma, weight_decay=0, popsize=functions.NPOPULATION) cma_history = functions.solve(cma, workers) # loading learned gait after training with open(functions.save_dir, 'rb') as f: bestparams = pickle.load(f) with open(functions.max_fit_dir, 'rb') as f: history = pickle.load(f) # testing learned gait functions.env[0].reset() time.sleep(2) fitness = functions.fitness_func(bestparams, True) # showing reward/time graph plt.plot(history) plt.show()
import functions as f from pathlib import Path import cv2 img_path = Path.cwd().joinpath('data').joinpath('diplom_data').joinpath( 'raw').joinpath('008.jpg') img = cv2.imread(str(img_path)) f.solve(img)
sudoku = [ [0, 9, 0, 3, 6, 0, 1, 0, 4], [0, 7, 5, 0, 0, 2, 3, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 7], [0, 0, 3, 4, 8, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 2, 5, 4, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 7, 8, 0, 0, 6, 3, 0], [6, 0, 4, 0, 3, 1, 0, 2, 0], ] def print_sudoku(grid): for i in range(len(grid)): if i % 3 == 0 and i != 0: print("- - - - - - - - - - - - - ") for j in range(len(grid[0])): if j % 3 == 0 and j != 0: print(" | ", end=" ") if j == 8: print(grid[i][j]) else: print(grid[i][j], end=" ") print_sudoku(sudoku) solve(sudoku) print("________________________") print_sudoku(sudoku)
libraries_num = content[0][1] days = content[0][2] scores_of_books = content[1] libraries = [] # print (scores_of_books) for x in range(1, len(content) / 2): # books = {} # for b in content[x * 2 + 1]: # books[b] = book(b,scores_of_books[b]) books = [] for b in content[x * 2 + 1]: books.append(book(b, scores_of_books[b])) books.sort(key=lambda x: x.score, reverse=True) libraries.append( lib(x - 1, content[x * 2][0], content[x * 2][1], content[x * 2][2], books)) print("done reading file") ret = solve(days, libraries) ret = [' '.join(map(str, x)) for x in ret] with open("output/" + filename + ".out", "w") as f: for item in ret: print >> f, item print("all done.") # print (ret)