Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 7c01c56

Browse files
authored
Add files via upload
Update BETA v 0.4
1 parent 260efac commit 7c01c56

File tree

15 files changed

+36
-29
lines changed

15 files changed

+36
-29
lines changed

GeneticalAlgorythm/GeneticalAlgorythm/GeneticalAlgorythm.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,29 @@ vector<bool> GetLineFromMatrix(vector<bool> matrix, int lineSym, int LineNum) {
4444
return temp;
4545
}
4646
//Random Mutation of line
47-
vector<bool> MutationProc(vector<bool> temp) {
48-
int BreakMoment = rand() % 2;
49-
while (true) {
50-
if (BreakMoment == 1) {
51-
break;
52-
}
53-
int RandomElement = rand() % (temp.size()-1);
54-
temp[RandomElement] = rand() % 2 == 1 ? true : false;
55-
BreakMoment = rand() % 2;
56-
}
47+
vector<bool> MutationProc(vector<bool> temp, int Prob) {
48+
//old code
49+
//int BreakMoment = rand() % 2;
50+
//while (true) {
51+
// if (BreakMoment == 1) {
52+
// break;
53+
// }
54+
// int RandomElement = rand() % (temp.size()-1);
55+
// temp[RandomElement] = rand() % 2 == 1 ? true : false;
56+
// BreakMoment = rand() % 2;
57+
//}
58+
//return temp;
59+
60+
for (int i = 0; i < temp.size(); i++) {
61+
int RandPerc = rand() % 101;
62+
if (RandPerc >= Prob) {
63+
temp[i] == true ? temp[i] = false : temp[i] = true;
64+
}
5765
return temp;
5866
}
67+
68+
69+
}
5970
//Fit Status with best matrix-line(11111.. and etc.)
6071
int FitStatus(vector<bool> Line) {
6172
int FitCounter=0;
@@ -70,29 +81,18 @@ int FitStatus(vector<bool> Line) {
7081
int main() {
7182
//VERY IMPORTANT LINE, IT IS NECESSARY FOR THE RAND() FUNCTION TO WORK CORRECTLY.
7283
srand(time(0));
73-
74-
75-
//TestCode, no needed, delete if u want.
76-
//vector<bool> test;
77-
//int LineSym, ColumnSym, LineNum;
78-
//cin >> LineSym >> ColumnSym;
79-
//test = RandomMatrix(LineSym, ColumnSym);
80-
//PrintMatrix(test, LineSym);
81-
//cout << "\n";
82-
//cin >> LineNum;
83-
//PrintMatrix(MutationProc(GetLineFromMatrix(test, LineSym, LineNum)), LineSym);
84-
//End of TestCode
8584

8685
//GeneticalAlgorithm
86+
int MutationProb = 5;
8787
int cycles=0;
8888
int LineSymb = 10;
8989
vector<bool> FirstPop;
9090
FirstPop = RandomMatrix(LineSymb, 4);
91-
cout << "FirstPop:\n";
92-
PrintMatrix(FirstPop, LineSymb);
93-
cout << "\nEnd of FirstPop.\n";
9491

9592
while (true) {
93+
cout << "FirstPop:\n";
94+
PrintMatrix(FirstPop, LineSymb);
95+
cout << "\nEnd of FirstPop.\n";
9696
cycles++;
9797
vector<bool> BestLine1;
9898
vector<bool> BestLine2;
@@ -213,7 +213,7 @@ int main() {
213213
for (int i = 0; i < (LineSymb / 2); i++) {
214214
BestLine2[i] = temp1[i];
215215
}
216-
rand() % 2 == 0 ? BestLine1 = MutationProc(BestLine1) : BestLine2 = MutationProc(BestLine2);
216+
rand() % 2 == 0 ? BestLine1 = MutationProc(BestLine1, MutationProb) : BestLine2 = MutationProc(BestLine2, MutationProb);
217217

218218
cout << "BestLine1 Mutated:\n";
219219
PrintMatrix(BestLine1, LineSymb);
@@ -245,13 +245,14 @@ int main() {
245245
TrueCounter2 = 0;
246246
FirstPop.clear();
247247
FirstPop = RandomMatrix(LineSymb, 2);
248-
for (int i = 0; i < 6; i++) {
248+
for (int i = 0; i < LineSymb; i++) {
249249
FirstPop.push_back(BestLine1[i]);
250250
}
251-
for (int i = 0; i < 6; i++) {
251+
for (int i = 0; i < LineSymb; i++) {
252252
FirstPop.push_back(BestLine2[i]);
253253
}
254-
254+
BestLine1.clear();
255+
BestLine2.clear();
255256
}
256257
return 0;
257258
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0
2+
Debug|x64|C:\Users\admin\Downloads\GeneticAlgorithm-master\GeneticAlgorithm-master\GeneticalAlgorythm\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
 GeneticalAlgorythm.cpp
2+
C:\Users\admin\Downloads\GeneticAlgorithm-master\GeneticAlgorithm-master\GeneticalAlgorythm\GeneticalAlgorythm\GeneticalAlgorythm.cpp(83,12): warning C4244: аргумент: преобразование "time_t" в "unsigned int", возможна потеря данных
3+
C:\Users\admin\Downloads\GeneticAlgorithm-master\GeneticAlgorithm-master\GeneticalAlgorythm\GeneticalAlgorythm\GeneticalAlgorythm.cpp(69): warning C4715: MutationProc: значение возвращается не при всех путях выполнения
4+
GeneticalAlgorythm.vcxproj -> C:\Users\admin\Downloads\GeneticAlgorithm-master\GeneticAlgorithm-master\GeneticalAlgorythm\x64\Debug\GeneticalAlgorythm.exe
Binary file not shown.

0 commit comments

Comments
 (0)