-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.js
46 lines (39 loc) · 1.11 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as R from 'ramda';
import {createPop} from './App/Genetics/population.js';
import {createMap} from './App/Genetics/map.js';
import nextGeneration from './App/Genetics/next-gen.js';
/*
Below, 4 values you can change to test the code
it's only hyper parameters:
- The number of city (maxCities)
- The population size (maxPopulation)
- The max distance calculated (maxDistance): It could be either a Number and Undefined
- the number of iteration
- the width of the map
- the height of the map
*/
const PARAMETERS = {
maxCities: 50,
maxPopulation: 10,
maxDistance: undefined,
maxIterations: 100,
width: 500,
height: 500,
};
const map = createMap(PARAMETERS);
let population = createPop(PARAMETERS);
const changePopulation = () => {
population = nextGeneration(map, PARAMETERS, population);
return population;
};
const repeatNextGeneration = ({maxIterations}) =>
R.times(changePopulation, maxIterations);
const getResults = R.pipe(
R.applySpec({
firstIteration: R.head,
lastIteration: R.last,
}),
R.map(R.head),
);
console.log('All Cities : \n', map);
console.log(getResults(repeatNextGeneration(PARAMETERS)));