Search code examples
genetic-algorithmgenetic-programminggenetic

Genetic algorithm(finding expression using digits and operators)


I have the following genetic programming problem(Homework): I need to use 5 digits (0 to 9) and any operators(+,-,*,/) to generate a expression to give me the answer as 30. Can anyone please explain how can I go about solving this using genetic programming?


Solution

  • First,it's a genetic programing(GP) problem.You can google it for more details.

    In GP,each individual represents one computer program,which is represented using a tree structure.In your problem ,it represents a mathematical expression.The tree in follow picture can represent a individual of expression ‘3.4-x’ .

    enter image description here

    The leaf node is chose from your digital set,and non-leaf node from operator set.

    Then,you can choose some crossover and mutation operators to evolve your expression.

    For a crossover operator,you can select one random node in each of the two parents,then swap the corresponding subtrees to create the two offspring as illustrated in next figure.

    enter image description here

    Also,there are many corresponding mutation operators.For example,randomly choose a node to change the digital or operators.