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

📄 timetableallocatehoursroomsform.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<html>\n";	tos<<"<title>"<<protect2(gt.rules.institutionName)<<"</title>\n";	tos<<"<body>";	tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br/>\n";	for(int i=0; i<gt.rules.nInternalRooms; i++){		tos<<"<p align=\"center\">"<<protect2(gt.rules.internalRoomsList[i]->name)<<"</p>\n";		tos<<"<table border=\"1\" cellpadding=\"6\">\n";		tos<<"<tr>\n<td>&nbsp;</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>";				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 << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<"<br/>";					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos << protect2(*it) << "<br/>";				}				else					tos<<"&nbsp;";				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];					tos<<"/<br/>";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<"<br/>";					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos << protect2(*it) << "<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 rooms' timetable in html format to a file.Days vertical.*/void TimetableAllocateHoursRoomsForm::writeRoomsTimetable1DaysVerticalHtml(const QString& htmlfilename){	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 html format	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>";	tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br/>\n";	for(int i=0; i<gt.rules.nInternalRooms; i++){		tos<<"<p align=\"center\">"<<protect2(gt.rules.internalRoomsList[i]->name)<<"</p>\n";		tos<<"<table border=\"1\" cellpadding=\"6\">\n";		tos<<"<tr>\n<td>&nbsp;</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>";				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 << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<"<br/>";					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos << protect2(*it) << "<br/>";				}				else					tos<<"&nbsp;";				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];					tos<<"/<br/>";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<"<br/>";					for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos << protect2(*it) << "<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 teachers' timetable (with rooms) html format to a file (var. 2)*/void TimetableAllocateHoursRoomsForm::writeRoomsTimetable2Html(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timeSpacePopulation.initialized);	assert(students_schedule_ready2 && teachers_schedule_ready2 && rooms_schedule_ready2);	//Writing the timetable in html format	QFile file(htmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos << "<html>\n<body>\n<table border=\"1\">\n";		tos<<"<tr><td></td>\n";	for(int k=0; k<gt.rules.nDaysPerWeek; k++)		tos << "<td align=\"center\" colspan=\"" << gt.rules.nHoursPerDay <<"\">" << protect2(gt.rules.daysOfTheWeek[k]) << "</td>\n";	tos<<"</tr>\n";	tos<<"<tr>\n";	tos<<"<td></td>\n";	for(int k=0; k<gt.rules.nDaysPerWeek; k++)		for(int j=0; j<gt.rules.nHoursPerDay; j++)			tos << "<td>" << protect2(gt.rules.hoursOfTheDay[j]) << "</td>\n";	for(int i=0; i<gt.rules.nInternalRooms; i++){		tos<<"<tr>\n";		tos << "<td>" << gt.rules.internalRoomsList[i]->name << "</td>\n";		for(int k=0; k<gt.rules.nDaysPerWeek; k++){			for(int j=0; j<gt.rules.nHoursPerDay; j++){				tos<<"<td>";				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<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";										for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<br/>";				}				else					tos<<"&nbsp;";				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<<protect2(*it)<<"<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";										for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)						tos<<protect2(*it)<<"<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();}void TimetableAllocateHoursRoomsForm::start(){	simulation_paused=false;	simulation_stopped=false;	simulation_save_position=false;	if(!gt.rules.initialized || gt.rules.activitiesList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with uninitialized rules or 0 activities...aborting"));		assert(0);		exit(1);		return;	}	//if(!gt.rules.internalStructureComputed){	if(!gt.timeSpacePopulation.initialized){		QMessageBox::information(this, QObject::tr("FET information"), 			QObject::tr("You didn't initialize or load the initial state"));		return;	}	timeSpaceSolvingThread.callingForm=this;	timeSpaceSolvingThread.start();}void TimetableAllocateHoursRoomsForm::stop(){	mutex.lock();	simulation_stopped=true;	mutex.unlock();	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Simulation completed successfully"));}void TimetableAllocateHoursRoomsForm::pause(){	mutex.lock();	simulation_paused=true;	mutex.unlock();}void TimetableAllocateHoursRoomsForm::write(){	if(simulation_running){		mutex.lock();		simulation_write_results=true;		mutex.unlock();	}	else{		TimeSpaceChromosome &c=gt.timeSpacePopulation.bestChromosome(gt.rules);		getTeachersTimetable(c);		getStudentsTimetable(c);		getRoomsTimetable(c);		writeSimulationResults(c);		//update the string representing the conflicts		timeSpaceConflictsString = "";		timeSpaceConflictsString += "COMPULSORY CONSTRAINTS CONFLICTS (more important):\n";		c.hardFitness(gt.rules, &timeSpaceConflictsString);		timeSpaceConflictsString += "\n--------------------------\n\n";		timeSpaceConflictsString += "NON-COMPULSORY CONSTRAINTS CONFLICTS (less important):\n";		c.softFitness(gt.rules, &timeSpaceConflictsString);	}	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Simulation results should be successfully written. You may check now Timetable/View"));}void TimetableAllocateHoursRoomsForm::savePosition(){	simulation_save_position=true;}void TimetableAllocateHoursRoomsForm::loadPosition(){	if(!gt.rules.initialized || gt.rules.activitiesList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with uninitialized rules or 0 activities...aborting"));		assert(0);		exit(1);		return;	}		if(!gt.rules.computeInternalStructure())		return;	bool prev_state=gt.timeSpacePopulation.initialized;	gt.timeSpacePopulation.init(gt.rules, population_number);	QString s=INPUT_FILENAME_XML.right(INPUT_FILENAME_XML.length()-INPUT_FILENAME_XML.findRev(FILE_SEP)-1);	bool existing_file=gt.timeSpacePopulation.read(gt.rules, OUTPUT_DIR+FILE_SEP+s+"_time_space_population_state.txt");	if(existing_file==false){		QMessageBox::warning(this, QObject::tr("FET information"),			QObject::tr("You did not save any internal state yet - aborting operation"));		gt.timeSpacePopulation.initialized=prev_state;		return;	}	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Simulation position restored from hard disk. You may now continue the simulation"));	this->writeResultsPushButton->setEnabled(TRUE);}void TimetableAllocateHoursRoomsForm::initializeUnallocated(){	if(!gt.rules.initialized){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with uninitialized rules...aborting"));		assert(0);		exit(1);		return;	}	if(gt.rules.activitiesList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with 0 activities...aborting"));		assert(0);		exit(1);		return;	}	if(gt.rules.roomsList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with 0 rooms...aborting"));		assert(0);		exit(1);		return;	}	if(!gt.rules.internalStructureComputed)		if(!gt.rules.computeInternalStructure())			return;	gt.timeSpacePopulation.init(gt.rules, population_number);	gt.timeSpacePopulation.makeTimesRoomsUnallocated(gt.rules);	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Initialized with unallocated data - now you can start simulation"));	this->writeResultsPushButton->setEnabled(TRUE);}void TimetableAllocateHoursRoomsForm::initializeRandomly(){	if(!gt.rules.initialized){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with uninitialized rules...aborting"));		assert(0);		exit(1);		return;	}	if(gt.rules.activitiesList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with 0 activities...aborting"));		assert(0);		exit(1);		return;	}	if(gt.rules.roomsList.isEmpty()){		QMessageBox::critical(this, QObject::tr("FET information"),			QObject::tr("You have entered simulation with 0 rooms...aborting"));		assert(0);		exit(1);		return;	}	if(!gt.rules.internalStructureComputed)		if(!gt.rules.computeInternalStructure())			return;	gt.timeSpacePopulation.init(gt.rules, population_number);	gt.timeSpacePopulation.makeTimesRoomsRandom(gt.rules);	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Initialized with random data - now you can start simulation"));	this->writeResultsPushButton->setEnabled(TRUE);}

⌨️ 快捷键说明

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