def setUp(self): data = 'GAMMA-PC/SBSBPP500/Experiment01/SBSBPP500_run1.txt' self.n = 500 pop = 50 # members per gen. end = 750 # function evaluations binc, binh, items = makeitems(data) moop = mop.MOproblem(pop, items) self.bpp = grasp.BPP(self.n, binc, binh, items, moop)
def setUp(self): data = 'example/example500.txt' self.n = 500 pop = 50 # members per gen. end = 750 # function evaluations binc, binh, items = makeitems(data) moop = mop.MOproblem(pop, items) self.bpp = grasp.BPP(self.n, binc, binh, items, moop)
def moma(n, folder, datafile): existing_files = glob(folder + '*.out') filename = folder + 'run%d.out' % (len(existing_files) + 1) data = folder + datafile # Initialize algorithm pop = 100 # members per gen. end = 25000 # function evaluations or 250 gen. outf.startout(filename, n, end, data, 'MOMA') startt = datetime.now() print(' ', startt) print( '*******************************************************************************' ) print(' Method: MOMA\n') print(' data: ', datafile) print( '*******************************************************************************' ) binc, binh, items = makeitems(data) bpp = bp.BPP(n, binc, binh, items) moop = mop.MOproblem(pop, items) gen = Generation(n, pop, end, items, bpp, moop) gen.initialp() gen.makeq() # NSGA-II - Local search while not gen.endgen(): gen.rungen() outf.genout(filename, gen.gett(), pop, gen.getq(), [gen.getarch(), []]) # Get final nondominated set aslimit = 75 r, allfronts = fnds(gen.getarch()) if len(allfronts[0]) > aslimit: gen.fittruncation(allfronts[0], aslimit) ndset = approx(gen.getarch()) # Make output see(ndset, folder) import csv with open(folder + 'ApproximationSet.csv', 'w') as csvfile: csvwriter = csv.writer(csvfile, dialect='excel', delimiter=',') csvwriter.writerow(['Solution ID', 'f[1]', 'f[2]', 'f[3]']) for m in ndset: csvwriter.writerow( [m.getindex(), m.getbins(), m.getmaxh(), m.getavgw()]) outf.endout(filename) print('This algorithm has completed successfully.')
def algorithm(n, folder, datafile): existing_files = glob(folder + '*.out') fname = folder + 'run%d.out' % (len(existing_files) + 1) data = folder + datafile # Initialize algorithm pop = 100 # members per gen. end = 25000 # function evaluations outf.startout(fname, n, end, data, 'GAMMA-PC') startt = datetime.now() print(' ', startt) print( '*******************************************************************************' ) print(' Method: GAMMA-PC\n') print(' data: ', datafile) print( '*******************************************************************************' ) binc, binh, items = makeitems(data) moop = mop.MOproblem(pop, items) bpp = grasp.BPP(n, binc, binh, items, moop) gen = Generation(n, pop, end, items, bpp, moop) gen.initialq() # Remove this after finishing import warnings warnings.simplefilter('error', RuntimeWarning) # Algorithm while not gen.endgen(): outf.gen_probabilities(fname, gen.gett() + 1, **gen.get_probabilities()) gen.rungen() outf.genout(fname, gen.gett(), pop, gen.getq(), gen.getarch(), onlyapprox=True) # Make output ndset = gen.finalapproxset() savefitvals(ndset, folder) savexys(ndset, folder) see(ndset, folder) outf.endout(fname) print('This algorithm has completed successfully.')
def moepso(n, folder, inputfile): existing_files = glob(folder + '*.out') filename = folder + 'run%d.out' % (len(existing_files) + 1) data = folder + inputfile # Initialize Algorithm pop = 500 # swarm members end = 25000 # function evaluations method = 'MOEPSO' outf.startout(filename, n, end, data, method) startt = datetime.now() print(' ', startt) print('*******************************************************************************') print(' Method: MOEPSO \n') print(' data: ', inputfile) print('*******************************************************************************') binc, binh, items = makeitems(data) bpp = bp.BPP(n, binc, binh, items) moop = mop.MOproblem(pop, items) gen = MOEPSOgen(n, pop, end, bpp, moop, items) # MOEPSO generations while not gen.endgen(): gen.rungen() fronts = [gen.getgbest(), []] outf.genout(filename, gen.gett(), pop, gen.getp(), fronts) see(gen.gbest, folder, 'variables/') import csv with open(folder + 'ApproximationSet.csv', 'w') as csvfile: csvwriter = csv.writer(csvfile, dialect='excel', delimiter=',') csvwriter.writerow(['Solution ID', 'f[1]', 'f[2]', 'f[3]']) for m in gen.gbest: csvwriter.writerow([m.getindex(), m.getbins(), m.getmaxh(), m.getavgw()]) outf.endout(filename) print('This algorithm has completed successfully.')