MatheusPaixaoG / Pacman-with-GA

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pacman-with-GA 👻

Code from Pacman available at https://pacmancode.com/

Parameters:

weights:

The possible range for random initialization of DNA weights.
    [a,b] -> a,b are positive floats.

crossover:

- prob_of_crossover

Chance of crossover occurring. 
    n -> float between (and including) 0 and 1.

- alpha

Alpha for arithmetic combination crossover. Only used when 2 parents are selected for crossover.
    α -> float between (and including) 0 and 1. Choosing 0 means that only the genes from the second parent will be chosen and 1 the opposite.

- offspring_size

Size of the generated offspring.
    n -> positive int (must be less or equal the population size).

- type

The crossover type.
    "simple": replaces only one gene.
    "normal": randomly selects a gene at the k position, and replaces k+1 until the final gene.
    "complete": replaces the entire DNA.

mutation:

- prob_of_mutation

Chance of mutation occurring. 
    n -> float between (and including) 0 and 1.

population:

- size

Population's size. 
    n -> positive int.

- tournament_to_select

The selected individuals from the population to participate into tournament.
    n -> positive int (must be less than the population size).

- tournament_n_parents

The number of parents selected from the tournament.
    n -> positive int.

- survival

The survival selection type.
    "elitist": merges the offspring with the population and selects only the best.
    "replace": replaces the parents with the offspring.

run:

- iterations

The number of generations to be created. 
    n -> positive int.

- early_stopping_max_iters

Early stopping's maximum number of iterations to check if the score doesn't increase.
    n -> positive int (must be less than the number of generations).

individual:

Recreate and run a individual. For the best individual's DNA, run the code, and get it on the "data" folder inside an study's "best.pacw" file.
    [normal],[power] -> the individual's dna.

How to run

This code uses Python 3.10 or newer.

Install dependencies

We recommend you to create a virtual environment for running the studies. On the local repository's root path:

pip install -r requirements.txt

Study's parameters path

Configure the parameters on: Pacman_Complete/params.json

Running the study

Go to "Pacman_Complete" and run:

python run.py

The PyGame window will appear with the study running and the log will be on the console. Also, an "data" folder containing further study data will appear on the "Pacman_Complete" path with the folder named with the datetime that the study started.

About


Languages

Language:Python 100.0%