コード例 #1
0
ファイル: benchmarker.py プロジェクト: hoh/gaproject
class Benchmarker(object):
    'Main class for benchmarker.'

    def __init__(self):
        self.launcher = Launcher()

    def go(self):
        '''
        Launches the benchmarker.

        1.loads problem
        1. Clears queue and results.
        2. create new job
        3. Executes the queue and retrieves the best result and plots it
        4. New variable and back to [1].

        '''
        print 'Go benchmarker go!'

        #base is a job based on the results of the optimizer
        base = {
            'evaluate': 'eval_simple',
            'mutate': ('mutshuf', {'indpb': 0.01}),
            'mate': 'cxSCX',
            'population': 201,
            'generations': 248,
            'indices': 'path_creator',
            'cxpb': 0.80,
            'mutpb': 0.2,
        }

        problems = ['belgiumtour.tsp', 'xqf131.tsp', 'bcl380.tsp', 'xql622.tsp']

        for problem in problems:

            #1. load problem
            box = Box('data/TSPBenchmark')
            data = box.get(problem)
            self.launcher.load_data(data)

            #2. clear
            self.launcher.clear()

            #3. create job
            print 'Attacking problem: ', problem
            job = base.copy()
            job['name'] = 'bmark-{}'.format(problem)

            #4. launch job
            best = self.launcher.launch_queue([job], plot_all=True)
            # plot solution
            analysis.plot(best['best'][0], data)

        print 'done!'
        raw_input()
コード例 #2
0
ファイル: optimizer.py プロジェクト: hoh/gaproject
 def __init__(self):
     self.launcher = Launcher()
コード例 #3
0
ファイル: optimizer.py プロジェクト: hoh/gaproject
class Optimizer(object):
    'Main class for parameter optimization.'

    def __init__(self):
        self.launcher = Launcher()

    def go(self):
        '''
        Launches the super uber optimizer.

        1. Clears queue and results.
        2. Queues new results for variable range of interest
        3. Executing the queue and retrieving the best result
        4. New variable and back to [2].

        '''
        print 'Go go go !'

        # 0. Loading data
        box = Box('data/TSPBenchmark')
        data = box.get('xqf131.tsp')
        self.launcher.load_data(data)

        # 1. clear queue and results
        self.launcher.clear()

        # 2. Create dictionnaries for range
        base = {
            'evaluate': 'eval_simple',
            'mutate': ('mutshuf', {'indpb': 0.01}),
            'mate': 'cxSCX',
            'population': 201,
            'generations': 248,
            'indices': 'path_creator',
            'cxpb': 0.80,
            'mutpb': 0.2,
        }

        print 'Optimizing population'
        jobs = []
        for pop in range(1, 1000, 50):
            job = base.copy()
            job['name'] = 'pop-{}'.format(pop)
            job['population'] = pop
            job['generations'] = 10000 / pop
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing cxpb'
        jobs = []
        for cxpb in xrange(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], cxpb / 100.)
            job['cxpb'] = cxpb / 100.
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing indpb'
        jobs = []
        for mut in range(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mut / 100.)
            job['mutate'] = (job['mutate'][0], {'indpb': mut / 100.})
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing mutpb'
        jobs = []
        for mutpb in xrange(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mutpb / 100.)
            job['mutpb'] = mutpb / 100.
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing crossover operator'
        crossovers = ['cxPMX', 'cxSCX', 'cxERX', 'cxOX', 'cxHeuristic']
        jobs = []
        for cx_operator in crossovers:
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], cx_operator)
            job['mate'] = cx_operator
            if cx_operator == 'cxHeuristic':
                job['evaluate'] = 'eval_adjacent'
                job['mutate'] = ('mutshuf_adj', {'indpb': best['mutate'][1]})
                job['indices'] = 'adj_creator'
            else:
                job['evaluate'] = 'eval_simple'
                job['mutate'] = ('mutshuf', {'indpb': best['mutate'][1]})
                job['indices'] = 'path_creator'

            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=True)['set']
        del best['_id']

        print 'Optimizing mutation operator'
        jobs = []
        if best['mate'] == 'cxHeuristic':
            mutations = ['mutshuf_adj', 'invert_mut_adj', 'insert_mut_adj', 'simple_inv_adj']
        else:
            mutations = ['mutshuf', 'invert_mut', 'insert_mut', 'simple_inv']

        for mut_operator in mutations:
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mut_operator)
            job['mutate'] = (mut_operator, {'indpb': best['mutate'][1]})

            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=True)['set']
        del best['_id']

        print 'runned'
        raw_input()
