Exemplo n.º 1
0
def main():
    # Generate the population
    pop = toolBox.toolbox.population(n=POPULATION_SIZE)

    hof = tools.HallOfFame(1)

    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    pop, log = algorithms.eaSimple(pop,
                                   toolBox.toolbox,
                                   cxpb=CROSS_OVER_PROB,
                                   mutpb=MUTATION_PROB,
                                   ngen=NO_OF_GENERATION,
                                   stats=stats,
                                   halloffame=hof,
                                   verbose=True)

    ## Evaluate the entire population
    #fitnesses = list(map(toolBox.toolbox.evaluate, pop))
    #for ind, fit in zip(pop, fitnesses):

    #    ind.fitness.values = fit

    # Iterate trough a number of generations
    # for g in range(NGEN):
    #    print("-- Generation %i --" % g)
    #    # Select individuals based on their fitness
    #    offspring = toolBox.toolbox.select(pop, len(pop))
    #    # Cloning those individuals into a new population
    #    offspring = list(map(toolBox.toolbox.clone, offspring))

    #    # Calling the crossover function
    #    crossover(offspring)
    #    mutation(offspring)

    #    invalidfitness(offspring)

    # The Best Individual found
    best_ind = tools.selBest(pop, 1)[0]
    individual = sorted(best_ind, key=itemgetter(3))
    individual = sorted(individual, key=itemgetter(0))
    #print "InsertBusTrip and TimeTable......"
    print("Best individual is %s, %s" % (individual, best_ind.fitness.values))
    print("Length of best individual: " + str(len(best_ind)))
    fitnessClass = Fitness()
    timetable = fitnessClass.genTimetable(best_ind)
    databaseClass = DB()
    #databaseClass.insertBusTrip(timetable)
    evaluate_timetable.eval(best_ind)
Exemplo n.º 2
0
Arquivo: main.py Projeto: 4sp1r3/monad
def main():
    # Generate the population
    pop = toolBox.toolbox.population(n=POPULATION_SIZE)

    hof = tools.HallOfFame(1)

    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    pop, log = algorithms.eaSimple(pop, toolBox.toolbox, cxpb=CROSS_OVER_PROB,
                                   mutpb=MUTATION_PROB, ngen=NO_OF_GENERATION, stats=stats,
                                   halloffame=hof, verbose=True)



    ## Evaluate the entire population
    #fitnesses = list(map(toolBox.toolbox.evaluate, pop))
    #for ind, fit in zip(pop, fitnesses):

    #    ind.fitness.values = fit

    # Iterate trough a number of generations
    # for g in range(NGEN):
    #    print("-- Generation %i --" % g)
    #    # Select individuals based on their fitness
    #    offspring = toolBox.toolbox.select(pop, len(pop))
    #    # Cloning those individuals into a new population
    #    offspring = list(map(toolBox.toolbox.clone, offspring))

    #    # Calling the crossover function
    #    crossover(offspring)
    #    mutation(offspring)

    #    invalidfitness(offspring)

    # The Best Individual found
    best_ind = tools.selBest(pop, 1)[0]
    individual = sorted(best_ind, key=itemgetter(3))
    individual = sorted(individual, key=itemgetter(0))
    #print "InsertBusTrip and TimeTable......"
    print("Best individual is %s, %s" % (individual, best_ind.fitness.values))
    print ("Length of best individual: " + str(len(best_ind)))
    fitnessClass = Fitness()
    timetable = fitnessClass.genTimetable(best_ind)
    databaseClass = DB()
    #databaseClass.insertBusTrip(timetable)
    evaluate_timetable.eval(best_ind)
Exemplo n.º 3
0
 def generateBusTrip(self, trip):
     fitness = Fitness()
     db = DB()
     line = 0
     count = 0
     chromosome = []
     for tripInstance in trip:
         for busInstance in tripInstance[3]:
             if line != busInstance["line"] and count != 0:
                 chromosome.append([line, capacity, self.calculateFrequency(count), startTime])
                 count = 0
             if count == 0:
                 capacity = busInstance["capacity"]
                 startTime = busInstance["startTime"]
             line = busInstance["line"]
             count += 1
     chromosome.append([line, capacity, self.calculateFrequency(count), startTime])
     individual = fitness.genTimetable(chromosome)
     db.insertBusTrip2(individual)
Exemplo n.º 4
0
 def generateBusTrip(self, trip):
     fitness = Fitness()
     db = DB()
     line = 0
     count = 0
     chromosome = []
     for tripInstance in trip:
         for busInstance in tripInstance[3]:
             if line != busInstance["line"] and count != 0:
                 chromosome.append([
                     line, capacity,
                     self.calculateFrequency(count), startTime
                 ])
                 count = 0
             if count == 0:
                 capacity = busInstance["capacity"]
                 startTime = busInstance["startTime"]
             line = busInstance["line"]
             count += 1
     chromosome.append(
         [line, capacity,
          self.calculateFrequency(count), startTime])
     individual = fitness.genTimetable(chromosome)
     db.insertBusTrip2(individual)