<commit_before># Genetic Algorithm to Solve Traveling Salesman Problem

## What is this project?

This project is a reimplementation of an old university of assignment of mine.
My original solution to the problem worked in roughly the same way, but it was
written when I did not know Ruby well at all and was fairly new to programming
in general.  The quality of the code wasn't great (it was in fact pretty
terrible), but since the assigment was interesting, I thought it would be fun
reimplement the project now that I have years of experience with Ruby.

You can find the assignment description at [INSTRUCTIONS.md](INSTRUCTIONS.md).

## What is this project not?

This project is not intended for general use.  I have no problem at all with you
using it to solve whatever problems you have that can be mapped to the traveling
salesman problem, but you will probably get better answers with a different library.
The various parameters of this program (population size, parents per generation,
children produced per generation, mutation length constraints, genetic segment
exchange lengths, etc.) were not chosen with any great degree of care — my work
has gone into the implementation, not parameter tuning.  It is likely further
experimentation with parameter tuning could result in faster convergence.

Performance was not an aim of this project, though of course I tried to avoid
needlessly expensive operations if a more performant alternative was not
significantly less obvious.

## Usage

### Setup

Run `bundle install` from the working directory.  This is only needed if you
intend to run the tests — the library itself uses only Ruby core and stdlib.

### Tests

You can run the test suite with `bin/rake` or `bin/rake spec`.
You can run an individual test file with e.g. `bin/rspec spec/foo_spec.rb`.

### Solving

You can run the algorithm with `bin/solve TSPDATA.txt 1000`, which will run
1000 generations with the city data in TSPDATA.txt.  It will print to stderr
a summary of each generation, where a line like `#45: 558711.57` means that
the best solution found in generation 45 is of length 558711.57.  At the end
of the run, it will print to stdout a list of city names separated by commas<commit_msg>add ruby requirements to readme<commit_after># Genetic Algorithm to Solve Traveling Salesman Problem

## What is this project?

This project is a reimplementation of an old university of assignment of mine.
My original solution to the problem worked in roughly the same way, but it was
written when I did not know Ruby well at all and was fairly new to programming
in general.  The quality of the code wasn't great (it was in fact pretty
terrible), but since the assigment was interesting, I thought it would be fun
reimplement the project now that I have years of experience with Ruby.

You can find the assignment description at [INSTRUCTIONS.md](INSTRUCTIONS.md).

## What is this project not?

This project is not intended for general use.  I have no problem at all with you
using it to solve whatever problems you have that can be mapped to the traveling
salesman problem, but you will probably get better answers with a different library.
The various parameters of this program (population size, parents per generation,
children produced per generation, mutation length constraints, genetic segment
exchange lengths, etc.) were not chosen with any great degree of care — my work
has gone into the implementation, not parameter tuning.  It is likely further
experimentation with parameter tuning could result in faster convergence.

Performance was not an aim of this project, though of course I tried to avoid
needlessly expensive operations if a more performant alternative was not
significantly less obvious.

## Usage

### Requirements

Requires Ruby 2.1+ due the use of required keyword arguments.

### Setup

Run `bundle install` from the working directory.  This is only needed if you
intend to run the tests — the library itself uses only Ruby core and stdlib.

### Tests

You can run the test suite with `bin/rake` or `bin/rake spec`.
You can run an individual test file with e.g. `bin/rspec spec/foo_spec.rb`.

### Solving

You can run the algorithm with `bin/solve TSPDATA.txt 1000`, which will run
1000 generations with the city data in TSPDATA.txt.  It will print to stderr
a summary of each generation, where a line like `#45: 558711.57` means that
the best solution found in generation 45 is of length 558711.57.  At the end
of the run, it will print to stdout a list of city names separated by commas
{'fraction_non_alphanumeric': 0.04094210873871891, 'fraction_numerical': 0.012766894122826326, 'mean_word_length': 4.377514792899408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2576314', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1099, 'n_words': 730}