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

📄 timetableallocatehoursroomsform.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	s=OUTPUT_DIR+FILE_SEP+s2+"_"+ROOMS_TIMETABLE_1_DAYS_HORIZONTAL_FILENAME_HTML;	writeRoomsTimetable1DaysHorizontalHtml(s);	s=OUTPUT_DIR+FILE_SEP+s2+"_"+ROOMS_TIMETABLE_1_DAYS_VERTICAL_FILENAME_HTML;	writeRoomsTimetable1DaysVerticalHtml(s);	s=OUTPUT_DIR+FILE_SEP+s2+"_"+ROOMS_TIMETABLE_2_FILENAME_HTML;	writeRoomsTimetable2Html(s);	cout<<"Writing simulation results to disk completed successfully"<<endl;}void TimetableAllocateHoursRoomsForm::getTeachersTimetable(TimeSpaceChromosome &c){	assert(gt.timeSpacePopulation.initialized);	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	//assert(c.HFitness()==0); - for perfect solutions	c.getTeachersTimetable(gt.rules, teachers_timetable_week1, teachers_timetable_week2);	teachers_schedule_ready2=true;}void TimetableAllocateHoursRoomsForm::getStudentsTimetable(TimeSpaceChromosome &c){	assert(gt.timeSpacePopulation.initialized);	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	//assert(c.HFitness()==0); - for perfect solutions	c.getSubgroupsTimetable(gt.rules, students_timetable_week1, students_timetable_week2);	students_schedule_ready2=true;}void TimetableAllocateHoursRoomsForm::getRoomsTimetable(TimeSpaceChromosome &c){	assert(gt.timeSpacePopulation.initialized);	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	//assert(c.HFitness()==0); - for perfect solutions	c.getRoomsTimetable(gt.rules, rooms_timetable_week1, rooms_timetable_week2);	best_time_space_chromosome.copy(gt.rules, c);	rooms_schedule_ready2=true;}/**Function writing the students' timetable in xml format to a file*/void TimetableAllocateHoursRoomsForm::writeStudentsTimetableXml(const QString& xmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2);	//Now we print the results to an XML file	QFile file(xmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<"<<protect(STUDENTS_TIMETABLE_TAG)<<">\n";	for(int subgroup=0; subgroup<gt.rules.nInternalSubgroups; subgroup++){		tos<<"\n";		tos<< "  <Subgroup name=\"";		QString subgroup_name = gt.rules.internalSubgroupsList[subgroup]->name;		tos<< protect(subgroup_name) << "\">\n";		for(int k=0; k<gt.rules.nDaysPerWeek; k++){			tos<<"   <Day name=\""<<protect(gt.rules.daysOfTheWeek[k])<<"\">\n";			for(int j=0; j<gt.rules.nHoursPerDay; j++){				tos << "    <Hour name=\"" << protect(gt.rules.hoursOfTheDay[j]) << "\">\n";				tos<<"     <Week1>";				int ai=students_timetable_week1[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<" <Teacher name=\""<<protect(*it)<<"\"></Teacher>";					tos<<"<Subject name=\""<<protect(act->subjectName)<<"\"></Subject>";					tos<<"<Subject_Tag name=\""<<protect(act->subjectTagName)<<"\"></Subject_Tag>";				}				tos<<"</Week1>\n";				tos<<"     <Week2>";				ai=students_timetable_week2[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<" <Teacher name=\""<<protect(*it)<<"\"></Teacher>";					tos<<"<Subject name=\""<<protect(act->subjectName)<<"\"></Subject>";					tos<<"<Subject_Tag name=\""<<protect(act->subjectTagName)<<"\"></Subject_Tag>";				}				tos<<"</Week2>\n";				tos << "    </Hour>\n";			}			tos<<"   </Day>\n";		}		tos<<"  </Subgroup>\n";	}	tos<<"\n";	tos << "</" << STUDENTS_TIMETABLE_TAG << ">\n";	file.close();}/**Function writing the teachers' timetable xml format to a file*/void TimetableAllocateHoursRoomsForm::writeTeachersTimetableXml(const QString& xmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2);	//Writing the timetable in xml format	QFile file(xmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos << "<" << protect(TEACHERS_TIMETABLE_TAG) << ">\n";	for(int i=0; i<gt.rules.nInternalTeachers; i++){		tos<<"\n";		tos << "  <Teacher name=\"" << protect(gt.rules.internalTeachersList[i]->name) << "\">\n";		for(int k=0; k<gt.rules.nDaysPerWeek; k++){			tos << "   <Day name=\"" << protect(gt.rules.daysOfTheWeek[k]) << "\">\n";			for(int j=0; j<gt.rules.nHoursPerDay; j++){				tos << "    <Hour name=\"" << protect(gt.rules.hoursOfTheDay[j]) << "\">\n";				tos<<"     <Week1>";				int ai=teachers_timetable_week1[i][k][j]; //activity index				//Activity* act=gt.rules.activitiesList.at(ai);				if(ai!=UNALLOCATED_ACTIVITY){					Activity* act=&gt.rules.internalActivitiesList[ai];					tos<<"<Subject name=\""<<protect(act->subjectName)<<"\"></Subject>";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << "<Students name=\"" << protect(*it) << "\"></Students>";				}				tos<<"</Week1>\n";				tos<<"     <Week2>";				ai=teachers_timetable_week2[i][k][j]; //activity index				//act=gt.rules.activitiesList.at(ai);				if(ai!=UNALLOCATED_ACTIVITY){					Activity* act=&gt.rules.internalActivitiesList[ai];					tos<<"<Subject name=\""<<protect(act->subjectName)<<"\"></Subject>";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << "<Students name=\"" << protect(*it) << "\"></Students>";				}				tos<<"</Week2>\n";				tos << "    </Hour>\n";			}			tos << "   </Day>\n";		}		tos<<"  </Teacher>\n";	}	tos<<"\n";	tos << "</" << TEACHERS_TIMETABLE_TAG << ">\n";	file.close();}/**Function writing the rooms' timetable in xml format to a file*/void TimetableAllocateHoursRoomsForm::writeRoomsTimetableXml(const QString& xmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2);	assert(rooms_schedule_ready2);	//Writing the timetable in xml format	QFile file(xmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos << "<" << protect(ROOMS_TIMETABLE_TAG) << ">\n";	for(int i=0; i<gt.rules.nInternalRooms; i++){		tos<<"\n";		tos << "  <Room name=\"" << protect(gt.rules.internalRoomsList[i]->name) << "\">\n";		for(int k=0; k<gt.rules.nDaysPerWeek; k++){			tos << "   <Day name=\"" << protect(gt.rules.daysOfTheWeek[k]) << "\">\n";			for(int j=0; j<gt.rules.nHoursPerDay; j++){				tos << "    <Hour name=\"" << protect(gt.rules.hoursOfTheDay[j]) << "\">\n";				tos<<"     <Week1>";				int ai=rooms_timetable_week1[i][k][j]; //activity index				//Activity* act=gt.rules.activitiesList.at(ai);				if(ai!=UNALLOCATED_ACTIVITY){					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << "<Students name=\"" << protect(*it) << "\"></Students>";				}				tos<<"</Week1>\n";				tos<<"     <Week2>";				ai=rooms_timetable_week2[i][k][j]; //activity index				//act=gt.rules.activitiesList.at(ai);				if(ai!=UNALLOCATED_ACTIVITY){					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << "<Students name=\"" << protect(*it) << "\"></Students>";				}				tos<<"</Week2>\n";				tos << "    </Hour>\n";			}			tos << "   </Day>\n";		}		tos<<"  </Room>\n";	}	tos<<"\n";	tos << "</" << ROOMS_TIMETABLE_TAG << ">\n";	file.close();}/**Function writing the students' timetable (with rooms) in html format to a file.Days horizontal.*/void TimetableAllocateHoursRoomsForm::writeStudentsTimetableWithRooms1DaysHorizontalHtml(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2 && rooms_schedule_ready2);	SpaceChromosome* c=(SpaceChromosome*)(&gt.timeSpacePopulation.bestChromosome(gt.rules));	//Now we print the results to an HTML file	QFile file(htmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<html>\n";	tos<<"<title>"<<protect2(gt.rules.institutionName)<<"</title>\n";	tos<<"<body>\n";		tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br>\n";	for(int subgroup=0; subgroup<gt.rules.nInternalSubgroups; subgroup++){		QString subgroup_name = gt.rules.internalSubgroupsList[subgroup]->name;		tos<<"<p align=\"center\">"<<protect2(subgroup_name)<<"</p>\n";				tos<<"<table border=\"1\" cellpadding=\"6\">"<<endl;		tos<<"<tr>\n<td></td>\n";		for(int j=0; j<gt.rules.nDaysPerWeek; j++)			tos<<"<td>"<<protect2(gt.rules.daysOfTheWeek[j])<<"</td>\n";				tos<<"</tr>\n";		for(int j=0; j<gt.rules.nHoursPerDay; j++){			tos<<"<tr>\n";			tos<<"<td>"<<protect2(gt.rules.hoursOfTheDay[j])<<"</td>\n";						for(int k=0; k<gt.rules.nDaysPerWeek; k++){				tos<<"<td style=\"width:14em;\">\n";								int ai=students_timetable_week1[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";										int ri=c->rooms[ai]; //room index					QString roomName;					if(ri==UNALLOCATED_SPACE)						roomName="UNALLOCATED_SPACE";					else						roomName=gt.rules.roomsList.at(ri)->name;					tos<<protect2(roomName)<<"<br/>";				}				else					tos<<"&nbsp;";				ai=students_timetable_week2[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					tos<<"/<br/>";					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";					int ri=c->rooms[ai]; //room index					QString roomName;					if(ri==UNALLOCATED_SPACE)						roomName="UNALLOCATED_SPACE";					else						roomName=gt.rules.roomsList.at(ri)->name;					tos<<protect2(roomName)<<"<br/>";				}				tos<<"</td>\n";			}						tos<<"</tr>\n";		}				tos<<"</table>\n";	}	tos<<"<p/>"<<endl;	time_t ltime;	tzset();	time(&ltime);	tos<<QObject::tr("Timetable generated with FET %1 on %2").arg(FET_VERSION).arg(ctime(&ltime));						tos<<"</body>\n</html>\n";	file.close();}/**Function writing the students' timetable (with rooms) in html format to a file.Days vertical.*/void TimetableAllocateHoursRoomsForm::writeStudentsTimetableWithRooms1DaysVerticalHtml(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2 && rooms_schedule_ready2);	SpaceChromosome* c=(SpaceChromosome*)(&gt.timeSpacePopulation.bestChromosome(gt.rules));	//Now we print the results to an HTML file	QFile file(htmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<html>\n";	tos<<"<title>"<<protect2(gt.rules.institutionName)<<"</title>\n";	tos<<"<body>\n";		tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br>\n";	for(int subgroup=0; subgroup<gt.rules.nInternalSubgroups; subgroup++){		QString subgroup_name = gt.rules.internalSubgroupsList[subgroup]->name;		tos<<"<p align=\"center\">"<<protect2(subgroup_name)<<"</p>\n";				tos<<"<table border=\"1\" cellpadding=\"6\">"<<endl;		tos<<"<tr>\n<td></td>\n";		for(int j=0; j<gt.rules.nHoursPerDay; j++)			tos<<"<td>"<<protect2(gt.rules.hoursOfTheDay[j])<<"</td>\n";				tos<<"</tr>\n";		for(int k=0; k<gt.rules.nDaysPerWeek; k++){			tos<<"<tr>\n";			tos<<"<td>"<<protect2(gt.rules.daysOfTheWeek[k])<<"</td>\n";						for(int j=0; j<gt.rules.nHoursPerDay; j++){				tos<<"<td style=\"width:14em;\">\n";								int ai=students_timetable_week1[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";										int ri=c->rooms[ai]; //room index					QString roomName;					if(ri==UNALLOCATED_SPACE)						roomName="UNALLOCATED_SPACE";					else						roomName=gt.rules.roomsList.at(ri)->name;					tos<<protect2(roomName)<<"<br/>";				}				else					tos<<"&nbsp;";				ai=students_timetable_week2[subgroup][k][j]; //activity index				if(ai!=UNALLOCATED_ACTIVITY){					tos<<"/<br/>";					//Activity* act=gt.rules.activitiesList.at(ai);					Activity* act=&gt.rules.internalActivitiesList[ai];					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";					int ri=c->rooms[ai]; //room index					QString roomName;					if(ri==UNALLOCATED_SPACE)						roomName="UNALLOCATED_SPACE";					else						roomName=gt.rules.roomsList.at(ri)->name;					tos<<protect2(roomName)<<"<br/>";				}				tos<<"</td>\n";			}						tos<<"</tr>\n";		}				tos<<"</table>\n";	}

⌨️ 快捷键说明

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