コード例 #4
0
ファイル: benchmarker.py プロジェクト: hoh/gaproject
 def __init__(self):
     self.launcher = Launcher()
コード例 #5
0
ファイル: repr_comparator.py プロジェクト: hoh/gaproject
class RComparator(object):
    'Main class for representation comparison.'

    def __init__(self):
        self.launcher = Launcher()

    def go(self):
        # '''
        # Launches the super uber optimizer.

        # 1. Clears queue and results.
        # 2. Queues new results for variable range of interest
        # 3. Executing the queue and retrieving the best result
        # 4. New variable and back to [2].

        # '''
        print 'Go go power rangers!'

        # 0. Loading data
        box = Box('data/TSPBenchmark')
        data = box.get('xqf131.tsp')
        self.launcher.load_data(data)

        # 1. clear queue and results
        self.launcher.clear()

        # 2. Create base dictionary
        base = {
            'evaluate': 'eval_simple',
            'mutate': ('mutshuf', {'indpb': 0.01}),
            'mate': 'cxSCX',
            'population': 201,
            'generations': 2,
            'indices': 'path_creator',
            'cxpb': 0.80,
            'mutpb': 0.2,
        }

        adj_mutations = ['mutshuf_adj', 'invert_mut_adj', 'insert_mut_adj', 'simple_inv_adj']
        path_mutations = ['mutshuf', 'invert_mut', 'insert_mut', 'simple_inv']
        crossovers = ['cxPMX', 'cxESCX', 'cxSCX', 'cxERX', 'cxOX', 'cxHeuristic']

        for mut_operator in path_mutations:
            print 'Computing comparison for ', mut_operator
            jobs = []
            for crossover in crossovers:
                job = base.copy()
                job['name'] = '{}-{}'.format(crossover, mut_operator)
                job['mate'] = crossover
                if crossover == 'cxHeuristic':
                    job['evaluate'] = 'eval_adjacent'
                    job['indices'] = 'adj_creator'
                    # we set the adjacent mutation relying on the fact that adj mut and path mut
                    # follow the same ordering
                    index_curr_mut = path_mutations.index(mut_operator)
                    job['mutate'] = (adj_mutations[index_curr_mut], {'indpb': job['mutate'][1]['indpb']})
                else:
                    job['evaluate'] = 'eval_simple'
                    job['mutate'] = (mut_operator, {'indpb': job['mutate'][1]['indpb']})
                    job['indices'] = 'path_creator'

                jobs.append(job)
            self.launcher.launch_queue(jobs, plot_all=True)['set']
        print 'runned'
        raw_input()
