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

📄 spaceconstraint.cpp

📁 ASP.NET 在线项目注册系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}bool ConstraintMinimizeNumberOfRoomsForStudents::isRelatedToStudentsSet(Rules& r, StudentsSet* s){	if(s)		;	if(&r)		;	return true;}bool ConstraintMinimizeNumberOfRoomsForStudents::isRelatedToEquipment(Equipment* e){	if(e)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForStudents::isRelatedToBuilding(Building* b){	if(b)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForStudents::isRelatedToRoom(Room* r){	if(r)		;	return false;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ConstraintMinimizeNumberOfRoomsForTeachers::ConstraintMinimizeNumberOfRoomsForTeachers()	: SpaceConstraint(){	this->type=CONSTRAINT_MINIMIZE_NUMBER_OF_ROOMS_FOR_TEACHERS;}ConstraintMinimizeNumberOfRoomsForTeachers::ConstraintMinimizeNumberOfRoomsForTeachers(double w, bool c)	: SpaceConstraint(w, c){	this->type=CONSTRAINT_MINIMIZE_NUMBER_OF_ROOMS_FOR_TEACHERS;}bool ConstraintMinimizeNumberOfRoomsForTeachers::computeInternalStructure(Rules& r){	if(&r!=NULL)		;	/*do nothing*/		return true;}QString ConstraintMinimizeNumberOfRoomsForTeachers::getXmlDescription(Rules& r){	if(&r!=NULL)		;	QString s = "<ConstraintMinimizeNumberOfRoomsForTeachers>\n";	s += "	<Weight>"+QString::number(this->weight)+"</Weight>\n";	s += "	<Compulsory>";	s += yesNo(this->compulsory);	s += "</Compulsory>\n";	s += "</ConstraintMinimizeNumberOfRoomsForTeachers>\n";	return s;}QString ConstraintMinimizeNumberOfRoomsForTeachers::getDescription(Rules& r){	if(&r!=NULL)		;	QString s=QObject::tr("Minimize number of rooms for teachers");s+=",";	s+=(QObject::tr("W:%1").arg(this->weight));s+=", ";	s+=(QObject::tr("C:%1").arg(yesNoTranslated(this->compulsory)));s+=", ";	return s;}QString ConstraintMinimizeNumberOfRoomsForTeachers::getDetailedDescription(Rules& r){	if(&r!=NULL)		;	QString s=QObject::tr("Space constraint");s+="\n";	s+=QObject::tr("Minimize number of rooms for each teacher");s+="\n";	s+=(QObject::tr("Weight=%1").arg(this->weight));s+="\n";	s+=(QObject::tr("Compulsory=%1").arg(yesNoTranslated(this->compulsory)));s+="\n";	return s;}//critical function here - must be optimized for speedint ConstraintMinimizeNumberOfRoomsForTeachers::fitness(	SpaceChromosome& c,	Rules& r,	const int days[/*MAX_ACTIVITIES*/],	const int hours[/*MAX_ACTIVITIES*/],	QString* conflictsString)	{	//if the matrix roomsMatrix is already calculated, do not calculate it again!	if(crt_chrom!=&c || crt_rules!=&r){		rooms_conflicts = c.getRoomsMatrix(r, days, hours, roomsMatrix);		crt_chrom = &c;		crt_rules = &r;	}	assert(r.internalStructureComputed);	int nbroken=0;		//without logging	if(conflictsString==NULL){		nbroken=0;			for(int i=0; i<r.nInternalTeachers; i++)			for(int j=0; j<r.nInternalRooms; j++)				teachersRooms[i][j]=false;					for(int i=0; i<r.nInternalActivities; i++){			if(c.rooms[i]!=UNALLOCATED_SPACE){				for(int j=0; j<r.internalActivitiesList[i].nTeachers; j++){					int k=r.internalActivitiesList[i].teachers[j];					teachersRooms[k][c.rooms[i]]=true;				}			}			}			int total[MAX_TEACHERS];		for(int i=0; i<r.nInternalTeachers; i++)			total[i]=0;				for(int i=0; i<r.nInternalTeachers; i++)			for(int j=0; j<r.nInternalRooms; j++)				if(teachersRooms[i][j])					total[i]++;						for(int i=0; i<r.nInternalTeachers; i++)			if(total[i]>1)				nbroken+=total[i]-1;	}	//with logging	else{		nbroken=0;			for(int i=0; i<r.nInternalTeachers; i++)			for(int j=0; j<r.nInternalRooms; j++)				teachersRooms[i][j]=false;					for(int i=0; i<r.nInternalActivities; i++){			if(c.rooms[i]!=UNALLOCATED_SPACE){				for(int j=0; j<r.internalActivitiesList[i].nTeachers; j++){					int k=r.internalActivitiesList[i].teachers[j];					teachersRooms[k][c.rooms[i]]=true;				}			}			}			int total[MAX_TEACHERS];		for(int i=0; i<r.nInternalTeachers; i++)			total[i]=0;				for(int i=0; i<r.nInternalTeachers; i++)			for(int j=0; j<r.nInternalRooms; j++)				if(teachersRooms[i][j])					total[i]++;						for(int i=0; i<r.nInternalTeachers; i++)			if(total[i]>1){				nbroken+=total[i]-1;					if(conflictsString!=NULL){					*conflictsString+=						QObject::tr("Space constraint minimize number of rooms for teachers broken for teacher %1, number of rooms=%2")						.arg(r.internalTeachersList[i]->name)						.arg(total[i]);					*conflictsString += ". ";					*conflictsString += (QObject::tr("This increases the conflicts total by %1").arg(weight*(total[i]-1)));					*conflictsString += "\n";				}			}	}	return int (ceil ( weight * nbroken ) );}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToActivity(Activity* a){	if(a)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToTeacher(Teacher* t){	if(t)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToSubject(Subject* s){	if(s)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToSubjectTag(SubjectTag* s){	if(s)		;	return true;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToStudentsSet(Rules& r, StudentsSet* s){	if(s)		;	if(&r)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToEquipment(Equipment* e){	if(e)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToBuilding(Building* b){	if(b)		;	return false;}bool ConstraintMinimizeNumberOfRoomsForTeachers::isRelatedToRoom(Room* r){	if(r)		;	return false;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ConstraintActivityPreferredRoom::ConstraintActivityPreferredRoom()	: SpaceConstraint(){	this->type=CONSTRAINT_ACTIVITY_PREFERRED_ROOM;}ConstraintActivityPreferredRoom::ConstraintActivityPreferredRoom(double w, bool c, int aid, const QString& room)	: SpaceConstraint(w, c){	this->type=CONSTRAINT_ACTIVITY_PREFERRED_ROOM;	this->activityId=aid;	this->roomName=room;}bool ConstraintActivityPreferredRoom::operator==(ConstraintActivityPreferredRoom& c){	if(this->roomName!=c.roomName)		return false;	if(this->activityId!=c.activityId)		return false;	if(this->compulsory!=c.compulsory)		return false;	if(this->weight!=c.weight)		return false;	return true;}bool ConstraintActivityPreferredRoom::computeInternalStructure(Rules& r){	this->_activity=-1;	int ac;	for(ac=0; ac<r.nInternalActivities; ac++)		if(r.internalActivitiesList[ac].id==this->activityId){			assert(this->_activity==-1);			this->_activity=ac;			break;		}	if(ac==r.nInternalActivities)		return false;			this->_room = r.searchRoom(this->roomName);	assert(this->_room>=0);		return true;}QString ConstraintActivityPreferredRoom::getXmlDescription(Rules& r){	if(&r!=NULL)		;	QString s="<ConstraintActivityPreferredRoom>\n";	s+="	<Weight>"+QString::number(weight)+"</Weight>\n";	s+="	<Compulsory>";	s+=yesNo(this->compulsory);	s+="</Compulsory>\n";	s+="	<Activity_Id>"+QString::number(this->activityId)+"</Activity_Id>\n";	s+="	<Room>"+protect(this->roomName)+"</Room>\n";			s+="</ConstraintActivityPreferredRoom>\n";	return s;}QString ConstraintActivityPreferredRoom::getDescription(Rules& r){	if(&r!=NULL)		;	QString s="Activity preferred room"; s+=", ";	s+=QObject::tr("W:%1").arg(this->weight);s+=", ";	s+=QObject::tr("C:%1").arg(yesNoTranslated(this->compulsory));s+=", ";	s+=QObject::tr("A:%1").arg(this->activityId);s+=", ";	s+=QObject::tr("R:%1").arg(this->roomName);	return s;}QString ConstraintActivityPreferredRoom::getDetailedDescription(Rules& r){	if(&r!=NULL)		;	QString s=QObject::tr("Space constraint"); s+="\n";	s+=QObject::tr("Activity preferred room"); s+="\n";	s+=QObject::tr("Weight=%1").arg(this->weight);s+="\n";	s+=QObject::tr("Compulsory=%1").arg(yesNoTranslated(this->compulsory));s+="\n";	s+=QObject::tr("Activity id=%1").arg(this->activityId);s+="\n";	s+=QObject::tr("Room=%1").arg(this->roomName);s+="\n";	return s;}//critical function here - must be optimized for speedint ConstraintActivityPreferredRoom::fitness(	SpaceChromosome& c,	Rules& r,	const int days[/*MAX_ACTIVITIES*/],	const int hours[/*MAX_ACTIVITIES*/],	QString* conflictsString){	//if the matrix roomsMatrix is already calculated, do not calculate it again!	if(crt_chrom!=&c || crt_rules!=&r){		rooms_conflicts = c.getRoomsMatrix(r, days, hours, roomsMatrix);		crt_chrom = &c;		crt_rules = &r;	}	//Calculates the number of conflicts	int nbroken;	//without logging	if(conflictsString==NULL){		nbroken=0;		int parity=r.internalActivitiesList[this->_activity].parity==PARITY_WEEKLY?2:1;		int rm=c.rooms[this->_activity];		if(rm!=UNALLOCATED_SPACE && rm!=this->_room)			nbroken+=parity;	}		//with logging	else{		nbroken=0;		int parity=r.internalActivitiesList[this->_activity].parity==PARITY_WEEKLY?2:1;		int rm=c.rooms[this->_activity];		if(rm!=UNALLOCATED_SPACE && rm!=this->_room){			if(conflictsString!=NULL){				*conflictsString+=					(QObject::tr("Space constraint activity preferred room broken for activity with id=%1, room=%2")					.arg(this->activityId)					.arg(this->roomName));				*conflictsString += ". ";				*conflictsString += (QObject::tr("This increases the conflicts total by %1").arg(weight*parity));				*conflictsString += "\n";			}			nbroken+=parity;		}	}	return int (ceil ( weight * nbroken ) );}bool ConstraintActivityPreferredRoom::isRelatedToActivity(Activity* a){	if(this->activityId==a->id)		return true;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToTeacher(Teacher* t){	if(t)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToSubject(Subject* s){	if(s)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToSubjectTag(SubjectTag* s){	if(s)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToStudentsSet(Rules& r, StudentsSet* s){	if(s)		;	if(&r)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToEquipment(Equipment* e){	if(e)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToBuilding(Building* b){	if(b)		;	return false;}bool ConstraintActivityPreferredRoom::isRelatedToRoom(Room* r){	if(r)		;	return false;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ConstraintActivityPreferredRooms::ConstraintActivityPreferredRooms()	: SpaceConstraint(){	this->type=CONSTRAINT_ACTIVITY_PREFERRED_ROOMS;}ConstraintActivityPreferredRooms::ConstraintActivityPreferredRooms(double w, bool c, int aid, const QStringList& roomsList)	: SpaceConstraint(w, c){	this->type=CONSTRAINT_ACTIVITY_PREFERRED_ROOMS;	this->activityId=aid;	this->roomsNames=roomsList;	assert(roomsList.count()<=(uint)MAX_CONSTRAINT_ACTIVITY_PREFERRED_ROOMS);}bool ConstraintActivityPreferredRooms::computeInternalStructure(Rules& r){	this->_activity=-1;	int ac;	for(ac=0; ac<r.nInternalActivities; ac++)		if(r.internalActivitiesList[ac].id==this->activityId){			assert(this->_activity==-1);			this->_activity=ac;			b

⌨️ 快捷键说明

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