Skip to content

Commit 9726850

Browse files
Merge pull request #80 from Saharsh33/fix/issue-3
fix: validate fields before sending to backend to run algorithm
2 parents e98fccc + 718aba0 commit 9726850

5 files changed

Lines changed: 978 additions & 707 deletions

File tree

CONTRIBUTING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Thank you for your interest in contributing to the **Evolutionary Algorithms on
44

55
Every contribution, no matter how small—from fixing typos to implementing new features—is welcome and valued.
66

7-
***
7+
---
88

99
## 🚀 Getting Started
1010

1111
To ensure a smooth workflow and avoid duplicate effort, please follow these steps before starting any code work.
1212

1313
### 1. Claim a Task
1414

15-
* Check the project's **issue tracker** to find an open bug or feature to work on.
16-
* To get a task officially assigned to you, **you must tag @Ashrockzzz2003 in a comment on the issue** you wish to work on. This is required to receive assignment confirmation.
15+
- Check the project's **issue tracker** to find an open bug or feature to work on.
16+
- To get a task officially assigned to you, **you must tag @Ashrockzzz2003 in a comment on the issue** you wish to work on. This is required to receive assignment confirmation.
1717

1818
### 2. Set Up Your Development Environment
1919

@@ -23,7 +23,7 @@ The complete guidelines for setting up your local environment, building, and run
2323

2424
Please follow these steps to ensure the application runs correctly locally before proceeding with any code changes.
2525

26-
***
26+
---
2727

2828
## 🛠 Submitting Changes (Pull Requests)
2929

@@ -38,17 +38,17 @@ When you are ready to submit your work, please follow the standard Git workflow:
3838

3939
### Commit Message Guidelines
4040

41-
* Use a clear, descriptive title for your commits.
42-
* The first line of the commit message should be a brief summary (under 50 characters).
43-
* **Reference the issue number** the PR is addressing (e.g., `Fix: Button layout on mobile view (#42)`).
41+
- Use a clear, descriptive title for your commits.
42+
- The first line of the commit message should be a brief summary (under 50 characters).
43+
- **Reference the issue number** the PR is addressing (e.g., `Fix: Button layout on mobile view (#42)`).
4444

45-
***
45+
---
4646

4747
## 🛡 Code of Conduct
4848

4949
To ensure a welcoming and friendly community, we expect all contributors to follow our **Code of Conduct** (CoC) in all project spaces. Please read the CoC to understand the behavioral standards and reporting procedures.
5050

51-
***
51+
---
5252

5353
## ❓ Need Help?
5454

