You are on page 1of 9

i i i iArtifical iIntelligence

i i i i i i iAsignment i#2
Name:
i i i i i i I Abdullah iAbbas
Roll iNo:
i i i i i i i i i17581556-026
Department:
i i i i i i i i i IInformation iTechnology

Submitted iTo:
i i i i i i i i i iMa’am iSamina iNaz

I
Time itable ischeduler iwith igenetic ialgoritm
// iTime-space islots, ione ientry irepresent ione ihour iin ione iclassroom
vector<list<CourseClass*>> i_slots;

// iClass itable ifor ichromosome


// iUsed ito idetermine ifirst itime-space islot iused iby iclass
// iNumber iof icrossover ipoints iof iparent's iclass itables
int i_numberOfCrossoverPoints;

// iNumber iof iclasses ithat iis imoved irandomly iby isingle imutation ioperation
int i_mutationSize;

// iProbability ithat icrossover iwill ioccure


int i_crossoverProbability;

// iProbability ithat imutation iwill ioccure


int i_mutationProbability;
// iPerformes icrossover ioperation iusing ito ichromosomes
// iand ireturns ipointer ito ioffspring
Schedule* iCrossover(const iSchedule& iparent2) iconst;
// iPerforms imutation ion ichromosome
void iMutation();
// iGenetic ialgorithm
class iAlgorithm
private:
i i i i// iPopulation iof ichromosomes
i i i ivector<Schedule*> i_chromosomes;

i i i i// iInidicates iwheahter ichromosome ibelongs ito


i i i i// ibest ichromosome igroup
i i i ivector<bool> i_bestFlags;

i i i i// iIndices iof ibest ichromosomes


i i i ivector<int> i_bestChromosomes;

i i i i// iNumber iof ibest ichromosomes icurrently isaved iin


i i i i// ibest ichromosome igroup
i i i iint i_currentBestSize;

i i i i// iNumber iof ichromosomes iwhich iare ireplaced iin


i i i i// ieach igeneration iby ioffspring
i i i iint i_replaceByGeneration;

i i i i// iPointer ito ialgorithm iobserver


i i i iScheduleObserver* i_observer;

i i i i// iPrototype iof ichromosomes iin ipopulation


i i i iSchedule* i_prototype;

i i i i// iCurrent igeneration


i i i iint i_currentGeneration;
i i i i// iState iof iexecution iof ialgorithm
i i i iAlgorithmState i_state;

i i i i// iSynchronization iof ialgorithm's istate


i i i iCCriticalSection i_stateSect;

i i i i// iPointer ito iglobal iinstance iof ialgorithm


i i i istatic iAlgorithm* i_instance;

i i i i// iSynchronization iof icreation iand idestruction


i i i i// iof iglobal iinstance
i i i istatic iCCriticalSection i_instanceSect;

public:

i i i i// iReturns ireference ito iglobal iinstance iof ialgorithm


i i i istatic iAlgorithm& iGetInstance();

i i i i// iFrees imemory iused iby igloval iinstance


i i i istatic ivoid iFreeInstance();

i i i i// iInitializes igenetic ialgorithm


i i i iAlgorithm(int inumberOfChromosomes,
i i i i i i i iint ireplaceByGeneration,
i i i i i i i iint itrackBest,
i i i i i i i iSchedule* iprototype,
i i i i i i i iScheduleObserver* iobserver);
i i i i// iFrees iused iresources
i i i i~Algorithm();

i i i i// iStarts iand iexecutes ialgorithm


i i i ivoid iStart();

i i i i// iStops iexecution iof ialgoruthm


i i i ivoid iStop();

i i i i// iReturns ipointer ito ibest ichromosomes iin ipopulation


i i i iSchedule* iGetBestChromosome() iconst;

i i i i// iReturns icurrent igeneration


i i i iinline iint iGetCurrentGeneration() iconst i{ ireturn i_currentGeneration; i}

i i i i// iReturns ipointe ito ialgorithm's iobserver


i i i iinline iScheduleObserver* iGetObserver() iconst i{ ireturn i_observer; i}

private:

i i i i// iTries ito iadd ichromosomes iin ibest ichromosome igroup


i i i ivoid iAddToBest(int ichromosomeIndex);

i i i i// iReturns iTRUE iif ichromosome ibelongs ito ibest ichromosome igroup
i i i ibool iIsInBest(int ichromosomeIndex);
i i i i// iClears ibest ichromosome igroup
i i i ivoid iClearBest();

};
// iHandles ievent ithat iis iraised
// iwhen ialgorithm ifinds inew ibest ichromosome
void iNewBestChromosome(const iSchedule& inewChromosome);

// iHandles ievent ithat iis iraised iwhen istate


// iof iexecution iof ialgorithm iis ichanged
void iEvolutionStateChanged(AlgorithmState inewState);

// iBlock icaller's ithread iuntil ialgorithm ifinishes iexecution


inline ivoid iWaitEvent() i//...
#prof
i i i iid i= i1
i i i iname i= iJohn iSmith
#end

#course
i i i iid i= i1
i i i iname i= iIntroduction ito iProgramming
#end

#room
i i i iname i= iR1
i i i ilab i= itrue
i i i isize i= i24
#end

#group
i i i iid i= i1
i i i iname i= i1O1
i i i isize i= i19
#end

#class
i i i iprofessor i= i1
i i i icourse i= i1
i i i iduration i= i2
i i i igroup i= i1
i i i igroup i= i2
#end

#class
i i i iprofessor i= i1
i i i icourse i= i1
i i i iduration i= i3
i i i igroup i= i1
i i i ilab i= itrue
#end

#class
i i i iprofessor i= i1
i i i icourse i= i1
i i i iduration i= i3
i i i igroup i= i2
i i i ilab i= itrue
#end
public:
i i i ivoid iParseFile(char* ifileName);

private:

i i i iProfessor* iParseProfessor(ifstream& ifile);


i i i iStudentsGroup* iParseStudentsGroup(ifstream& ifile);
i i i iCourse* iParseCourse(ifstream& ifile);
i i i iRoom* iParseRoom(ifstream& ifile);
i i i iCourseClass* iParseCourseClass(ifstream& ifile);
Configuration::GetInstance().ParseFile( i"GaSchedule.cfg" i);
private:

i i i ihash_map<int, iProfessor*> i_professors;


i i i ihash_map<int, iStudentsGroup*> i_studentGroups;
i i i ihash_map<int, iCourse*> i_courses;
i i i ihash_map<int, iRoom*> i_rooms;

i i i ilist<CourseClass*> i_courseClasses;
public:
i i i iinline iProfessor* iGetProfessorById(int iid) i//...
i i i iinline iint iGetNumberOfProfessors() iconst i//...
i i i iinline iStudentsGroup* iGetStudentsGroupById(int iid) i//...
i i i iinline iint iGetNumberOfStudentGroups() iconst i//...

i i i iinline iCourse* iGetCourseById(int iid) i//...


i i i iinline iint iGetNumberOfCourses() iconst i//...

i i i iinline iRoom* iGetRoomById(int iid) i//...


i i i iinline iint iGetNumberOfRooms() iconst i//...

i i i iinline iconst ilist<CourseClass*>& iGetCourseClasses() iconst i//...


i i i iinline iint iGetNumberOfCourseClasses() iconst i//...

You might also like