def generate_html(dir, overwrite=False, star=False, short=False, quiet=False, disp="s"): filenames = os.listdir(dir) # See the docstring for add_result for the structure of the results dict. results = {} flat_results = [] files_found = 0 for filename in filenames: if "experiment" in filename and filename[-5:] == ".json": files_found += 1 result = parse_output.parse(dir + '/' + filename, external=False) flat_result = flatten_result(result) flat_results.append(flat_result) results = add_result(results, result) else: continue print "processed", files_found, "files" if not quiet: overwrite = 'w' if overwrite else 'a' with open('data/results.html', overwrite) as f: f.write('<script src="sorttable.js"></script>\n') f.write('<head><style type="text/css"> ' + css() + '</style></head>\n') for result in results: write_table(f, results[result], result, star, short, disp) f.write('<br></br>\n') assert(f.closed) return results, flat_results
def generate_html(dir, outFile, overwrite=False): """Reads every experiment json file in dir (*experiment*.json), and writes a summary in html to outFile (default data/test.html). Overwrites the file if overwrite is true, and appends to it otherwise. """ filenames = os.listdir(dir) results = [] files_found = 0 for filename in filenames: if "experiment" in filename and filename[-5:] == ".json": files_found += 1 result = parse_output.parse(dir + '/' + filename, external=False) results = add_result(results, result) else: continue print "processed", files_found, "files" overwrite = 'w' if overwrite else 'a' with open(outFile, overwrite) as f: f.write('<script src="sorttable.js"></script>\n') f.write('<head> <style type="text/css"> ' + css() + ' </style></head>\n') for result in results: write_table(f, result) f.write('<br></br>\n') assert(f.closed) return results
def main(args): serial_time = parse(os.path.join(args.dir, 'serial.txt')) print(serial_time) num_threads = sorted(args.num_threads) parallel_times = [serial_time] serial_times = [serial_time] for num_thread in num_threads: parallel_times.append( parse(os.path.join(args.dir, f'threads_{num_thread}.txt'))) serial_times.append( parse(os.path.join(args.dir, f'serial_{num_thread}.txt'))) parallel_times = np.array(parallel_times) serial_times = np.array(serial_times) print("Parallel_times: ", parallel_times) print("Serial times: ", serial_times) speedup = serial_times / parallel_times print("Speedup: ", speedup) # Fitting a linear regression model X = np.arange(1, 1 + len(speedup)).reshape(-1, 1) reg = LinearRegression().fit(X, speedup) print(reg.coef_) print(reg.intercept_) print(num_threads) plt.plot([1] + num_threads, speedup, '-*', label='Scaled Speedup') # plot best fitted line plt.plot(X.flatten(), reg.predict(X).flatten(), '--', label='Best Fitted Line: {:.2f}p+{:.2f}'.format( reg.coef_[0], reg.intercept_)) plt.xticks([1] + num_threads) plt.ylabel('Scaled Speedup') plt.xlabel('Number of threads, p') plt.grid() plt.legend() if args.show_plot: plt.show() else: plt.savefig(f'{args.dir}.jpg')
def main(args): serial_time = parse(os.path.join(args.dir, 'serial.txt')) print(serial_time) num_threads = sorted(args.num_threads) times = [serial_time] for num_thread in num_threads: times.append(parse(os.path.join(args.dir, f'threads_{num_thread}.txt'))) times = np.array(times) speedup = serial_time / times print('Speedup: ', speedup) plt.plot([1] + num_threads, speedup, '-*', label='Speedup') plt.xticks([1] + num_threads) plt.ylabel('Speedup') plt.xlabel('Number of threads') plt.grid() plt.legend() if args.show_plot: plt.show() else: plt.savefig('strong_scaling.jpg')
def main(): # Selecting level filename = "Json/mission" + sys.argv[1] + "-level" + sys.argv[2] + ".json" # Initializing variables start_time = time.time() tile_list = [] tiles = parse_json.get_tiles(filename) dimension = parse_json.get_dimensions(filename) has_hammer = parse_json.has_hammer(filename) start_location = parse_json.get_pos_player(filename) direction = parse_json.get_dir_player(filename) best_solution = parse_json.get_best_solutions(filename) # Searching for a demo for the level demo = parse_json.get_demo(sys.argv[1], sys.argv[2]) if demo is not None: moves = demo[0] goals_collected = demo[1] else: print("No demo found") moves = [] goals_collected = [] # Creating the tile grid rows = tiles.split(';') for y in range(len(rows)): row = rows[y].split(',') for x in range(len(row)): tile_list.append(create_tile(row[x], x, y)) # Ceating the goal list goal_list = create_goal_list(tile_list) # Receiving the start location on the tiles start_tile = get_tile(tile_list, start_location[0], start_location[1], \ dimension[1], dimension[0]) # Calling the brute force algorithm b = brute_force.Brute_force(dimension[1], dimension[0], tile_list, \ goal_list, best_solution, start_tile, has_hammer, direction) best_path, rotations, permutations = b.solve() # Displaying the answer in commando's output = parse_output.parse(best_path, start_tile, best_solution, \ rotations) print("--- Level information ---") print("Starting location: (" + str(start_location[0]) + ", " + \ str(start_location[1]) + ")") print("Starting direction:", direction) # Displaying the grid for the users display_grid(start_location, dimension, tiles) print("\n--- Path info ---") print ('Path found:', len(best_path), 'moves. | ' 'Best solution:', \ best_solution,' moves. | Permutation used', permutations) print("Best path: ", ', '.join(output)) print("User path: ", ', '.join(moves)) # Creating hints for the user if necessary print("\n--- Hint generated ---") hint = hint_generation.Hint_generation(moves, output, goals_collected, \ goal_list, permutations) hint.process() print("\n--- Run time: ---") print("%s seconds" % (time.time() - start_time))