⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rules.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){		if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(subjectTagName == crt_constraint->subjectTagName){				this->removeTimeConstraint(ctr); //single constraint removal				ctr=this->timeConstraintsList.current();			}			else{				ctr=this->timeConstraintsList.next();			}		}		else			ctr=this->timeConstraintsList.next();	}	//delete the space constraints related to this subject tag	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ){		if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){			ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;			if(c->subjectTagName == subjectTagName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOM){			ConstraintSubjectSubjectTagPreferredRoom* c=(ConstraintSubjectSubjectTagPreferredRoom*)ctr;			if(c->subjectTagName == subjectTagName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOMS){			ConstraintSubjectSubjectTagPreferredRooms* c=(ConstraintSubjectSubjectTagPreferredRooms*)ctr;			if(c->subjectTagName == subjectTagName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_TEACHERS_SUBJECT_TAG_MAX_HOURS_CONTINUOUSLY){			ConstraintTeachersSubjectTagMaxHoursContinuously* c=(ConstraintTeachersSubjectTagMaxHoursContinuously*)ctr;			if(c->subjectTagName == subjectTagName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else			ctr=this->spaceConstraintsList.next();	}		//remove the subject tag from the list	for(SubjectTag* sbt=this->subjectTagsList.first(); sbt; sbt=this->subjectTagsList.next())		if(sbt->name==subjectTagName)			break;	this->subjectTagsList.remove();	this->internalStructureComputed=false;	return true;}bool Rules::modifySubjectTag(const QString& initialSubjectTagName, const QString& finalSubjectTagName){	assert(this->searchSubjectTag(finalSubjectTagName)==-1);	assert(this->searchSubjectTag(initialSubjectTagName)>=0);	//check the activities first	for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())		if( act->subjectTagName == initialSubjectTagName)			act->subjectTagName=finalSubjectTagName;		//modify the time constraints related to this subject tag	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(initialSubjectTagName == crt_constraint->subjectTagName)				crt_constraint->subjectTagName=finalSubjectTagName;		}	}	//modify the space constraints related to this subject	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next())		if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){			ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;			if(c->subjectTagName == initialSubjectTagName)				c->subjectTagName=finalSubjectTagName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOM){			ConstraintSubjectSubjectTagPreferredRoom* c=(ConstraintSubjectSubjectTagPreferredRoom*)ctr;			if(c->subjectTagName == initialSubjectTagName)				c->subjectTagName=finalSubjectTagName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOMS){			ConstraintSubjectSubjectTagPreferredRooms* c=(ConstraintSubjectSubjectTagPreferredRooms*)ctr;			if(c->subjectTagName == initialSubjectTagName)				c->subjectTagName=finalSubjectTagName;		}		else if(ctr->type==CONSTRAINT_TEACHERS_SUBJECT_TAG_MAX_HOURS_CONTINUOUSLY){			ConstraintTeachersSubjectTagMaxHoursContinuously* c=(ConstraintTeachersSubjectTagMaxHoursContinuously*)ctr;			if(c->subjectTagName == initialSubjectTagName)				c->subjectTagName=finalSubjectTagName;		}	//rename the subject tag in the list	int t=0;	for(SubjectTag* sbt=this->subjectTagsList.first(); sbt; sbt=this->subjectTagsList.next())		if(sbt->name==initialSubjectTagName){			t++;			sbt->name=finalSubjectTagName;		}	assert(t<=1);	this->internalStructureComputed=false;	return true;}void Rules::sortSubjectTagsAlphabetically(){	this->subjectTagsList.sort();	this->internalStructureComputed=false;}bool Rules::studentsSetsRelated(const QString& studentsSet1, const QString& studentsSet2){	StudentsSet* s1=this->searchStudentsSet(studentsSet1);	StudentsSet* s2=this->searchStudentsSet(studentsSet2);	if(s1->type==STUDENTS_YEAR && s2->type==STUDENTS_YEAR){		StudentsYear* sy1=(StudentsYear*)s1;		StudentsYear* sy2=(StudentsYear*)s2;		if(sy1->name==sy2->name)			return true;		for(StudentsGroup* sg1=sy1->groupsList.first(); sg1; sg1=sy1->groupsList.next()){			for(StudentsGroup* sg2=sy2->groupsList.first(); sg2; sg2=sy2->groupsList.next()){				if(sg1->name==sg2->name)					return true;				for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){					for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){						if(ss1->name==ss2->name)							return true;					}				}									}		}	}	else if(s1->type==STUDENTS_GROUP && s2->type==STUDENTS_YEAR){		StudentsGroup* sg1=(StudentsGroup*)s1;		StudentsYear* sy2=(StudentsYear*)s2;		for(StudentsGroup* sg2=sy2->groupsList.first(); sg2; sg2=sy2->groupsList.next()){			if(sg1->name==sg2->name)				return true;			for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){				for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){					if(ss1->name==ss2->name)						return true;				}			}								}	}	else if(s1->type==STUDENTS_SUBGROUP && s2->type==STUDENTS_YEAR){		StudentsSubgroup* ss1=(StudentsSubgroup*)s1;		StudentsYear* sy2=(StudentsYear*)s2;		for(StudentsGroup* sg2=sy2->groupsList.first(); sg2; sg2=sy2->groupsList.next()){			for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){				if(ss1->name==ss2->name)					return true;			}		}							}	else if(s1->type==STUDENTS_YEAR && s2->type==STUDENTS_GROUP){		StudentsYear* sy1=(StudentsYear*)s1;		StudentsGroup* sg2=(StudentsGroup*)s2;		for(StudentsGroup* sg1=sy1->groupsList.first(); sg1; sg1=sy1->groupsList.next()){			if(sg1->name==sg2->name)				return true;			for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){				for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){					if(ss1->name==ss2->name)						return true;				}			}								}	}	else if(s1->type==STUDENTS_YEAR && s2->type==STUDENTS_SUBGROUP){		StudentsYear* sy1=(StudentsYear*)s1;		StudentsSubgroup* ss2=(StudentsSubgroup*)s2;		for(StudentsGroup* sg1=sy1->groupsList.first(); sg1; sg1=sy1->groupsList.next()){			for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){				if(ss1->name==ss2->name)					return true;			}		}							}	else if(s1->type==STUDENTS_GROUP && s2->type==STUDENTS_GROUP){		StudentsGroup* sg1=(StudentsGroup*)s1;		StudentsGroup* sg2=(StudentsGroup*)s2;		if(sg1->name==sg2->name)			return true;		for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){			for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){				if(ss1->name==ss2->name)					return true;			}		}							}	else if(s1->type==STUDENTS_SUBGROUP && s2->type==STUDENTS_GROUP){		StudentsSubgroup* ss1=(StudentsSubgroup*)s1;		StudentsGroup* sg2=(StudentsGroup*)s2;		for(StudentsSubgroup* ss2=sg2->subgroupsList.first(); ss2; ss2=sg2->subgroupsList.next()){			if(ss1->name==ss2->name)				return true;		}	}							else if(s1->type==STUDENTS_GROUP && s2->type==STUDENTS_SUBGROUP){		StudentsGroup* sg1=(StudentsGroup*)s1;		StudentsSubgroup* ss2=(StudentsSubgroup*)s2;		for(StudentsSubgroup* ss1=sg1->subgroupsList.first(); ss1; ss1=sg1->subgroupsList.next()){			if(ss1->name==ss2->name)				return true;		}	}							else if(s1->type==STUDENTS_SUBGROUP && s2->type==STUDENTS_SUBGROUP){		StudentsSubgroup* ss1=(StudentsSubgroup*)s1;		StudentsSubgroup* ss2=(StudentsSubgroup*)s2;		if(ss1->name==ss2->name)			return true;	}							else 		assert(0);	return false;}StudentsSet* Rules::searchStudentsSet(const QString& setName){	for(StudentsYear* sty=this->yearsList.first(); sty; sty=this->yearsList.next()){		if(sty->name==setName)			return sty;		for(StudentsGroup* stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()){			if(stg->name==setName)				return stg;			for(StudentsSubgroup* sts=stg->subgroupsList.first(); sts; sts=stg->subgroupsList.next())				if(sts->name==setName)					return sts;		}	}	return NULL;}bool Rules::addYear(StudentsYear* year){	//already existing?	if(this->searchStudentsSet(year->name)!=NULL)		return false;	this->yearsList.append(year);	this->internalStructureComputed=false;	return true;}bool Rules::removeYear(const QString& yearName){	//TODO: improve this part	for(Activity* act=this->activitiesList.first(); act; ){		act->removeStudents(yearName);		if(act->studentsNames.count()==0){			this->removeActivity(act->id, act->activityGroupId);			act=this->activitiesList.first(); //!!! please improve this!!!			//(You have to be careful, there can be erased more activities here)		}		else			act=this->activitiesList.next();	}	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){		bool erased=false;		if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){			ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr;			if(yearName == crt_constraint->students){				this->removeTimeConstraint(ctr);				erased=true;			}		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_N_HOURS_DAILY){			ConstraintStudentsSetNHoursDaily* crt_constraint=(ConstraintStudentsSetNHoursDaily*)ctr;			if(yearName == crt_constraint->students){				this->removeTimeConstraint(ctr);				erased=true;			}		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_NO_GAPS){			ConstraintStudentsSetNoGaps* crt_constraint=(ConstraintStudentsSetNoGaps*)ctr;			if(yearName == crt_constraint->students){				this->removeTimeConstraint(ctr);				erased=true;			}		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_INTERVAL_MAX_DAYS_PER_WEEK){			ConstraintStudentsSetIntervalMaxDaysPerWeek* crt_constraint=(ConstraintStudentsSetIntervalMaxDaysPerWeek*)ctr;			if(yearName == crt_constraint->students){				this->removeTimeConstraint(ctr);				erased=true;			}		}		else if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(yearName == crt_constraint->studentsName){				this->removeTimeConstraint(ctr);				erased=true;			}		}		if(!erased)			ctr=this->timeConstraintsList.next();		else			ctr=this->timeConstraintsList.current();	}	StudentsYear* sty;	for(sty=this->yearsList.first(); sty; sty=this->yearsList.next())		if(sty->name==yearName)			break;	assert(sty);	this->yearsList.remove();	this->internalStructureComputed=false;	return true;}int Rules::searchYear(const QString& yearName){	int i;	StudentsYear* sty;	for(sty=this->yearsList.first(), i=0; sty; sty=this->yearsList.next(), i++){		if(sty->name==yearName)			return i;	}	return -1;}bool Rules::modifyYear(const QString& initialYearName, const QString& finalYearName, int finalNumberOfStudents){	assert(searchYear(initialYearName)>=0);	assert(searchStudentsSet(finalYearName)==NULL || initialYearName==finalYearName);	//TODO: improve this part	for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())		act->renameStudents(initialYearName, finalYearName);	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){			ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr;			if(initialYearName == crt_constraint->students)				crt_constraint->students=finalYearName;		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_N_HOURS_DAILY){			ConstraintStudentsSetNHoursDaily* crt_constraint=(ConstraintStudentsSetNHoursDaily*)ctr;			if(initialYearName == crt_constraint->students)				crt_constraint->students=finalYearName;		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_NO_GAPS){			ConstraintStudentsSetNoGaps* crt_constraint=(ConstraintStudentsSetNoGaps*)ctr;			if(initialYearName == crt_constraint->students)				crt_constraint->students=finalYearName;		}		else if(ctr->type==CONSTRAINT_STUDENTS_SET_INTERVAL_MAX_DAYS_PER_WEEK){			ConstraintStudentsSetIntervalMaxDaysPerWeek* crt_constraint=(ConstraintStudentsSetIntervalMaxDaysPerWeek*)ctr;			if(initialYearName == crt_constraint->students)				crt_constraint->students=finalYearName;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -