Changeset 1191


Ignore:
Timestamp:
12/11/22 16:07:08 (7 weeks ago)
Author:
Maciej Komosinski
Message:

Cosmetic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksEvolution.py

    r1163 r1191  
    6464
    6565
    66 def prepareToolbox(frams_cli, tournament_size, genetic_format, initial_genotype):
     66def prepareToolbox(frams_cli, OPTIMIZATION_CRITERIA, tournament_size, genetic_format, initial_genotype):
    6767        creator.create("FitnessMax", base.Fitness, weights=[1.0] * len(OPTIMIZATION_CRITERIA))
    6868        creator.create("Individual", list, fitness=creator.FitnessMax)  # would be nice to have "str" instead of unnecessary "list of str"
     
    134134
    135135
    136 if __name__ == "__main__":
     136def main():
     137        global parsed_args, OPTIMIZATION_CRITERIA  # needed in frams_evaluate(), so made global to avoid passing as arguments
     138
    137139        # random.seed(123)  # see FramsticksLib.DETERMINISTIC below, set to True if you want full determinism
    138140        FramsticksLib.DETERMINISTIC = False  # must be set before FramsticksLib() constructor call
    139141        parsed_args = parseArguments()
    140142        print("Argument values:", ", ".join(['%s=%s' % (arg, getattr(parsed_args, arg)) for arg in vars(parsed_args)]))
    141 
    142143        OPTIMIZATION_CRITERIA = parsed_args.opt.split(",")
    143144        framsLib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim.split(";"))
    144 
    145         toolbox = prepareToolbox(framsLib, parsed_args.tournament, '1' if parsed_args.genformat is None else parsed_args.genformat, parsed_args.initialgenotype)
    146 
     145        toolbox = prepareToolbox(framsLib, OPTIMIZATION_CRITERIA, parsed_args.tournament, '1' if parsed_args.genformat is None else parsed_args.genformat, parsed_args.initialgenotype)
    147146        pop = toolbox.population(n=parsed_args.popsize)
    148147        hof = tools.HallOfFame(parsed_args.hof_size)
     
    152151        stats.register("min", np.min)
    153152        stats.register("max", np.max)
    154 
    155153        pop, log = algorithms.eaSimple(pop, toolbox, cxpb=parsed_args.pxov, mutpb=parsed_args.pmut, ngen=parsed_args.generations, stats=stats, halloffame=hof, verbose=True)
    156154        print('Best individuals:')
    157155        for ind in hof:
    158156                print(ind.fitness, '\t-->\t', ind[0])
    159 
    160157        if parsed_args.hof_savefile is not None:
    161158                save_genotypes(parsed_args.hof_savefile, OPTIMIZATION_CRITERIA, hof)
     159
     160
     161if __name__ == "__main__":
     162        main()
Note: See TracChangeset for help on using the changeset viewer.