Skip to content

Commit

Permalink
Add tsconfig.dev.json and build command
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Riva committed Mar 28, 2019
1 parent 9936efa commit 5fc49c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions dist/genome.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ define("core/Population", ["require", "exports", "core/Chromosome"], function (r
this.blueprint = blueprint;
this.chromosomes = [];
this.sumFitness = 0;
this.mutationRate = 0.01;
this.initializeChromosomes();
}
Population.prototype.initializeChromosomes = function () {
Expand Down Expand Up @@ -140,10 +141,13 @@ define("core/Population", ["require", "exports", "core/Chromosome"], function (r
}
this.chromosomes = this.chromosomes.concat(newChromosomes);
};
Population.prototype.setMutationRate = function (mutationRate) {
this.mutationRate = mutationRate;
};
Population.prototype.mutateChromosones = function () {
var mutationRate = 0.01;
var _this = this;
this.chromosomes.map(function (chromosome) {
if (Math.random() < mutationRate) {
if (Math.random() < _this.mutationRate) {
chromosome.mutate();
}
});
Expand Down Expand Up @@ -196,6 +200,7 @@ define("example", ["require", "exports", "core/Population", "core/Blueprint"], f
var blueprint = new Blueprint_1.Blueprint();
blueprint.add(26, answer.length);
var population = new Population_1.Population(200, blueprint);
population.setMutationRate(0.01);
population.setFitnessCalculation(function (genes) {
var sum = 1; // Avoid to have 0 on fitness
for (var i = 0; i < genes.length; i += 1) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "dist/genome.min.js",
"scripts": {
"tsc": "tsc",
"dev": "ts-node --transpile-only ./src/example.ts"
"build": "tsc -p tsconfig.json",
"dev": "ts-node -p tsconfig.dev.json --transpile-only ./src/example.ts"
},
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"strict": true
}
}

0 comments on commit 5fc49c2

Please sign in to comment.