Example #1
0
    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()
Example #2
0
 def run(self):
     'Launches the benchmarks.'
     box = Box('data/TSPBenchmark')
     data = box.get('belgiumtour.tsp')
     # Overwriting data file if given:
     for arg in self.argv:
         if box.isfile(arg):
             data = box.get(arg)
     print 'Using benchmark:', data.path
     gaproject.run.main(data)
     print 'runned'
Example #3
0
    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()
Example #4
0
def plot(job):
    job_result_path = os.path.join(shared.settings.filesDir, str(job['_id']),
                                   'data.json')
    job_result = json.load(open(job_result_path))

    box = Box('data/TSPBenchmark')
    data = box.get(job['data'])

    best_individual = job_result['best'][0]
    plot_ind(best_individual, data)

    for stats in job_result['stats']:
        plot_fitness(stats)

    raw_input('end ?')
    plt.close()
    plt.close()
Example #5
0
def process(job):
    "Launches the given job."

    logging.info('running job {}'.format(job))

    box = Box('data/TSPBenchmark')
    shared.data = box.get(job['data'])

    if 'metaGA' in job:
        shared.settings.metaGA = job['metaGA']

    # TODO: Refactor the following:
    shared.orderedSequenceOfNodes = shared.data.nodesOrderedByMedian(shared.data.dist_matrix())

    operators = gaproject.sets.evaluate(job['operators'])
    result = gaproject.run.run(shared.data, operators)

    return result
Example #6
0
def process(job):
    "Launches the given job."

    logging.info('running job {}'.format(job))

    box = Box('data/TSPBenchmark')
    shared.data = box.get(job['data'])

    if 'metaGA' in job:
        shared.settings.metaGA = job['metaGA']

    # TODO: Refactor the following:
    shared.orderedSequenceOfNodes = shared.data.nodesOrderedByMedian(
        shared.data.dist_matrix())

    operators = gaproject.sets.evaluate(job['operators'])
    result = gaproject.run.run(shared.data, operators)

    return result
Example #7
0
import pytest

# Loading data:
from gaproject.data import Box
import gaproject.shared as shared
box = Box('data/TSPBenchmark')
shared.data = box.get('belgiumtour.tsp')

import gaproject.operators.creators as creators
from gaproject.tools.adjacent import fromPathToAdjacent, fromAdjacentToPath


def test_fromPathToAdjacent():
    path_individual = creators.path_creator()
    print path_individual
    adj_individual = fromPathToAdjacent(path_individual)
    print adj_individual


def test_fromAdjacentToPath():
    adj_individual = creators.adj_creator()
    path_individual = fromAdjacentToPath(adj_individual)
    print path_individual


def test_loopConversion():
    'Testing if we get the same result after the two translations:'
    orig = creators.path_creator()
    adj_individual = fromPathToAdjacent(orig)
    new = fromAdjacentToPath(adj_individual)
Example #8
0
    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()
Example #9
0
    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()
Example #10
0
def test_box():
    box = Box('data/TSPBenchmark')
    data = box.get('belgiumtour.tsp')
    assert data is not None
Example #11
0
def belgiumtour_data():
    box = Box('data/TSPBenchmark')
    return box.get('belgiumtour.tsp')
Example #12
0
    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()