def get_neighbour(self, state):

        # Select an allele to change
        allele = random.randint(0, 10)

        if self.mode == "RS":
            while allele in [1, 2]:
                allele = random.randint(0, 10)

        if self.mode == "FS":
            while allele in [1, 2, 5, 8]:
                allele = random.randint(0, 10)

        # Random values determining the new value of the allele
        r_1 = random.random()
        r_2 = random.random()

        if r_1 < 0.5:
            delta = ((chromgen.get_bounds(self.mode)[1])[allele] - state[allele]) * r_2
            state[allele] += delta
        else:
            delta = (state[allele] - (chromgen.get_bounds(self.mode)[0])[allele]) * r_2
            state[allele] -= delta

        self.logger.info("Changing allele " + str(allele) + " to " + str(state[allele]))

        return state
def start(pconf):
    global logger
    logger = pconf.get_logger("evolution")

    # logger.info(Currents)
    rand = Random()
    rand.seed(int(time()))

    t = strftime("%d.%m.%Y-%H:%M:%S")

    EC = inspyred.ec.EvolutionaryComputation(rand)
    # EC.analysis = inspyred.ec.analysis.generation_plot
    mode = pconf.get("mode", "Simulation")

    l_bound, u_bound = chromgen.get_bounds(mode)

    # braucht statistics_file und individuals_file für analysis
    EC.observer = inspyred.ec.observers.file_observer

    statistics_file = open(pconf.local_path("inspyred-statistics-{0}.csv".format(strftime("%m%d-%H%M"))), "w")
    individuals_file = open(pconf.local_path("inspyred-individuals-{0}.csv".format(strftime("%m%d-%H%M"))), "w")
    filename = pconf.local_path("inspyred-inspyred-statistics-{0}.csv".format(strftime("%m%d-%H%M")))
    parsed_kwargs = {
        "statistics_file": statistics_file,
        "individuals_file": individuals_file,
        "filename": filename,
        "proj_name": pconf.parse_project_data()["proj_name"],
        "errorbars": False,
        "logger": pconf.get_logger("EC.inspyred"),
        "lower_bound": l_bound,
        "upper_bound": u_bound,
        "pconf": pconf,
        "mode": mode,
    }

    # Parse general evolve parameters.
    for item in pconf.cfg.items("EvolveParameters"):
        parsed_kwargs[item[0]] = eval(item[1])

    # Load selector, variators, replacer and terminators from the config file.
    selector_section = pconf.get("selector", "Simulation")
    logger.debug("Parsing selector: " + selector_section)
    EC.selector, parsed_kwargs = parse_callable(pconf, logger, selector_section, parsed_kwargs)

    variator_section_list = pconf.get_list("variators", "Simulation")
    logger.debug("Parsing variators: " + repr(variator_section_list))
    EC.variator, parsed_kwargs = parse_callable(pconf, logger, variator_section_list, parsed_kwargs)

    replacer_section = pconf.get("replacer", "Simulation")
    logger.debug("Parsing replacer: " + replacer_section)
    EC.replacer, parsed_kwargs = parse_callable(pconf, logger, replacer_section, parsed_kwargs)

    terminator_section_list = pconf.get_list("terminators", "Simulation")
    logger.debug("Parsing terminators: " + repr(terminator_section_list))
    EC.terminator, parsed_kwargs = parse_callable(pconf, logger, terminator_section_list, parsed_kwargs)

    evaluator_section = pconf.get("evaluator", "Simulation")
    logger.debug("Parsing evaluator: " + evaluator_section)
    evaluator, parsed_kwargs = parse_callable(pconf, logger, evaluator_section, parsed_kwargs)

    generator_section = pconf.get("generator", "Simulation")
    logger.debug("Parsing generator: " + generator_section)
    generator, parsed_kwargs = parse_callable(pconf, logger, generator_section, parsed_kwargs)

    logger.debug("Arguments accumulated for evolve: " + repr(parsed_kwargs))
    final_pop = EC.evolve(generator=generator, evaluator=evaluator, **parsed_kwargs)
    final_pop.sort(reverse=True)

    logger.info("=================================")
    logger.info("The best candidate has a fitness value of " + repr(final_pop[0].fitness))
    # schreibt Ergebnisse in Datei zur späteren Auswertung!
    with open(pconf.get_local_path("resultDensityFile"), "a") as d:
        for item in final_pop:
            d.write("# fitness: " + repr(item.fitness) + "\n")
            channels = chromgen.chromosome_to_channels(item.candidate)
            for v in channels:
                d.write(str(v) + "\n")
            d.write("\n")
        d.write("####\n\n")
    logger.info(
        "Die Eigenschaften der letzten Generation"
        + " kann in '"
        + pconf.get("resultDensityFile")
        + "' gefunden werden."
    )