jeudi 1 août 2013

Idea of ​​genetic algorithm program

On a grid of pixels, we randomly create one or some of living beings represented by colored pixels.


One or some colored pixels representing food, or more generally a source of life is placed. Same for poison, or more generally a source of death.



Each creature has in memory an algorithm that directs its actions, and a memory where it can retain information, say an array of integers or booleans. Every time a creature comes across food, it eats it. Every time it comes across poison, it dies.



Possible actions:

  • Write in a memory box. To enable the use of pointers, it may be advantageous to use the same size for the integers stored in memory as for the memory. Inputted values ​​can be constants, random variables, other variables from memory or external variables.
  • Evaluate an expression containing an operator and one or more variables from memory. The arguments are memory addresses, and another memory address to know where to write the result.
  • Move to one of four directions. (An instruction for each possibility) If you try to move around the edges, either you get stuck, or you are transported to the other side.



In the algorithm, we will have control structures:

  • If, with a variable parameter in memory. If it is true, it goes to the next instruction, otherwise it skips this instruction.
  • Goto parameter with the number of a line of the algorithm. (It is necessary to determine in advance the size of the algorithm.)



Possible operators (we won't use every one of these):

  • Incrementation
  • Decrementation
  • Addition
  • Subtraction
  • Multiplication
  • Integer division
  • Modulo
  • Conjunction
  • Disjunction
  • Negation
  • Test of equality
  • Test of inferiority
  • Test of strict inferiority
  • Test of superiority
  • Test of strict superiority



Possible external variables:

  • Current position (x and y)
  • Position of food
  • Position of the poison
  • Position of congeners


If we only put one food unit and one poison unit, one can simply define their position. If we place more, we will certainly have to set variable names according to a number refering to a particular unit. But in this case the number attributed to a unit can influence the behavior of the creature, which is not very realistic.



We can also limit the available variables. For example, we can make visible only units that are in close range. Btw we can also limit the possible actions. (We already did it when deciding that creatures were moving to adjacent positions, whereas we could have had an instruction to move to absolute coordinates given by two variables from the memory.)



For external variables to be consistent with the memory variables, it may be interesting to define the dimensions of the universe with the same size as the variables.



When a living being breeds, the better for the program to move on is to produce a maximum of offspring. So let's say a new individual on each of the eight adjacent squares is created. All the children mutate.



Possible changes:

  • Adding a new command anywhere in the algorithm
  • Deleting an instruction
  • Modifying an instruction, rather with small changes, for example just change a parameter

Aucun commentaire:

Enregistrer un commentaire