Esempio n. 1
0
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 moma(n, folder, datafile):
    existing_files = glob(folder + '*.out')
    filename = folder + 'run%d.out' % (len(existing_files) + 1)
    data = folder + datafile

    # Initialize algorithm
    batchsize = 100
    boxcap = 24
    rackcap = 300
    fillcap = 8
    pop = 100  # members per gen.
    end = 25000  # function evaluations
    # batchsize = 6
    # boxcap = 8
    # rackcap = 15
    # fillcap = 2
    # pop = 50            # members per gen.
    # end = 750           # function evaluations
    outf.startout(filename, n, end, data, 'MOMA')
    startt = datetime.now()
    print('                         ', startt)
    print(
        '*******************************************************************************'
    )
    print('     Method: MOMA\n')
    print('     data: ', datafile)
    print(
        '*******************************************************************************'
    )
    cookies = coolcookies.makeobjects(n, batchsize, data)
    moop = mop.MOCookieProblem(n, boxcap, rackcap, fillcap, cookies)
    bpp = BPP(n, boxcap, rackcap, cookies)
    gen = Generation(n, pop, end, cookies, bpp, moop)
    gen.initialp(folder + 'seed.txt')
    gen.makeq()

    # NSGA-II - Local search
    while not gen.endgen():
        gen.rungen()
        outf.genout(filename, gen.gett(), pop, gen.getq(), gen.getfnts())

    # Make output
    ndset = gen.finalapproxset()
    savefitvals(ndset, folder)
    savexys(ndset, folder)
    see(ndset, folder)
    outf.endout(filename)
    print('This algorithm has completed successfully.')
Esempio n. 3
0
def algorithm(n, folder, datafile):
    existing_files = glob(folder + '*.out')
    fname = folder + 'run%d.out' % (len(existing_files) + 1)
    data = folder + datafile

    # Initialize algorithm
    batchsize = 100
    boxcap = 24
    rackcap = 300
    fillcap = 8
    pop = 100           # members per gen.
    end = 25000         # function evaluations
    # batchsize = 6
    # boxcap = 8
    # rackcap = 15
    # fillcap = 2
    # pop = 50            # members per gen.
    # end = 750           # 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('*******************************************************************************')
    cookies = coolcookies.makeobjects(n, batchsize, data)
    moop = mop.MOCookieProblem(n, boxcap, rackcap, fillcap, cookies)
    bpp = grasp.BPP(n, cookies, moop)
    gen = Generation(n, pop, end, cookies, bpp, moop)
    gen.initialq(folder + 'seed.txt')
    # 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.')
Esempio n. 4
0
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 nsgaii(n, folder, file):
    import outformat as outf
    from glob import glob
    existing_files = glob(folder + '*.out')
    filename = folder + 'run%d.out' % (len(existing_files) + 1)
    data = folder + file

    # Initialize algorithm
    pop = 100  # members per gen.
    end = 25000  # function evaluations or 250 gen.
    outf.startout(filename, n, end, data, 'NSGA-II')
    startt = datetime.datetime.now()
    print('                         ', startt)
    print(
        '*******************************************************************************'
    )
    print('     Method: NSGA-II\n')
    print('     data: ', file)
    print(
        '*******************************************************************************'
    )
    binc, binh, items = makeitems(data)
    bpp = bp.BPP(n, binc, binh, items)
    gen = Generation(n, pop, end, items, bpp)
    gen.initialp()
    gen.makeq()

    # NSGA-II
    while not gen.endgen():
        gen.rungen()
        outf.genout(filename, gen.gett(), pop, gen.getq(), gen.getfnts())

    # Make output
    ndset = approx(gen.getarch())
    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.')
Esempio n. 6
0
def momad(n, folder, file):
    existing_files = glob(folder + '*.out')
    filename = folder + 'run%d.out' % (len(existing_files) + 1)
    data = folder + file

    # Initialize Algorithm
    end = 25000  # function evaluations
    method = 'MOMAD'
    outf.startout(filename, n, end, data, method)
    startt = datetime.now()
    print('                         ', startt)
    print('*******************************************************************************')
    print('     Method: MOMAD \n')
    print('     data: ', file)
    print('*******************************************************************************')
    if n <= 600:
        nso = n
    else:
        nso = 600  # number of single-objective functions
    binc, binh, items = makeitems(data)
    bpp = bp.BPP(n, binc, binh, items)
    moop = MOproblem(nso, items)
    gen = MOMADgen(n, bpp, moop, items, end)
    gen.initialize()

    # MOMAD
    while not gen.endgen():
        gen.rungen()
        fronts = []
        fronts.append(gen.getpe())
        fronts.append([])
        outf.genout(filename, gen.gett(), nso, gen.getpl(), fronts)

    see(gen.pe, 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 gen.pe:
            csvwriter.writerow([m.getindex(), m.getbins(), m.getmaxh(), m.getavgw()])
    outf.endout(filename)
    print('This algorithm has completed successfully.')
Esempio n. 7
0
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.')