Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nested properties for easier config #34

Merged
merged 2 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const randomExt = require('random-ext');
const rp = require('request-promise');
const { some } = require('bluebird');
const fs = require('fs-extra');
const flat = require('flat');

class Ga {

Expand Down Expand Up @@ -169,7 +170,9 @@ class Ga {
mutate(a, maxAmount) {

let amt = randomExt.integer(maxAmount, 0);
let allProps = Object.keys(a);
// flatten, mutate, return unflattened object
let flattened = flat.flatten(a);
let allProps = Object.keys(flattened);

let tmp = {};

Expand All @@ -191,7 +194,7 @@ class Ga {

}

return tmp;
return flat.unflatten(tmp);
}

// For the given population and fitness, returns new population and max score
Expand Down Expand Up @@ -243,11 +246,8 @@ class Ga {
}

} else {

for (let j = 0; j < this.populationAmt; j++) {

selectionProb[j] = populationProfits[j] / fitnessSum;

}

}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"async": "^2.6.0",
"commander": "^2.11.0",
"flat": "^4.0.0",
"fs-extra": "^4.0.2",
"nodemailer": "^4.4.1",
"random-ext": "^2.6.1",
Expand Down