コード例 #6
0
class Optimizer(object):
    'Main class for parameter optimization.'

    def __init__(self):
        self.launcher = Launcher()

    def go(self):
        '''
        Launches the super uber optimizer.

        1. Clears queue and results.
        2. Queues new results for variable range of interest
        3. Executing the queue and retrieving the best result
        4. New variable and back to [2].

        '''
        print 'Go go go !'

        # 0. Loading data
        box = Box('data/TSPBenchmark')
        data = box.get('xqf131.tsp')
        self.launcher.load_data(data)

        # 1. clear queue and results
        self.launcher.clear()

        # 2. Create dictionnaries for range
        base = {
            'evaluate': 'eval_simple',
            'mutate': ('mutshuf', {
                'indpb': 0.01
            }),
            'mate': 'cxSCX',
            'population': 201,
            'generations': 248,
            'indices': 'path_creator',
            'cxpb': 0.80,
            'mutpb': 0.2,
        }

        print 'Optimizing population'
        jobs = []
        for pop in range(1, 1000, 50):
            job = base.copy()
            job['name'] = 'pop-{}'.format(pop)
            job['population'] = pop
            job['generations'] = 10000 / pop
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing cxpb'
        jobs = []
        for cxpb in xrange(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], cxpb / 100.)
            job['cxpb'] = cxpb / 100.
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing indpb'
        jobs = []
        for mut in range(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mut / 100.)
            job['mutate'] = (job['mutate'][0], {'indpb': mut / 100.})
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing mutpb'
        jobs = []
        for mutpb in xrange(1, 100, 5):
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mutpb / 100.)
            job['mutpb'] = mutpb / 100.
            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=False)['set']
        del best['_id']

        print 'Optimizing crossover operator'
        crossovers = ['cxPMX', 'cxSCX', 'cxERX', 'cxOX', 'cxHeuristic']
        jobs = []
        for cx_operator in crossovers:
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], cx_operator)
            job['mate'] = cx_operator
            if cx_operator == 'cxHeuristic':
                job['evaluate'] = 'eval_adjacent'
                job['mutate'] = ('mutshuf_adj', {'indpb': best['mutate'][1]})
                job['indices'] = 'adj_creator'
            else:
                job['evaluate'] = 'eval_simple'
                job['mutate'] = ('mutshuf', {'indpb': best['mutate'][1]})
                job['indices'] = 'path_creator'

            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=True)['set']
        del best['_id']

        print 'Optimizing mutation operator'
        jobs = []
        if best['mate'] == 'cxHeuristic':
            mutations = [
                'mutshuf_adj', 'invert_mut_adj', 'insert_mut_adj',
                'simple_inv_adj'
            ]
        else:
            mutations = ['mutshuf', 'invert_mut', 'insert_mut', 'simple_inv']

        for mut_operator in mutations:
            job = best.copy()
            job['name'] = '{}-{}'.format(job['name'], mut_operator)
            job['mutate'] = (mut_operator, {'indpb': best['mutate'][1]})

            jobs.append(job)

        best = self.launcher.launch_queue(jobs, plot_all=True)['set']
        del best['_id']

        print 'runned'
        raw_input()
コード例 #7
0
ファイル: repr_comparator.py プロジェクト: hoh/gaproject
class RComparator(object):
    'Main class for representation comparison.'

    def __init__(self):
        self.launcher = Launcher()

    def go(self):
        # '''
        # Launches the super uber optimizer.

        # 1. Clears queue and results.
        # 2. Queues new results for variable range of interest
        # 3. Executing the queue and retrieving the best result
        # 4. New variable and back to [2].

        # '''
        print 'Go go power rangers!'

        # 0. Loading data
        box = Box('data/TSPBenchmark')
        data = box.get('xqf131.tsp')
        self.launcher.load_data(data)

        # 1. clear queue and results
        self.launcher.clear()

        # 2. Create base dictionary
        base = {
            'evaluate': 'eval_simple',
            'mutate': ('mutshuf', {
                'indpb': 0.01
            }),
            'mate': 'cxSCX',
            'population': 201,
            'generations': 2,
            'indices': 'path_creator',
            'cxpb': 0.80,
            'mutpb': 0.2,
        }

        adj_mutations = [
            'mutshuf_adj', 'invert_mut_adj', 'insert_mut_adj', 'simple_inv_adj'
        ]
        path_mutations = ['mutshuf', 'invert_mut', 'insert_mut', 'simple_inv']
        crossovers = [
            'cxPMX', 'cxESCX', 'cxSCX', 'cxERX', 'cxOX', 'cxHeuristic'
        ]

        for mut_operator in path_mutations:
            print 'Computing comparison for ', mut_operator
            jobs = []
            for crossover in crossovers:
                job = base.copy()
                job['name'] = '{}-{}'.format(crossover, mut_operator)
                job['mate'] = crossover
                if crossover == 'cxHeuristic':
                    job['evaluate'] = 'eval_adjacent'
                    job['indices'] = 'adj_creator'
                    # we set the adjacent mutation relying on the fact that adj mut and path mut
                    # follow the same ordering
                    index_curr_mut = path_mutations.index(mut_operator)
                    job['mutate'] = (adj_mutations[index_curr_mut], {
                        'indpb': job['mutate'][1]['indpb']
                    })
                else:
                    job['evaluate'] = 'eval_simple'
                    job['mutate'] = (mut_operator, {
                        'indpb': job['mutate'][1]['indpb']
                    })
                    job['indices'] = 'path_creator'

                jobs.append(job)
            self.launcher.launch_queue(jobs, plot_all=True)['set']
        print 'runned'
        raw_input()