Exemplo n.º 1
0
def action(model):
    start_time = time.time()
    # generating the 10k random solutions
    candidates = list()
    for _ in range(10000):
        ran_dec = [random.random() for _ in range(model.decsNum)]
        can = model.Individual(ran_dec)
        candidates.append(can)
    print('random sol created.')
    for can in candidates:
        model.eval(can)
    print('finish evaluating.')
    res = emo.sortNondominated(candidates, len(candidates), True)
    print('finish selection.')
    finish_time = time.time()
    with open(request_new_file('./tse_rs/god', model.name), 'w') as f:
        f.write('T:' + str(start_time) + '\n~~~\n')
        f.write('T:' + str(finish_time) + '\n')
        for front in res[0]:
            f.write(' '.join(map(str, front.fitness.values)))
            f.write('\n')

        f.write('~~~\n')

    return res
Exemplo n.º 2
0
from __future__ import division
from Benchmarks.POM3 import pre_defined
from Algorithms.NSGA2 import action
from repeats import request_new_file
import time
import pdb

if __name__ == '__main__':
    for x in [0, 1, 2]:
        model = pre_defined()[x]
        start_time = time.time()
        res = action(model, mu=300, ngen=10000 // 100, cxpb=0.9, mutpb=0.15)
        finish_time = time.time()

        with open(request_new_file('./tse_rs/nsga2', model.name), 'w') as f:
            f.write('T:' + str(start_time) + '\n~~~\n')
            f.write('T:' + str(finish_time) + '\n')
            for i in res:
                f.write(' '.join(map(str, i.fitness.values)))
                f.write('\n')
Exemplo n.º 3
0
    candidates = list()
    for _ in range(10000):
        ran_dec = [random.random() for _ in range(model.decsNum)]
        can = model.Individual(ran_dec)
        candidates.append(can)
    global M
    M = model
    res = sway(candidates, model.eval, where, comparing)

    return res


if __name__ == '__main__':
    for repeat in range(1):
        ii = [0, 1, 2, 3]
        for i in ii:
            XOMO_model = pre_defined()[i]
            start_time = time.time()
            res = get_sway_res(XOMO_model)
            finish_time = time.time()
            print(finish_time - start_time)
            # save the results
            with open(request_new_file('./tse_rs/sway', XOMO_model.name), 'w') as f:
                f.write('T:' + str(start_time) + '\n~~~\n')
                f.write('T:' + str(finish_time) + '\n')
                for i in res:
                    f.write(' '.join(map(str, i.fitness.values)))
                    f.write('\n')

        print('******   ' + str(repeat) + '   ******')
Exemplo n.º 4
0
    #     for l in f:
    #         can = model.Individual(l.strip('\n'))
    #         candidates.append(can)

    candidates = sat_gen_valid_pop(model, 10000)
    res = sway(candidates, model.eval,
               partial(split_products, groupC=min(15, model.featureNum // 7)),
               comparing)
    return res


if __name__ == '__main__':
    # models = ['eshop']
    #models = [ 'fiasco', 'freebsd', 'linux']
    models = ['webportal']

    for repeat in range(1):
        for name in models:
            print(name)
            model = DimacsModel(name)
            start_time = time.time()
            res = get_sway_res(model)
            finish_time = time.time()
            # save the results
            with open(request_new_file('./tse_rs/sway', name), 'w') as f:
                f.write('T:' + str(start_time) + '\n~~~\n')
                f.write('T:' + str(finish_time) + '\n')
                for i in res:
                    f.write(' '.join(map(str, i.fitness.values)))
                    f.write('\n')
Exemplo n.º 5
0
import sys

if __name__ == '__main__':
    # save_stdout = sys.stdout
    models = ['webportal', 'eshop', 'fiasco', 'freebsd', 'linux']
    # models = ['webportal']
    # for repeat in range(20):
    for name in models:
        fm = DimacsModel(name)
        start_at = time.time()

        res = SATIBEA.action(fm)
        # sys.stdout = save_stdout
        print(time.time() - start_at)
        # save the results
        with open(request_new_file('./tse_rs/satibea', name), 'w') as f:
            f.write('T:' + str(start_at) + '\n')
            f.write('~~~\n')
            for log in res[1]:
                gen = log['gen']
                fitness = log['fitness']
                at = log['time']

                if fitness == 'pass':
                    continue

                f.write('T:' + str(at) + '\n')
                f.write('Gen: ' + str(gen) + '\n')

                for i in fitness:
                    f.write(' '.join(map(str, i)))
Exemplo n.º 6
0
def action(fm):
    # get the 10k sat solutions
    def sat_gen_valid_pop(n):
        pops = list()
        cnf = copy.deepcopy(fm.cnfs)
        while len(pops) < n:
            for index, sol in enumerate(pycosat.itersolve(cnf)):
                new_ind = fm.Individual(''.join(
                    ['1' if i > 0 else '0' for i in sol]))
                pops.append(new_ind)
                if index > 20:
                    break
            for x in cnf:
                random.shuffle(x)
            random.shuffle(cnf)

        # for c in range(n):
        #     if c % 1 == 0: print(c)
        #     for sol in pycosat.itersolve(cnf):
        #         new_ind = fm.Individual(''.join(['1' if i > 0 else '0' for i in sol]))
        #         print 'x'
        #
        #     sol = pycosat.solve(cnf, vars=fm.featureNum)
        #     # ground_sol = copy.deepcopy(sol)
        #     if isinstance(sol, list):
        #         new_ind = fm.Individual(''.join(['1' if i > 0 else '0' for i in sol]))
        #         pops.append(new_ind)
        #         cnf.append([-x for x in sol])
        #         if c % 100 == 0:
        #             for x in cnf:
        #                 random.shuffle(x)
        #             random.shuffle(cnf)
        #     else:
        #         break
        random.shuffle(pops)
        return pops

    start_time = time.time()
    print('start gen ' + fm.name)
    pops = sat_gen_valid_pop(10000)
    print('finish gen ' + fm.name)
    candidates = [fm.Individual(i) for i in pops]

    # pdb.set_trace()
    # with open('/Users/jianfeng/Desktop/tse_rs/' + fm.name + '.txt', 'r') as f:
    #     for l in f:
    #         can = fm.Individual(l.strip('\n'))
    #         candidates.append(can)
    # evaluate all
    for can in candidates:
        fm.eval(can)

    res = emo.sortNondominated(candidates, len(candidates), True)
    finish_time = time.time()

    with open(request_new_file('./tse_rs/god', fm.name), 'w') as f:
        f.write('T:' + str(start_time) + '\n~~~\n')
        f.write('T:' + str(finish_time) + '\n')
        for front in res[0]:
            f.write(' '.join(map(str, front.fitness.values)))
            f.write('\n')

        f.write('~~~\n')