def mutation(chrom): inds = [i for i, x in enumerate(chrom) if f.is_operator(x)] index = random.choice(inds) sub_tree = f.find_subtree(chrom, index) mut_tree = f.generate(0) return (chrom[:index] + mut_tree + chrom[index+len(sub_tree):])
import change_in_dirs import functions a = change_in_dirs.compute_dir_index() functions.generate(2) functions.remove(2) b = change_in_dirs.compute_dir_index() data = change_in_dirs.compute_diff(b,a) print(data) created_files = data["created"] print(created_files) functions.compile_and_move(data)
#when naming the epub (not in the epub itself), need to integrate the #mechanics of get_chapter_s_e() with the above code elif chapter_start == '': chapter_s, chapter_e = f.get_chapter_s_e(title_list) novel_name = info['novel_name'] ''' if finished_flag: epub_name = novel_name + '.epub' else: ''' latter = '-' + chapter_e if one: latter = '' epub_name = novel_name + ' ' + chapter_s + latter + '.epub' f.generate(cleaned_html_files, info["novel_name"], info["author"], epub_name, imgs, info) #generate epub using cleaned files and making the necessary files elapsed_time = time.time() - start_time print('Time taken to finish: ' + str(elapsed_time) + ' seconds (around ' + str(elapsed_time // 60) + ' minutes)') flag = input('\nWant to download another epub? y/n ') flag = f.check_error_yn(flag) if flag.lower() == 'y': continue elif flag.lower() == 'n': print('Quitting program...') sys.exit()
def gen_pop(pop_size): return list(map(lambda x: f.generate(0), range(pop_size)))
# -*- coding: utf-8 -*- import sys import mpi4py.MPI as MPI from functions import generate, packParams if len(sys.argv) < 2: # Mensaje de error si se recibe más o menos de 1 parámetro print 'ERROR, dirName is a required input' else: if not MPI.Is_initialized(): MPI.Init() params = packParams(sys.argv[1:],'') params[0] = sys.argv[1] generate(params)
def game_loop(): functions.generate() # initializing local variables changex=0 changey=0 speedx=3 man=40 k=-1 count=0 m=0 velocity=3 while not settings.gamequit: keys = pygame.key.get_pressed() if keys[pygame.K_a] and ((objects.A.rect.y>=objects.D.height+80-90 and objects.A.rect.y<=objects.D.height+80-70) or (objects.A.rect.y>=settings.dheight*0.4-90 and objects.A.rect.y<=settings.dheight*0.4-70) or (objects.A.rect.y>=settings.dheight*0.6-90 and objects.A.rect.y<=settings.dheight*0.6-70) or (objects.A.rect.y>=settings.dheight*0.8-90 and objects.A.rect.y<=settings.dheight*0.8-70) or (objects.A.rect.y>=settings.dheight-90 and objects.A.rect.y<=settings.dheight-72)): objects.A.rect.x -= 2 if settings.jump==1: settings.left=1 objects.A.imgchange('mariowalk2.png') if keys[pygame.K_d] and ((objects.A.rect.y>=objects.D.height+80-90 and objects.A.rect.y<=objects.D.height+80-70) or (objects.A.rect.y>=settings.dheight*0.4-90 and objects.A.rect.y<=settings.dheight*0.4-70) or (objects.A.rect.y>=settings.dheight*0.6-90 and objects.A.rect.y<=settings.dheight*0.6-70) or (objects.A.rect.y>=settings.dheight*0.8-90 and objects.A.rect.y<=settings.dheight*0.8-70) or (objects.A.rect.y>=settings.dheight-90 and objects.A.rect.y<=settings.dheight-72)): objects.A.rect.x += 2 objects.A.imgchange('mariowalk.png') if settings.jump==1: settings.right=1 if keys[pygame.K_w] and ((objects.A.rect.x>settings.Allowed[0]-30 and objects.A.rect.x<settings.Allowed[0]+50 and objects.A.rect.y>settings.Allowed[1]-objects.A.height-30 and objects.A.rect.y<settings.Allowed[1]+50) or (objects.A.rect.x>settings.Allowed[2]-30 and objects.A.rect.x<settings.Allowed[2]+50 and objects.A.rect.y>settings.Allowed[3]-objects.A.height-30 and objects.A.rect.y<settings.Allowed[3]+50) or (objects.A.rect.x>settings.Allowed[4]-30 and objects.A.rect.x<settings.Allowed[4]+50 and objects.A.rect.y>settings.Allowed[5]-objects.A.height-30 and objects.A.rect.y<settings.Allowed[5]+50) or (objects.A.rect.x>settings.Allowed[6]-30 and objects.A.rect.x<settings.Allowed[6]+50 and objects.A.rect.y>settings.Allowed[7]-objects.A.height-20 and objects.A.rect.y<settings.Allowed[7]+50)): objects.A.rect.y-=1 #A.imgchange('marioback.png') if keys[pygame.K_s] and ((objects.A.rect.x>settings.Allowed[0]-30 and objects.A.rect.x<settings.Allowed[0]+50 and objects.A.rect.y>settings.Allowed[1]-objects.A.height-50 and objects.A.rect.y<settings.Allowed[1]+40) or (objects.A.rect.x>settings.Allowed[2]-30 and objects.A.rect.x<settings.Allowed[2]+50 and objects.A.rect.y>settings.Allowed[3]-objects.A.height-50 and objects.A.rect.y<settings.Allowed[3]+40) or (objects.A.rect.x>settings.Allowed[4]-30 and objects.A.rect.x<settings.Allowed[4]+50 and objects.A.rect.y>settings.Allowed[5]-objects.A.height-50 and objects.A.rect.y<settings.Allowed[5]+40) or (objects.A.rect.x>settings.Allowed[6]-30 and objects.A.rect.x<settings.Allowed[6]+50 and objects.A.rect.y>settings.Allowed[7]-objects.A.height-50 and objects.A.rect.y<settings.Allowed[7]+46)) : objects.A.rect.y+=1 #A.imgchange('marioback.png') for event in pygame.event.get(): man+=30 if event.type==pygame.QUIT: settings.gamequit=True if event.type==pygame.KEYDOWN: if event.key==pygame.K_SPACE and settings.jump!=1 and ((objects.A.rect.y>=objects.D.height+80-90 and objects.A.rect.y<=objects.D.height+80-70) or (objects.A.rect.y>=settings.dheight*0.4-90 and objects.A.rect.y<=settings.dheight*0.4-70) or (objects.A.rect.y>=settings.dheight*0.6-90 and objects.A.rect.y<=settings.dheight*0.6-70) or (objects.A.rect.y>=settings.dheight*0.8-90 and objects.A.rect.y<=settings.dheight*0.8-70) or (objects.A.rect.y>=settings.dheight-90 and objects.A.rect.y<=settings.dheight-70)): changey=-5 changex=0 save=objects.A.rect.y settings.jump=1 if event.key==pygame.K_q: settings.gamequit=True if event.type==pygame.USEREVENT: k+=1 settings.ball.append('0') settings.ball[k]=classes.Fireball('firen.png',objects.D.rect.x,110) settings.ball[k].start(settings.fast,0,0) groups.fireball.add(settings.ball[k]) m=0 while m<=k: settings.ball[m].movement() m+=1 if ((objects.A.rect.y>=objects.D.height+80-90 and objects.A.rect.y<=objects.D.height+80-70 and objects.A.rect.x>3*296) or (objects.A.rect.y>=settings.dheight*0.4-90 and objects.A.rect.y<=settings.dheight*0.4-70 and objects.A.rect.x>2*296 and objects.A.rect.x<3*296-195) or (objects.A.rect.y>=settings.dheight*0.6-90 and objects.A.rect.y<=settings.dheight*0.6-70 and ((objects.A.rect.x>296 and objects.A.rect.x<2*296-230) or (objects.A.rect.x>3*296+40 and objects.A.rect.x<settings.dwidth)))): settings.fall=1 if settings.fall==1: objects.A.falling() if objects.A.rect.x>1.2*296+40: functions.changeimg('princess2.png') else: functions.changeimg('princess.png') if settings.jump==1 and velocity>0 and settings.count==0: objects.A.rect.y-=velocity if settings.right==1: objects.A.rect.x+=2 elif settings.left==1: objects.A.rect.x-=2 else: objects.A.rect.x+=0 velocity-=0.1 elif settings.jump==1 and objects.A.rect.y<save: velocity+=0.1 settings.count=1 objects.A.rect.y+=velocity settings.count+=1 if settings.left==1: objects.A.rect.x-=2 elif settings.right==1: objects.A.rect.x+=2 else: objects.A.rect.x+=0 else: if objects.A.rect.y==71: objects.A.rect.y=68 settings.count=settings.jump=settings.left=settings.right=0 velocity=3 functions.checkWall() blockhit=functions.checkCollision(groups.block_list,True) for blocks in blockhit: settings.score+=5 firehit=functions.checkCollision(groups.fireball,False) donkeyhit=functions.checkCollision(groups.donkey,False) if len(firehit)!=0 or len(donkeyhit)!=0: settings.jump=settings.right=settings.count=settings.left=settings.fall=0 functions.death() objects.D.move() functions.checkWin() changex=0 changey=0 draw.blitndraw()
optimizer = tf.keras.optimizers.Adam(learning_rate, beta_1=0.9, beta_2=0.98, epsilon=1e-9) ckpt = tf.train.Checkpoint(transformer=model, optimizer=optimizer) ckpt_manager = tf.train.CheckpointManager(ckpt, settings.checkpoint_dir, max_to_keep=5) # load weights if ckpt_manager.latest_checkpoint: ckpt.restore(ckpt_manager.latest_checkpoint).expect_partial( ) # since we'll load the optimizer as well print('Latest checkpoint restored.') # # load savedModel format # model = tf.keras.models.load_model('Models/SmAll/fast3') # model.run_eagerly = True # just some midi header info touhou = False # generate print("Generating w/ starter...") starter = functions.generate( model, np.load('Music/Albéniz/wordEvents/Aragon (Fantasia) Op.47 part 6.mid.npy') [:100], 200) decode.decode(starter, 'starter test.mid', touhou=touhou) # model.save('INSERT PATH HERE')