0

Parent 1 chromosome:

"parameters": {
    "{sensor1FMU}.sensor1.lf_position_x": 0.01,
    "{sensor1FMU}.sensor1.lf_position_y": 0.01,
    "{sensor2FMU}.sensor2.lf_position_x": -0.01,
    "{sensor2FMU}.sensor2.lf_position_y": 0.01
}

Parent 2 chromosome:

"parameters": {
    "{sensor1FMU}.sensor1.lf_position_x": 0.03,
    "{sensor1FMU}.sensor1.lf_position_y": 0.01,
    "{sensor2FMU}.sensor2.lf_position_x": -0.05,
    "{sensor2FMU}.sensor2.lf_position_y": 0.07
}

Hi! I'm writing a genetic algorithm in Python to cross the "parameters" in the above separate JSON objects. How would I go about doing this, I'm not sure how to retrieve specific name-value pairs based on the crossover index. Thanks!! :D

  • use the json module. What you presented is not valid json (you need another {} on the outside). – syntonym Jun 22 '16 at 14:55
  • 1
    Possible duplicate of [Parsing values from a JSON file in Python](http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python) – syntonym Jun 22 '16 at 15:13
  • Seems you have real-valued genotypes. Are you sure you want to do just a single-point crossover? That is usually a very bad approach when dealing with real numbers. Much better are crossovers based on random sampling, e.g. BLX-alpha. – zegkljan Jun 23 '16 at 05:33

0 Answers0