Skip to content
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
40 changes: 20 additions & 20 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Do Not Translate or Localize


--------------------------------------------------------------------------------
@babel/runtime v7.11.0 - Sebastian McKenzie <sebmck@gmail.com>
@babel/runtime v7.11.2 - Sebastian McKenzie <sebmck@gmail.com>
https://github.com/babel/babel.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -312,7 +312,7 @@ SOFTWARE.


--------------------------------------------------------------------------------
@technote-space/ga-framework v0.14.0 - Technote
@technote-space/ga-framework v0.14.6 - Technote
https://github.com/technote-space/ga-framework.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -340,7 +340,7 @@ THE SOFTWARE.


--------------------------------------------------------------------------------
@technote-space/genetic-algorithms-js v0.8.2 - Technote
@technote-space/genetic-algorithms-js v0.8.6 - Technote
https://github.com/technote-space/genetic-algorithms-js.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -368,7 +368,7 @@ THE SOFTWARE.


--------------------------------------------------------------------------------
@technote-space/worker-controller v0.5.2 - Technote
@technote-space/worker-controller v0.5.5 - Technote
https://github.com/technote-space/worker-controller.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -396,7 +396,7 @@ THE SOFTWARE.


--------------------------------------------------------------------------------
axios v0.19.2 - Matt Zabriskie
axios v0.20.0 - Matt Zabriskie
https://github.com/axios/axios.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -537,7 +537,7 @@ THE SOFTWARE.


--------------------------------------------------------------------------------
dom-helpers v5.1.4 - Jason Quense
dom-helpers v5.2.0 - Jason Quense
git+https://github.com/react-bootstrap/dom-helpers.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -624,7 +624,7 @@ OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
fastest-levenshtein v1.0.10 - Kasper U. Weihe
fastest-levenshtein v1.0.12 - Kasper U. Weihe
git+https://github.com/ka-weihe/fastest-levenshtein.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -758,7 +758,7 @@ git+https://github.com/tuxsudo/is-in-browser.git
MIT

--------------------------------------------------------------------------------
jss v10.3.0 - JSS Team
jss v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -784,7 +784,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-camel-case v10.3.0 - JSS Team
jss-plugin-camel-case v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -810,7 +810,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-default-unit v10.3.0 - JSS Team
jss-plugin-default-unit v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -836,7 +836,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-global v10.3.0 - JSS Team
jss-plugin-global v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -862,7 +862,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-nested v10.3.0 - JSS Team
jss-plugin-nested v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -888,7 +888,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-props-sort v10.3.0 - JSS Team
jss-plugin-props-sort v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -914,7 +914,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-rule-value-function v10.3.0 - JSS Team
jss-plugin-rule-value-function v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand All @@ -940,7 +940,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
jss-plugin-vendor-prefixer v10.3.0 - JSS Team
jss-plugin-vendor-prefixer v10.4.0 - JSS Team
https://github.com/cssinjs/jss
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -1020,7 +1020,7 @@ terms above.


