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

📄 rules.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			}			else{				ctr=this->spaceConstraintsList.next();			}		}		else			ctr=this->spaceConstraintsList.next();	}	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ){		if(ctr->type==CONSTRAINT_TEACHER_SUBJECT_REQUIRE_ROOM){			ConstraintTeacherSubjectRequireRoom* crt_constraint=(ConstraintTeacherSubjectRequireRoom*)ctr;			if(teacherName == crt_constraint->teacherName){				this->removeSpaceConstraint(ctr); //single constraint removal				ctr=this->spaceConstraintsList.current();			}			else{				ctr=this->spaceConstraintsList.next();			}		}		else			ctr=this->spaceConstraintsList.next();	}	for(Teacher* tch=this->teachersList.first(); tch; tch=this->teachersList.next())		if(tch->name==teacherName)			break;	this->teachersList.remove();	this->internalStructureComputed=false;	return true;}bool Rules::modifyTeacher(const QString& initialTeacherName, const QString& finalTeacherName){	assert(this->searchTeacher(finalTeacherName)==-1);	assert(this->searchTeacher(initialTeacherName)>=0);	//TODO: improve this part	for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())		act->renameTeacher(initialTeacherName, finalTeacherName);	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_TEACHER_NOT_AVAILABLE){			ConstraintTeacherNotAvailable* crt_constraint=(ConstraintTeacherNotAvailable*)ctr;			if(initialTeacherName == crt_constraint->teacherName)				crt_constraint->teacherName=finalTeacherName;		}	}	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_TEACHER_MAX_DAYS_PER_WEEK){			ConstraintTeacherMaxDaysPerWeek* crt_constraint=(ConstraintTeacherMaxDaysPerWeek*)ctr;			if(initialTeacherName == crt_constraint->teacher)				crt_constraint->teacher=finalTeacherName;		}	}		for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(initialTeacherName == crt_constraint->teacherName)				crt_constraint->teacherName=finalTeacherName;		}	}		for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next()){		if(ctr->type==CONSTRAINT_TEACHER_REQUIRES_ROOM){			ConstraintTeacherRequiresRoom* crt_constraint=(ConstraintTeacherRequiresRoom*)ctr;			if(initialTeacherName == crt_constraint->teacherName)				crt_constraint->teacherName=finalTeacherName;		}	}	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next()){		if(ctr->type==CONSTRAINT_TEACHER_SUBJECT_REQUIRE_ROOM){			ConstraintTeacherSubjectRequireRoom* crt_constraint=(ConstraintTeacherSubjectRequireRoom*)ctr;			if(initialTeacherName == crt_constraint->teacherName)				crt_constraint->teacherName=finalTeacherName;		}	}	int t=0;	for(Teacher* tch=this->teachersList.first(); tch; tch=this->teachersList.next())		if(tch->name==initialTeacherName){			tch->name=finalTeacherName;			t++;		}	assert(t<=1);	this->internalStructureComputed=false;	if(t==0)		return false;	else		return true;}void Rules::sortTeachersAlphabetically(){	this->teachersList.sort();	this->internalStructureComputed=false;}bool Rules::addSubject(Subject* subject){	for(Subject* sbj=this->subjectsList.first(); sbj; sbj=this->subjectsList.next())		if(sbj->name==subject->name)			return false;	this->internalStructureComputed=false;	this->subjectsList.append(subject);	return true;}int Rules::searchSubject(const QString& subjectName){	int i;	Subject* subject;	for(subject=this->subjectsList.first(), i=0; subject; subject=this->subjectsList.next())		if(subject->name==subjectName)			return i;	return -1;}bool Rules::removeSubject(const QString& subjectName){	//check the activities first	//TODO: improve this part	for(Activity* act=this->activitiesList.first(); act; ){		if( act->subjectName == subjectName){			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();	}		//delete the time constraints related to this subject	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){		if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(subjectName == crt_constraint->subjectName){				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	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ){		if(ctr->type==CONSTRAINT_ROOM_TYPE_NOT_ALLOWED_SUBJECTS){			ConstraintRoomTypeNotAllowedSubjects* crtas=(ConstraintRoomTypeNotAllowedSubjects*)ctr;			QStringList::Iterator it;			for(it=crtas->subjects.begin(); it!=crtas->subjects.end(); it++)				if(*it==subjectName)					break;			if(it!=crtas->subjects.end()){				int tmp=crtas->removeNotAllowedSubject(subjectName);				assert(tmp==1);			}			//remove the constraint if subjects list empty			if(crtas->subjects.isEmpty()){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_REQUIRES_EQUIPMENTS){			ConstraintSubjectRequiresEquipments* csre=(ConstraintSubjectRequiresEquipments*)ctr;			if(csre->subjectName == subjectName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){			ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;			if(c->subjectName == subjectName){				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->subjectName == subjectName){				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->subjectName == subjectName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOM){			ConstraintSubjectPreferredRoom* c=(ConstraintSubjectPreferredRoom*)ctr;			if(c->subjectName == subjectName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_TEACHER_SUBJECT_REQUIRE_ROOM){			ConstraintTeacherSubjectRequireRoom* c=(ConstraintTeacherSubjectRequireRoom*)ctr;			if(c->subjectName == subjectName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOMS){			ConstraintSubjectPreferredRooms* c=(ConstraintSubjectPreferredRooms*)ctr;			if(c->subjectName == subjectName){				this->removeSpaceConstraint(ctr);				ctr=this->spaceConstraintsList.current();			}			else				ctr=this->spaceConstraintsList.next();		}		else			ctr=this->spaceConstraintsList.next();	}	//remove the subject from the list	for(Subject* sbj=this->subjectsList.first(); sbj; sbj=this->subjectsList.next())		if(sbj->name==subjectName)			break;	this->subjectsList.remove();	this->internalStructureComputed=false;	return true;}bool Rules::modifySubject(const QString& initialSubjectName, const QString& finalSubjectName){	assert(this->searchSubject(finalSubjectName)==-1);	assert(this->searchSubject(initialSubjectName)>=0);	//check the activities first	for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())		if( act->subjectName == initialSubjectName)			act->subjectName=finalSubjectName;		//modify the time constraints related to this subject	for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){		if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){			ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;			if(initialSubjectName == crt_constraint->subjectName)				crt_constraint->subjectName=finalSubjectName;		}	}	//modify the space constraints related to this subject	for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next()){		if(ctr->type==CONSTRAINT_ROOM_TYPE_NOT_ALLOWED_SUBJECTS){			ConstraintRoomTypeNotAllowedSubjects* crtas=(ConstraintRoomTypeNotAllowedSubjects*)ctr;			QStringList::Iterator it;			for(it=crtas->subjects.begin(); it!=crtas->subjects.end(); it++)				if(*it==initialSubjectName){					*it=finalSubjectName;					break;				}		}		else if(ctr->type==CONSTRAINT_SUBJECT_REQUIRES_EQUIPMENTS){			ConstraintSubjectRequiresEquipments* csre=(ConstraintSubjectRequiresEquipments*)ctr;			if(csre->subjectName == initialSubjectName)				csre->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){			ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOM){			ConstraintSubjectSubjectTagPreferredRoom* c=(ConstraintSubjectSubjectTagPreferredRoom*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_PREFERRED_ROOMS){			ConstraintSubjectSubjectTagPreferredRooms* c=(ConstraintSubjectSubjectTagPreferredRooms*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOM){			ConstraintSubjectPreferredRoom* c=(ConstraintSubjectPreferredRoom*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_TEACHER_SUBJECT_REQUIRE_ROOM){			ConstraintTeacherSubjectRequireRoom* c=(ConstraintTeacherSubjectRequireRoom*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}		else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOMS){			ConstraintSubjectPreferredRooms* c=(ConstraintSubjectPreferredRooms*)ctr;			if(c->subjectName == initialSubjectName)				c->subjectName=finalSubjectName;		}	}	//rename the subject in the list	int t=0;	for(Subject* sbj=this->subjectsList.first(); sbj; sbj=this->subjectsList.next())		if(sbj->name==initialSubjectName){			t++;			sbj->name=finalSubjectName;		}	assert(t<=1);	this->internalStructureComputed=false;	return true;}void Rules::sortSubjectsAlphabetically(){	this->subjectsList.sort();	this->internalStructureComputed=false;}bool Rules::addSubjectTag(SubjectTag* subjectTag){	for(SubjectTag* sbt=this->subjectTagsList.first(); sbt; sbt=this->subjectTagsList.next())		if(sbt->name==subjectTag->name)			return false;	this->internalStructureComputed=false;	this->subjectTagsList.append(subjectTag);	return true;}int Rules::searchSubjectTag(const QString& subjectTagName){	int i;	SubjectTag* subjectTag;	for(subjectTag=this->subjectTagsList.first(), i=0; subjectTag; subjectTag=this->subjectTagsList.next(), i++)		if(subjectTag->name==subjectTagName)			return i;	return -1;}bool Rules::removeSubjectTag(const QString& subjectTagName){	//check the activities first	//TODO: improve this part	for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())		if( act->subjectTagName == subjectTagName)			act->subjectTagName="";				//delete the time constraints related to this subject tag

⌨️ 快捷键说明

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