def mpi_run(): problem = { 'yu_2d_only': { 'npop': 4000, 'ngen': 100, 'nobj': 10, 'nvar': 6, 'vran': [[0., 35.], [-35., 0], [-35., 0], [-35., 0], [0., 35.], [-35., 0]], 'f': yu_2d_only }, } def def_problem(v): p = problem[v] return p['f'], p['npop'], p['ngen'], p['nvar'], p['nobj'], p['vran'] eta_c, eta_m = 20, 20 f, npop, ngen, nvar, nobj, vran = def_problem('yu_2d_only') #== create random parents if rank == 0: #pop = nsga2.nsga2init(npop, ngen, nvar, nobj, vran) fid = h5py.File('./data/yu_2d_only.h5', 'r') pop = copy.deepcopy(np.array(fid['0100'])) fid.close() pop = mpi_controller(pop) else: mpi_worker(f, nvar, nobj) #== evolve for ng in range(ngen): if rank == 0: print('\n%4i-th generation' % (ng + 1)) print('started at {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now())) kd = nsga2.nsga2getChild(pop, nvar, nobj, vran, eta_c, eta_m) #print 'got child' kd = mpi_controller(kd) #print 'cal child' pop = nsga2.nsga2toursel(pop, kd, nvar) #print 'select child' #--- save results fid = h5py.File('./data/nsls2_20161118.h5', 'a') fid['%04i' % (ng + 1)] = pop fid.close() print('finished at {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now())) else: mpi_worker(f, nvar, nobj) MPI.Finalize()
def main(): problem = { 'yu_2d_only': { 'npop': 8000, 'ngen': 100, 'nobj': 10, 'nvar': 6, 'vran': [[0.,35.],[-35.,0],[-35.,0],[-35.,0],[0.,35.],[-35.,0]], 'f': yu_2d_only }, } def def_problem(v): p = problem[v] return p['f'], p['npop'], p['ngen'], p['nvar'], p['nobj'], p['vran'] eta_c, eta_m = 20, 20 f, npop, ngen, nvar, nobj, vran = def_problem('yu_2d_only') #== create random parents if rank == 0: if len(sys.argv) == 1: pop = nsga2.nsga2init(npop, ngen, nvar, nobj, vran) lastg = 0 #print lastg # --- starting from previous result else: fid = h5py.File(sys.argv[1],'r') lastg = fid.keys()[-1] pop = np.array(fid[lastg]) fid.close() lastg = int(lastg) # --- pop = mpi_controller(pop) else: mpi_worker(f,nvar,nobj) lastg = None lastg = comm.bcast(lastg, root=0) #== evolve for ng in xrange(lastg+1,ngen): if rank == 0: print('\n%4i-th generation ...'%ng) kd = nsga2.nsga2getChild(pop, nvar, nobj, vran, eta_c, eta_m) kd = mpi_controller(kd) pop = nsga2.nsga2toursel(pop,kd,nvar) #--- save results fid = h5py.File(sys.argv[1],'a') fid['%04i'%ng] = pop fid.close() print('finished at {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())) else: mpi_worker(f,nvar,nobj) MPI.Finalize()
def mpi_run(): problem = { 'yu_2d_only': { 'npop': 4000, 'ngen': 100, 'nobj': 10, 'nvar': 9, #'vran': [[23.,27.],[-15.,-11.],[-16.,-12.],[-29.,-27.],[31.,35.],[-4.,0],[23.,27.],[-15.,-11.],[-16.,-12.]], 'vran': [[0., 35.], [-35., 0.], [-35., 0.], [-35., 0.], [0., 35.], [-35., 0.], [-2., 2.], [-2., 2.], [-2., 2.]], 'f': yu_2d_only }, } def def_problem(v): p = problem[v] return p['f'], p['npop'], p['ngen'], p['nvar'], p['nobj'], p['vran'] eta_c, eta_m = 20, 20 f, npop, ngen, nvar, nobj, vran = def_problem('yu_2d_only') #== create random parents if rank == 0: pop = nsga2.nsga2init(npop, ngen, nvar, nobj, vran) # --- starting from previous result #fid = h5py.File('./data/anhe_20170203.h5','r') #pop = copy.deepcopy(np.array(fid['0030'])) #fid.close() # --- pop = mpi_controller(pop) else: mpi_worker(f, nvar, nobj) #== evolve for ng in xrange(0, ngen): if rank == 0: print('\n%4i-th generation ...' % ng) kd = nsga2.nsga2getChild(pop, nvar, nobj, vran, eta_c, eta_m) kd = mpi_controller(kd) pop = nsga2.nsga2toursel(pop, kd, nvar) #--- save results fid = h5py.File('data/anhe_20170204.h5', 'a') fid['%04i' % ng] = pop fid.close() print('finished at {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now())) else: mpi_worker(f, nvar, nobj) MPI.Finalize()
def mpi_run(): problem = { 'yu_2d': { 'npop': 4000, 'ngen': 100, 'nobj': 34, 'nvar': 6, 'vran': [[0.,35.],[-35.,0],[-35.,0],[-35.,0],[0.,35.],[-35.,0]], 'f': yu_2d }, 'yu_2d_only': { 'npop': 4000, 'ngen': 100, 'nobj': 8, 'nvar': 6, 'vran': [[0.,35.],[-35.,0],[-35.,0],[-35.,0],[0.,35.],[-35.,0]], 'f': yu_2d_only }, } def def_problem(v): p = problem[v] return p['f'], p['npop'], p['ngen'], p['nvar'], p['nobj'], p['vran'] eta_c, eta_m = 20, 20 f, npop, ngen, nvar, nobj, vran = def_problem('yu_2d_only') #== create random parents if rank == 0: pop = nsga2.nsga2init(npop, ngen, nvar, nobj, vran) #pop = np.loadtxt('./data/yu_2d_only_0037.txt') pop = mpi_controller(pop) else: mpi_worker(f,nvar,nobj) #== evolve for ng in range(ngen): if rank == 0: print('\n%4i-th generation ...'%(ng+1)) kd = nsga2.nsga2getChild(pop, nvar, nobj, vran, eta_c, eta_m) kd = mpi_controller(kd) pop = nsga2.nsga2toursel(pop,kd,nvar) #--- save results ''' fname = './data/yu_2d_only_new_'+string.zfill(ng+1,4)+'.txt' fid = open(fname,'w') m,n = pop.shape for i1 in range(m): fid.write((n*'%15.6e'+'\n')%tuple(pop[i1])) fid.close() ''' fid = h5py.File('data/yu_2d_only_triangler.h5','a') fid['%04i'%(ng+1)] = pop fid.close() else: mpi_worker(f,nvar,nobj) MPI.Finalize()
def mpi_run(): rank = MPI.COMM_WORLD.Get_rank() name = MPI.Get_processor_name() size = MPI.COMM_WORLD.Get_size() problem = { 'yu_2d_only': { 'npop': 500, 'ngen': 100, 'nobj': 10, 'nvar': 5, 'vran': [[0, 1000], [-1000, 0], [0, 1000], [-1000, 0], [0, 1000]], 'f': yu_2d_only }, } def def_problem(v): p = problem[v] return p['f'], p['npop'], p['ngen'], p['nvar'], p['nobj'], p['vran'] eta_c, eta_m = 20, 20 f, npop, ngen, nvar, nobj, vran = def_problem('yu_2d_only') #== create random parents if rank == 0: #pop = nsga2.nsga2init(npop, ngen, nvar, nobj, vran) fid = h5py.File('./data/sls_20161128_8.h5', 'r') last = fid.keys()[-1] pop = copy.deepcopy(np.array(fid[last])) fid.close() pop = master(pop) else: slave(f, nvar, nobj) #== evolve for ng in range(ngen): if rank == 0: print('\n%4i-th generation' % (ng + 1)) print('started at {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now())) kd = nsga2.nsga2getChild(pop, nvar, nobj, vran, eta_c, eta_m) print 'got child' kd = master(kd) print 'cal child' pop = nsga2.nsga2toursel(pop, kd, nvar) print 'select child' #--- save results fid = h5py.File('./data/sls_20161128_9.h5', 'a') fid['%04i' % (ng + 1)] = pop fid.close() print('finished at {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now())) else: slave(f, nvar, nobj) MPI.Finalize()