# Added ant colony optimization algorithm for traveling salesman problem #3914

Open
wants to merge 1 commit into
from

## Conversation

Projects
None yet
2 participants

### Jimmyzs commented Dec 9, 2018

 Fixes issue: Issue #3631 Changes: Adds Ant Colony Optimization algorithm for Traveling Salesman Problem
``` Added ant colony optimization algorithm for traveling salesman problem ```
``` cb6d745 ```

### arnavb suggested changes Jan 10, 2019

 #include #include using namespace std;

#### arnavb Jan 10, 2019

Member

Don't use this.

 using namespace std; const double g_rho = 0.6; // Evaporation constant

#### arnavb Jan 10, 2019

Member

Make these `constexpr`.

 double doubleRand() { // Generate random double within the interval [0.0, 1.0) return double(rand()) / (double(RAND_MAX) + 1.0);

#### arnavb Jan 10, 2019

Member

Is it possible that you could instead use something from the `random` header instead, which is more modern.

 int chooseNextNode (int ant, int startOfTour, int N, vector> &distance, vector> &pheromone, vector> &parents) { // Choose the next vertex for "ant" to go double denominator = 0, prob, interval = 0;

#### arnavb Jan 10, 2019

Member

 } } } else

#### arnavb Jan 10, 2019

Member

No need for the else.

 { double t = 0; for (int k = 0; k < N; k++) if ((parents[k][i]==j) || (parents[k][j]==i) ) // kth ant uses edge (i,j)

#### arnavb Jan 10, 2019

Member

Spaces around all operators.

 double calculateDeltaPheromone (int i, int j, int N, vector> &parents, vector &len) { double t = 0; for (int k = 0; k < N; k++)

Member