1e50e1a8e667663c1943aa4355b15b6e29ff87e6
it3708 - bio-inspired artificial intelligence
assignment 1
this project is written in odin and uiua (uiua-plot) with nix for dependency management.
with nix installed, just run
$ nix run
and it will run through the pipeline. it will generate data/image files in output/.
implementation overview
i implement a genetic algorithm to solve the binary knapsack problem.
this is done by
- first generating a population of individuals/chromosomes, modeled as bit_arrays for memory performance.
- then continue for some fixed amount of generations
- calculate the fitness of each chromosome in the population by calculating the distance to the capacity. to avoid negative fitness values, chromosomes that overshoot the capacity are penalized.
- create offspring by
- selecting two parents using a tournament selection
- then performing single point crossover between the parents to create two children
- then mutate each child with random bit-flip mutations.
- create a new population via elitism survivor selection
- repeat
each generation, the fitness value maximum, minimum and mean values are logged in output/data.csv.
this data is read through uiua src/plot.ua to plot the data to output/plot.png.
Description
Languages
Odin
94.1%
Nix
5.9%