#include #include #include #include #include #include using namespace std; struct X { int task, gad, rannum; }; int random(int bb, int tb) { return bb+rand()%(tb-bb); } class Individ { private: X *vector; int criterion, sv; public: Individ(){} // constructor without parametres Individ(int sv_1)// constructor with parametres { sv = sv_1; vector = new X[sv]; for(int i = 0; i < sv; i++) { vector[i].task = 0; vector[i].gad = 0; vector[i].rannum = 0; } } Individ (const Individ& Individ_1) // copy-constructor { sv = Individ_1.sv; vector = new X[sv]; for(int i = 0; i < sv; i++) { vector[i].task = Individ_1.vector[i].task; vector[i].gad = Individ_1.vector[i].gad; vector[i].rannum = Individ_1.vector[i].rannum; } criterion=Individ_1.criterion; } Individ operator = (Individ Individ_1) //overload "=" { sv = Individ_1.sv; vector = new X[sv]; for(int i = 0; i < sv; i++) { vector[i].task = Individ_1.vector[i].task; vector[i].gad = Individ_1.vector[i].gad; vector[i].rannum = Individ_1.vector[i].rannum; } criterion = Individ_1.criterion; return *this; } Individ CrossOver(Individ Individ_1, int sv_1, ofstream& out)// operation of crossover { Individ xxx = Individ_1.sv; int EP; int *vec; static int one = 1; vec = new int [sv_1]; for(int i = 0; i < sv_1; i++) vec[i]=0; srand(time(0)+random(0,sv)); EP = random(1,sv); cout < i; j--) { if( vec[j-1] > vec[j]) { qos = vec[j-1]; vec[j-1] = vec[j]; vec[j] = qos; } } } one=one*2; xxx.criterion = vec[sv_1-1]; return xxx; } Individ Mutation(int sv_1, ofstream& out)// operation of mutation { int mutelem, ranbit, sum=0,a, EP; Individ xxx(*this); int v[8]; int *vec; static int one = 1; vec = new int [sv_1]; for(int i = 0; i < sv_1; i++) vec[i] = 0; for(int i = 0; i < 8; i++) v[i]=0; srand(time(0)+random(1,sv_1)); mutelem = random(1,sv); cout < i;j--) { if(vec[j-1] > vec[j]) { qos = vec[j-1]; vec[j-1] = vec[j]; vec[j] = qos; } } } one = one*2; xxx.criterion = vec[sv_1-1]; return xxx; } void Initialization(int **Ma3x_1, int sv_2, int ran, int sv_1)//create generation { int *vec; vec = new int[sv_1]; for(int i = 0; i < sv_1; i++) vec[i] = 0; sv = sv_2; vector = new X [sv_2]; for(int i = 0; i < sv; i++) vector[i].task = Ma3x_1[i][0]; srand(time(0)+random(0,ran)); for(int i = 0; i < sv; i++) vector[i].rannum = random(0,256); for(int i = 0; i < sv; i++) { for(int j = 1; j <= sv_1; j++) { if(vector[i].rannum <= 257/((double)sv_1/j)) { vector[i].gad = j; j=1; break; } } } for(int i = 0; i < sv; i++) { for(int j = 1; j <= sv_1; j++) { if( vector[i].gad == j) { vec[j-1] = vec[j-1]+vector[i].task; j=1; break; } } } int qos; for(int i = 0; i < sv_1; i++) { for(int j = sv_1-1; j > i; j--) { if(vec[j-1] > vec[j]) { qos = vec[j-1]; vec[j-1] = vec[j]; vec[j] = qos; } } } criterion = vec[sv_1-1]; } int get_Criterion_T() { return criterion; } void ToDisplay(ofstream& out)// show generation & individual { for(int i = 0; i < sv; i++) { cout<>nog; out<<"The number os gadget: "<>nota; out<<"The number os tasks: "<>bb; out<<"The bottom border: "<>tb; out<<"The top border: "<>noi; out <<"Number of Individ: " <>nore; out <<"Number of Repetition: " <= 90) { cout <