--------------------------------------------------------------------------------
moment v2.27.0 - Iskren Ivov Chernev <iskren.chernev@gmail.com> (https://github.com/ichernev)
moment v2.29.0 - Iskren Ivov Chernev <iskren.chernev@gmail.com> (https://github.com/ichernev)
https://github.com/moment/moment.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -1434,7 +1434,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
styled-components v5.1.1 - Glen Maddern
styled-components v5.2.0 - Glen Maddern
git+https://github.com/styled-components/styled-components.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -1468,7 +1468,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------------------------------------------
vis-data v6.6.1
vis-data v7.0.0
https://github.com/visjs/vis-data.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -1651,7 +1651,7 @@ END OF TERMS AND CONDITIONS


--------------------------------------------------------------------------------
vis-network v7.10.2
vis-network v8.3.2
https://github.com/visjs/vis-network.git
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -1834,7 +1834,7 @@ END OF TERMS AND CONDITIONS


--------------------------------------------------------------------------------
webpack v4.44.1 - Tobias Koppers @sokra
webpack v4.44.2 - Tobias Koppers @sokra
https://github.com/webpack/webpack.git
--------------------------------------------------------------------------------

Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/hello-genetic-algorithm",
"version": "0.1.6",
"version": "0.1.7",
"description": "Hello Genetic Algorithm",
"author": {
"name": "Technote",
Expand All @@ -21,8 +21,8 @@
"main": "build/index.js",
"dependencies": {
"@material-ui/core": "^4.11.0",
"@technote-space/ga-framework": "^0.14.4",
"@technote-space/genetic-algorithms-js": "^0.8.4",
"@technote-space/ga-framework": "^0.14.6",
"@technote-space/genetic-algorithms-js": "^0.8.6",
"axios": "^0.20.0",
"encoding-japanese": "^1.0.30",
"fast-levenshtein": "^3.0.0",
Expand All @@ -32,40 +32,40 @@
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"@babel/core": "^7.11.4",
"@babel/core": "^7.11.6",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
"@babel/plugin-transform-react-inline-elements": "^7.10.4",
"@babel/preset-env": "^7.11.0",
"@babel/preset-env": "^7.11.5",
"@babel/preset-flow": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@commitlint/cli": "^9.1.2",
"@commitlint/config-conventional": "^9.1.2",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/encoding-japanese": "^1.0.15",
"@types/fast-levenshtein": "^0.0.1",
"@types/file-saver": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"babel-loader": "^8.1.0",
"babel-plugin-react-html-attrs": "^3.0.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"copy-webpack-plugin": "^6.0.3",
"eslint": "^7.7.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.0",
"file-loader": "^6.0.0",
"html-loader": "^1.2.1",
"html-webpack-plugin": "^4.3.0",
"husky": "^4.2.5",
"copy-webpack-plugin": "^6.1.1",
"eslint": "^7.9.0",
"eslint-plugin-react": "^7.21.1",
"eslint-plugin-react-hooks": "^4.1.2",
"file-loader": "^6.1.0",
"html-loader": "^1.3.1",
"html-webpack-plugin": "^4.5.0",
"husky": "^4.3.0",
"license-checker-webpack-plugin": "^0.1.5",
"lint-staged": "^10.2.11",
"terser-webpack-plugin": "^4.1.0",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"lint-staged": "^10.4.0",
"terser-webpack-plugin": "^4.2.2",
"typescript": "^4.0.3",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^5.1.2",
"webpack-merge": "^5.1.4",
"write-file-webpack-plugin": "^4.5.1"
},
"port": 5000,
Expand Down
5 changes: 3 additions & 2 deletions src/logic/ga/Algorithm/Ga.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GeneticAlgorithmBase} from '@technote-space/ga-framework';
import {GeneticAlgorithmBase} from '@technote-space/ga-framework/dist/app/logic/Algorithm';
import {ITermination, IMigration} from '@technote-space/genetic-algorithms-js';
import {Genotype} from '../Genotype';
import {Phenotype} from '../Phenotype';
import {Termination} from '../Termination';
import {Migration} from '../Migration';
import {UpdateResult, Context} from '../../types';
Expand Down Expand Up @@ -53,7 +54,7 @@ export abstract class Ga extends GeneticAlgorithmBase<UpdateResult> {
population: this.chromosomes.map(chromosome => {
const genotype = chromosome as Genotype;
return {
value: genotype.phenotype.value,
value: Phenotype.getValue(genotype),
fitness: genotype.fitness ?? 0,
};
}),
Expand Down
14 changes: 13 additions & 1 deletion src/logic/ga/Crossovers/Cultural.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import {CrossoverBase, IChromosome} from '@technote-space/genetic-algorithms-js';
import {Genotype} from '../Genotype';

export class Cultural extends CrossoverBase {
private _pool: Array<IChromosome> = [];

public constructor(probability: number) {
super(2, 2, probability);

[...Array(this.childrenNumber)].forEach(() => {
this._pool.push(new Genotype());
});
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected performCross(parents: Array<IChromosome>, _probability: number): Array<IChromosome> {
return parents.flatMap(parent => parent.clone());
let index = 0;
parents.forEach(parent => {
this._pool[index++].copyFrom(parent);
});

return this._pool;
}
}
20 changes: 15 additions & 5 deletions src/logic/ga/Crossovers/Mgg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {CrossoverBase, IChromosome} from '@technote-space/genetic-algorithms-js';
import {Genotype} from '../Genotype';

export class Mgg extends CrossoverBase {
private _pool: Array<IChromosome> = [];

public constructor(probability: number, private readonly mixProbability: number, private readonly crossoverTime: number) {
super(2, crossoverTime * 2, probability);

Expand All @@ -9,15 +12,22 @@ export class Mgg extends CrossoverBase {
this.mixProbability = 1 - mixProbability;
}
this.mixProbability = Math.min(Math.max(this.mixProbability, 0), 0.5);

[...Array(this.childrenNumber)].forEach(() => {
this._pool.push(new Genotype());
});
}

protected performCross(parents: Array<IChromosome>, probability: number): Array<IChromosome> {
const parent1 = parents[0];
const parent2 = parents[1];

return [...Array(this.crossoverTime)].flatMap(() => {
const child1 = parent1.clone();
const child2 = parent2.clone();
let index = 0;
[...Array(this.crossoverTime)].forEach(() => {
const child1 = this._pool[index++];
const child2 = this._pool[index++];
child1.copyFrom(parent1);
child2.copyFrom(parent2);

if (probability > 0 && Math.random() < probability) {
const len = Math.min(parent1.length, parent2.length);
Expand All @@ -30,8 +40,8 @@ export class Mgg extends CrossoverBase {
}
}
}

return [child1, child2];
});

return this._pool;
}
}
8 changes: 4 additions & 4 deletions src/logic/ga/Fitness.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {FitnessBase, IChromosome} from '@technote-space/genetic-algorithms-js';
import levenshtein from 'fast-levenshtein';
import {Genotype} from './Genotype';
import {Phenotype} from './Phenotype';
import {TestData} from './TestData/TestData';

export class Fitness extends FitnessBase {
Expand All @@ -9,10 +10,9 @@ export class Fitness extends FitnessBase {
}

public evaluate(chromosome: IChromosome): void {
const genotype = chromosome as Genotype;
const phenotype = genotype.phenotype;
const genotype = chromosome as Genotype;

const diff = levenshtein.get(this.testData.target, phenotype.value);
phenotype.setFitness(1.0 / (diff + 1));
const diff = levenshtein.get(this.testData.target, Phenotype.getValue(genotype));
genotype.fitness = 1.0 / (diff + 1);
}
}
Loading