app/create/gp/page.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,53 @@ export default function ConfigureGP() {
9999

100100
const router = useRouter();
101101

102+
const validateInput = () => {
103+
if (
104+
![
105+
"eaSimple",
106+
"eaMuPlusLambda",
107+
"eaMuCommaLambda",
108+
"eaGenerateUpdate",
109+
].includes(chosenAlgo)
110+
) {
111+
alert("Invalid algorithm! Choose a supported GP algorithm.");
112+
return false;
113+
}
114+
if (populationSize <= 0) {
115+
alert("Population size must be greater than 0!!");
116+
return false;
117+
}
118+
if (generations <= 0) {
119+
alert("Generations must be greater than 0!!");
120+
return false;
121+
}
122+
if (cxpb < 0 || cxpb > 1) {
123+
alert("Crossover probability must be between 0 and 1!!");
124+
return false;
125+
}
126+
if (mutpb < 0 || mutpb > 1) {
127+
alert("Mutation probability must be between 0 and 1!!");
128+
return false;
129+
}
130+
if (!matingFunc) {
131+
alert("Mating function is required!!");
132+
return false;
133+
}
134+
if (!mutateFunc) {
135+
alert("Mutation function is required!!");
136+
return false;
137+
}
138+
if (!selectionFunction) {
139+
alert("Selection function is required!!");
140+
return false;
141+
}
142+
return true;
143+
};
144+
102145
const runGPAlgorithm = async () => {
146+
if (!validateInput()) {
147+
return;
148+
}
103149
/*
104150
const gpConfig = {
105151
"algorithm": "eaSimple", // DONE
@@ -475,6 +521,7 @@ export default function ConfigureGP() {
475521
<div className="mt-4">
476522
<button
477523
className="bg-foreground text-background p-2 rounded-lg w-full hover:opacity-70 active:opacity-50"
524+
disable={!validateInput()}
478525
onClick={(e) => {
479526
e.preventDefault();
480527
setIsLoading(true);

app/create/non-gp/page.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,46 @@ export default function ConfigureNonGP() {
9595
}
9696
}, [currentStep]);
9797

98+
const validateInput = () => {
99+
if (!chosenAlgo) {
100+
alert("Algorithm is required!!");
101+
return false;
102+
}
103+
if (!indGen) {
104+
alert("Individual generator is required!!");
105+
return false;
106+
}
107+
if (!popFunc) {
108+
alert("Population function is required!!");
109+
return false;
110+
}
111+
if (!matingFunc) {
112+
alert("Mating (crossover) function is required!!");
113+
return false;
114+
}
115+
if (!mutateFunc) {
116+
alert("Mutation function is required!!");
117+
return false;
118+
}
119+
if (!selectFunc) {
120+
alert("Selection function is required!!");
121+
return false;
122+
}
123+
if (!evalFunc) {
124+
alert("Evaluation function is required!!");
125+
return false;
126+
}
127+
if (populationSize <= 0 || generations <= 0) {
128+
alert("Population size and generations must be greater than 0!!");
129+
return false;
130+
}
131+
return true;
132+
};
133+
98134
const runAlgorithm = async () => {
135+
if (!validateInput()) {
136+
return;
137+
}
99138
/*
100139
algorithm: str
101140
individual: str
@@ -447,6 +486,7 @@ export default function ConfigureNonGP() {
447486
<div className="mt-4">
448487
<button
449488
className="bg-foreground text-background p-2 rounded-lg w-full"
489+
disabled={!validateInput()}
450490
onClick={(e) => {
451491
e.preventDefault();
452492
setIsLoading(true);

app/create/pso/page.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,63 @@ export default function ConfigurePSO() {
5858

5959
const router = useRouter();
6060

61+
const validateInput = () => {
62+
if (!["original", "multiswarm", "speciation"].includes(algorithm)) {
63+
alert(
64+
"Invalid PSO algorithm. Choose original, multiswarm, or speciation!!",
65+
);
66+
return false;
67+
}
68+
if (dimensions <= 0) {
69+
alert("Dimensions must be greater than 0!!");
70+
return false;
71+
}
72+
if (minPosition >= maxPosition) {
73+
alert("Min position must be less than max position!!");
74+
return false;
75+
}
76+
if (minSpeed >= maxSpeed) {
77+
alert("Min speed must be less than max speed!!");
78+
return false;
79+
}
80+
if (
81+
![
82+
"rand",
83+
"plane",
84+
"sphere",
85+
"cigar",
86+
"rosenbrock",
87+
"h1",
88+
"ackley",
89+
"bohachevsky",
90+
"griewank",
91+
"rastrigin",
92+
"rastrigin_scaled",
93+
"rastrigin_skew",
94+
"schaffer",
95+
"schwefel",
96+
"himmelblau",
97+
].includes(benchmark)
98+
) {
99+
alert("Invalid benchmark function selected!!");
100+
return false;
101+
}
102+
if (populationSize <= 0) {
103+
alert("Population size must be greater than 0!!");
104+
return false;
105+
}
106+
if (generations <= 0) {
107+
alert("Generations must be greater than 0!!");
108+
return false;
109+
}
110+
return true;
111+
};
112+
61113
const runPSO = async () => {
114+
if (!validateInput()) {
115+
return;
116+
}
117+
62118
const inputData = {
63119
algorithm: algorithm,
64120
dimensions: parseInt(dimensions.toString()),
@@ -266,6 +322,7 @@ export default function ConfigurePSO() {
266322
<div className="mt-4">
267323
<button
268324
className="bg-foreground text-background p-2 rounded-lg w-full hover:opacity-70 active:opacity-50"
325+
disable={!validateInput()}
269326
onClick={(e) => {
270327
e.preventDefault();
271328
setIsLoading(true);

0 commit comments

Comments
 (0)