Skip to content

Commit d923699

Browse files
Merge pull request #55 from Evolutionary-Algorithms-On-Click/54-reflect-bug-fixes-in-runner_controller-microservice
Add new crossover methods and update selection logic
2 parents 0188dac + bbd1162 commit d923699

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

app/_data/mate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export const mateData = [
3333
description:
3434
"Executes a messy one-point crossover on the input individuals.",
3535
},
36+
{
37+
name: "cxUniform",
38+
description: "Executes a uniform crossover on the input individuals.",
39+
},
40+
{
41+
name: "cxUniformPartialyMatched",
42+
description:
43+
"Executes a uniform partially matched crossover on the input individuals.",
44+
},
3645
];
3746

3847
export const deMateData = [

app/_data/selection.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ export const selectionData = [
2626
description:
2727
"Select by roulette wheel. The selection probability of an individual is proportional to its fitness.",
2828
},
29-
{
30-
name: "selNSGA2",
31-
description:
32-
"Select the best individual according to the non-dominated sorting of NSGA-II.",
33-
},
34-
{
35-
name: "selSPEA2",
36-
description:
37-
"Select the best individual according to the non-dominated sorting of SPEA2.",
38-
},
29+
// {
30+
// name: "selNSGA2",
31+
// description:
32+
// "Select the best individual according to the non-dominated sorting of NSGA-II.",
33+
// },
34+
// {
35+
// name: "selSPEA2",
36+
// description:
37+
// "Select the best individual according to the non-dominated sorting of SPEA2.",
38+
// },
3939
{
4040
name: "selRandom",
4141
description: "Select randomly.",

app/create/_components/chooseAlgorithm.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export const ChooseAlgo = ({
6262
<h5 className="text-lg font-bold">
6363
Step 1.1: Configure Mu and Lambda
6464
</h5>
65+
<p className="text-sm">
66+
Mu - (Number of individuals to select for the next
67+
generation. Positive Integer)
68+
</p>
69+
<p className="text-sm">
70+
Lambda - (The number of children to produce at each
71+
generation. Positive Integer)
72+
</p>
6573
{chosenAlgo === "eaMuCommaLambda" && !(mu < lambda) && (
6674
<p className="text-blue-500">
6775
Mu should be less than Lambda for eaMuCommaLambda.

app/create/_components/chooseSelectionFunction.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { selectionData } from "@/app/_data/selection";
22

33
export default function ChooseSelectionFunction({
44
title = "Step 8: Choose a selection function.",
5+
selData = selectionData,
56
selectFunc,
67
setSelectFunc,
78
currentStep,
@@ -14,7 +15,7 @@ export default function ChooseSelectionFunction({
1415
<div className="mt-16">
1516
<h4 className="text-lg font-bold mb-4">{title}</h4>
1617
<div className="grid grid-cols-2 gap-4 align-top">
17-
{selectionData.map((sel, index) => (
18+
{selData.map((sel, index) => (
1819
<button
1920
onClick={(e) => {
2021
e.preventDefault();

app/create/non-gp/page.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { deMateData, mateData } from "@/app/_data/mate";
1919
import Link from "next/link";
2020
import { LogOut } from "lucide-react";
2121
import { ConfigureDEParams } from "./_components/chooseDEParams";
22+
import { selectionData } from "@/app/_data/selection";
2223

2324
export default function ConfigureNonGP() {
2425
const [userData, setUserData] = useState({});
@@ -116,6 +117,30 @@ export default function ConfigureNonGP() {
116117
lambda_: Optional[int] = None
117118
hofSize: Optional[int] = 1
118119
*/
120+
121+
if (
122+
![
123+
"cxPartialyMatched",
124+
"cxOrdered",
125+
"cxUniformPartialyMatched",
126+
].includes(matingFunc.name)
127+
) {
128+
// individual size should be greater than max random range and datatype not floating point.
129+
if (indGen === "floatingPoint") {
130+
alert(
131+
`Please select a different type. This is because of the way in which ${matingFunc.name} works.`,
132+
);
133+
return;
134+
}
135+
136+
if (indSize <= parseInt(randomRangeEnd)) {
137+
alert(
138+
`Please select a valid individual size greater than random range. This is because of the way in which ${matingFunc.name} works.`,
139+
);
140+
return;
141+
}
142+
}
143+
119144
const inputData = {
120145
algorithm: chosenAlgo.toString(),
121146
individual: indGen.toString(),
@@ -127,7 +152,7 @@ export default function ConfigureNonGP() {
127152
mutpb: parseFloat(mutpb ?? 0.2),
128153
weights: parameters.map((param) => parseFloat(param)),
129154
individualSize: parseInt(indSize ?? 10),
130-
indpb: 0.05,
155+
indpb: 0.05, // TODO: Get this from the user.
131156
randomRange: [
132157
parseInt(randomRangeStart ?? 0),
133158
parseInt(randomRangeEnd ?? 100),
@@ -327,7 +352,18 @@ export default function ConfigureNonGP() {
327352
{currentStep >= 6 && popFunc && (
328353
<ChooseMatingFunction
329354
mateData={
330-
chosenAlgo === "de" ? deMateData : mateData
355+
chosenAlgo === "de"
356+
? deMateData
357+
: indGen === "floatingPoint"
358+
? mateData.filter(
359+
(mate) =>
360+
![
361+
"cxPartialyMatched",
362+
"cxOrdered",
363+
"cxUniformPartialyMatched",
364+
].includes(mate.name),
365+
)
366+
: mateData
331367
}
332368
mateFunc={matingFunc}
333369
setMateFunc={setMatingFunc}
@@ -354,6 +390,19 @@ export default function ConfigureNonGP() {
354390

355391
{currentStep >= 8 && matingFunc && (
356392
<ChooseSelectionFunction
393+
selData={
394+
chosenAlgo === "eaMuPlusLambda" ||
395+
chosenAlgo === "eaMuCommaLambda"
396+
? selectionData.filter(
397+
(sel) =>
398+
![
399+
"selRoulette",
400+
"selBest",
401+
"selWorst",
402+
].includes(sel.name),
403+
)
404+
: selectionData
405+
}
357406
selectFunc={selectFunc}
358407
setSelectFunc={setSelectFunc}
359408
currentStep={currentStep}

0 commit comments

Comments
 (0)