Nov 21, 2011 at 3:59am UTC
I need help to solve the following program. :(
#include<iostream>
using namespace std;
struct mc2
{
public:
int seq;
double fitnes;
};
int main(){
mc2 *pros_tim,*chrom,job;
cin>>job;//enter chromosom size
chrom=new mc2[job].seq;
pros_tim=new mc2[job].seq;
cin>>chrom[job].seq;
cin>>pros_tim[job].seq;
int i,pop,rand_index,p;
int*chrom,temp,job;
cout<<"enter population size";
cin>>pop;
cout<<"enter no of jobs";
ofstream outfile("C:\\fuad.OUT");
outfile<<"population size:"<<pop<<endl;
outfile<<"no of jobs:"<<job<<endl;
srand(unsigned (time(0)));
for(i=0;i<job;i++)
{
chrom[i]=i+1;
}
for(i=0;i<job;i++){
cout<<chrom[i]<<"\t";
outfile<<chrom[i]<<"\t";
}
outfile<<endl;
cout<<endl;
for(p=1;p<=pop;p++){
for(i=0;i<job;i++)
{
rand_index=(rand()%(job-1))+1;//swapping operation
temp=chrom[rand_index];
chrom[rand_index]=chrom[i];
chrom[i]=temp;
}
for(i=0;i<job;i++)
{
cout<<chrom[i]<<"\t";
outfile<<chrom[i]<<"\t";
}
outfile<<endl;
cout<<endl;
/*for(i=0;i<job;i++)
{
cout<<chrom[rand_index]<<"\t"<<endl;
}*/
cout<<endl;
}
outfile.close();
return 0;
}
Last edited on Nov 21, 2011 at 4:00am UTC
Nov 21, 2011 at 4:21am UTC
Please post using code tags - it's very difficult to read unformatted code, especially when you haven't told us what it's supposed to do and what the problem is.
Jim