#include #include #include #include #include #include #define cout STD_COUT #define cerr STD_CERR #define istream STD_ISTREAM #define ostream STD_OSTREAM #define ifstream STD_IFSTREAM class activitydata { public: int duration; int facduration; int startdate; int minr1; int maxr1; int facr1; int minr2; int maxr2; int facr2; int pred1; int pred2; //int pred3; int delay; int delay1; int priority; int priority1; char predtype1[10]; char predtype2[10]; char predtype3[10]; }; activitydata *act = new activitydata [1000]; activitydata *predone = new activitydata [1000]; activitydata *predtwo = new activitydata [1000]; int resource1,resource2; int minprojectduration; int r1avail[1000],r1profile[1000]; int r2avail[1000],r2profile[1000]; int rprofile [1000]; int i1,highest,i,no_act,highest1 , highpriority; int m,k1,k2,k,j,length; int temp=6; int scheduledact[1000]; int eligibleact[1000]; //declaration of functions // check the availability &shift start void start(); //stores pred activities info void perd(); void input(); class SubhaGenome : public GAGenome { public: GADefineIdentity("SubhaGenome", 201); static void SubhaInitializer(GAGenome&); static int SubhaMutator(GAGenome&, float); static float SubhaComparator(const GAGenome&, const GAGenome&); static int SubhaCrossover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*); public: SubhaGenome(int, GAGenome::Evaluator f=NULL, void* u=NULL); SubhaGenome(const SubhaGenome & orig); SubhaGenome& operator=(const GAGenome& g); virtual ~SubhaGenome(); virtual GAGenome* clone(GAGenome::CloneMethod) const ; virtual void copy(const GAGenome & c); virtual int equal(const GAGenome& g) const; virtual int read(istream & is); virtual int write(ostream & os) const; GA1DArrayGenome & factorstr() const {return *fac;} GAListGenome & priorityy() const {return *pri;} protected: GA1DArrayGenome *fac; GAListGenome*pri; }; void ListInitializer(GAGenome &); void ArrayInitializer(GAGenome &); float Objective(GAGenome & ); //float level1objective(GAGenome &); //float objective1(GAGenome &); int SubhaGenome::write(ostream & os) const { int i,j; for(i=0; ilength(); i++){ os << (fac->gene(i) ) <<"\t"; //os << "\n"; } os << "\n" << *pri->head() << "\t"; for(i=1;inext()<< "\t"; } os << "\n"; return os.fail() ? 1 : 0; } SubhaGenome:: SubhaGenome(int length,GAGenome::Evaluator f, void* u) : GAGenome( SubhaInitializer, SubhaMutator, SubhaComparator) { evaluator(f); userData(u); crossover(SubhaCrossover); fac = new GA1DArrayGenome (length, f, u); pri = new GAListGenome ( f, u); pri->crossover(GAListGenome::PartialMatchCrossover); } SubhaGenome::SubhaGenome(const SubhaGenome & orig) { fac = new GA1DArrayGenome(orig.factorstr()); pri= new GAListGenome(orig.priorityy()); copy(orig); } SubhaGenome& SubhaGenome::operator=(const GAGenome& g) { copy(g); return *this; } SubhaGenome::~SubhaGenome() { delete fac; delete pri; } GAGenome* SubhaGenome::clone(GAGenome::CloneMethod) const { return new SubhaGenome(*this); } void SubhaGenome::copy(const GAGenome & c){ if(&c != this && sameClass(c)){ GAGenome::copy(c); SubhaGenome & bc = (SubhaGenome &)c; fac->copy(*(bc.fac)); pri->copy(*(bc.pri)); } } int SubhaGenome::equal(const GAGenome& g) const { SubhaGenome& genome = (SubhaGenome&)g; return ((*fac == *genome.fac) && (*pri == *genome.pri)); } int SubhaGenome::read(istream & is) { is >> *fac>> *pri; return is.fail() ? 1 : 0; } void SubhaGenome::SubhaInitializer(GAGenome & c) { SubhaGenome & child = (SubhaGenome &)c; child.factorstr().initializer(ArrayInitializer); child.priorityy().initializer(ListInitializer); child.factorstr().initialize(); child.priorityy().initialize(); //cout<sexual(); GAGenome:: SexualCrossover pricross = mom.pri->sexual(); //GAGenome::SexualCrossover pricross (GAGenome::SexualCrossover PartialMatchCrossover); if(c && d){ SubhaGenome& sis = (SubhaGenome&)*c; SubhaGenome& bro = (SubhaGenome&)*d; // sis.priority()::SexualCrossover Crossover (sis.priority::PartialMatchCrossover); // bro.priority().Crossover(GAListGenome::PartialMatchCrossover); (*faccross)(mom.factorstr(), dad.factorstr(), &sis.factorstr(), &bro.factorstr()); (*pricross)(mom.priorityy(),dad.priorityy(), &sis.priorityy(), &bro.priorityy()); sis._evaluated = gaFalse; bro._evaluated = gaFalse; n = 2; } else if(c){ SubhaGenome& sis = (SubhaGenome&)*c; (*faccross)(mom.factorstr(), dad.factorstr(), &sis.factorstr(), 0); (*pricross)(mom.priorityy(), dad.priorityy(), &sis.priorityy(), 0); sis._evaluated = gaFalse; n = 1; } else if(d){ SubhaGenome& bro = (SubhaGenome&)*d; (*faccross)(mom.factorstr(), dad.factorstr(), 0, &bro.factorstr()); (*pricross)(mom.priorityy(), dad.priorityy(), 0, &bro.priorityy()); bro._evaluated = gaFalse; n = 1; } return n; } /*typedef struct _SubhaData { short ** fac; float * pri; } SubhaData;*/ /* ---------------------------------------------------------------------------- List Genome Operators ------------------------------------------------------------------------------- The initializer creates a list with n elements in it and puts a unique digit in each one. After we make the list, we scramble everything up. ---------------------------------------------------------------------------- */ template<> int GAListGenome::write(ostream & os) const { int *cur, *head; GAListIter tmpiter(*this); if((head=tmpiter.head()) != 0) os << *head << " "; for(cur=tmpiter.next(); cur && cur != head; cur=tmpiter.next()) os << *cur << " "; return os.fail() ? 1 : 0; } // force instantiations for compilers that do not do auto instantiation // for some compilers (e.g. metrowerks) this must come after any // specializations or you will get 'multiply-defined errors when you compile. #if !defined(GALIB_USE_AUTO_INST) #include #include GALIB_INSTANTIATION_PREFIX GAList; GALIB_INSTANTIATION_PREFIX GAListGenome; #endif void ListInitializer(GAGenome & c) { GAListGenome &child=(GAListGenome &)c; while(child.head()) child.destroy(); // destroy any pre-existing list int n=11; child.insert(0,GAListBASE::HEAD); // the head node contains a '0' for(int i=1; i &child1=(GA1DArrayGenome &) c1; float low[1000]; float high[1000]; for(int i=0;i<1000;i++) { low[i] =0; high[i] =0; } for(int i=1;i>resource1; cout<<"Give availability of r2"<>resource2; for(m=0;m<1000;m++) { r1avail[m]=resource1; r2avail[m]=resource2; } /*for(int i=0;i & fac = genome.factorstr(); GAListGenome & pri = genome.priorityy(); int i; /* short **pattern = ((SubhaData *)g.userData())->fac; float *sequence = ((SubhaData *)g.userData())->pri;*/ act[0].facr1=act[0].minr1* fac.gene(0) ; act[0].facr2=act[0].minr2* fac.gene(0) ; act[0].facduration=0; act[0].priority=*pri.head(); for(i=1; i