-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (92 loc) · 1.64 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (92 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include<math.h>
using namespace std;
double eval(int *pj);
int main()
{
int vec[100],curr[100],next[100],destvec[100];
unsigned long int i;
double currfit,nextfit;
bool flag = false;
int bit = 100;
unsigned long int fspeed = 0;
unsigned long int fspeedmax = 30;
unsigned long int loop;
//Initialize the starting point to all 0's
for(i = 0; i < 100; i++)
{
vec[i] = 0;
}
for(i = 0; i < 100; i++)
{
destvec[i] = 1;
}
currfit = eval(vec);
if(currfit == 100)
{
for(i = 0; i < 100; i++)
{
cout<<vec[i];
}
return 0;
}
std::copy ( vec, vec+100, curr );
while(!flag)
{
//Loop to move forward depending on the fspeed variable
loop = pow(2.0,fspeed);
for (i=0; i<= loop; i++)
{
//cout<<"loop no"<<i<<endl;
flag = true;
while(flag && bit >=0)
{
if(vec[bit] == 0)
{
vec[bit] = 1;
flag = false;
}
else
{
vec[bit] = 0;
}
bit--;
}
if(flag){
break;
}
bit = 100;
}
std::copy ( vec, vec+100, next );
nextfit = eval(vec);
cout << "fitness = " << nextfit << endl;
if(nextfit == 100)
{
for(i = 0; i < 100; i++)
{
cout<<vec[i];
}
return 0;
}
if(nextfit> currfit)
{
std::copy ( next, next+100, curr );
currfit = nextfit;
fspeedmax>= fspeed ? :fspeed++;
}
if(nextfit == currfit && currfit < 100)
{
std::copy ( next, next+100, curr );
currfit = nextfit;
}
if(nextfit<currfit && currfit < 100 && fspeed >=1)
{
fspeed--;
}
if(nextfit<currfit && currfit < 100 && fspeed ==0)
{
fspeed = 30;
}
std::copy ( curr, curr+100, vec );
}
}