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

📄 timetableallocatehoursform.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/**Function writing the teachers' timetable html format to a file (var. 1).Days horizontal.*/void TimetableAllocateHoursForm::writeTeachersTimetable1DaysHorizontalHtml(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timePopulation.initialized);	assert(students_schedule_ready && teachers_schedule_ready);	//Writing the timetable in xml format	QFile file(htmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<html>\n<title>"<<protect2(gt.rules.institutionName)<<"</title>\n";	tos<<"<body>\n";	tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br>\n";	for(int i=0; i<gt.rules.nInternalTeachers; i++){		tos<<"<p align=\"center\">"<<protect2(gt.rules.internalTeachersList[i]->name)<<"</p>\n";		tos<<"<table width=\"100%\" border=\"1\" cellpadding=\"6\">\n";		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;\">";				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];					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";				}				else					tos<<"&nbsp;";				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<<"/<br/>\n";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<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 html format to a file (var. 1).Days vertical.*/void TimetableAllocateHoursForm::writeTeachersTimetable1DaysVerticalHtml(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timePopulation.initialized);	assert(students_schedule_ready && teachers_schedule_ready);	//Writing the timetable in xml format	QFile file(htmlfilename);	if(!file.open(IO_WriteOnly))		assert(0);	QTextStream tos(&file);	tos<<"<html>\n<title>"<<protect2(gt.rules.institutionName)<<"</title>\n";	tos<<"<body>\n";	tos<<"<center><h3>"<<protect2(gt.rules.institutionName)<<"</h3></center><br>\n";	for(int i=0; i<gt.rules.nInternalTeachers; i++){		tos<<"<p align=\"center\">"<<protect2(gt.rules.internalTeachersList[i]->name)<<"</p>\n";		tos<<"<table width=\"100%\" border=\"1\" cellpadding=\"6\">\n";		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;\">";				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];					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<br/>";				}				else					tos<<"&nbsp;";				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<<"/<br/>\n";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos << protect2(*it) << "<br/>";					tos<<protect2(act->subjectName)<<" "<<protect2(act->subjectTagName)<<"<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 html format to a file (var. 2)*/void TimetableAllocateHoursForm::writeTeachersTimetable2Html(const QString& htmlfilename){	assert(gt.rules.initialized && gt.rules.internalStructureComputed);	assert(gt.timePopulation.initialized);	assert(students_schedule_ready && teachers_schedule_ready);	//Writing the timetable in xml 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.nInternalTeachers; i++){		tos<<"<tr>\n";		tos << "<td>" << protect2(gt.rules.internalTeachersList[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=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];					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)						tos<<protect2(*it)<<"<br/>";				}				else					tos<<"&nbsp;";				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<<"/<br/>";					for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.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 TimetableAllocateHoursForm::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.timePopulation.initialized){		QMessageBox::warning(this, QObject::tr("FET information"),			QObject::tr("You didn't initialize or load the initial state"));		return;	}	timeSolvingThread.callingForm=this;	timeSolvingThread.start();}void TimetableAllocateHoursForm::stop(){	mutex.lock();	simulation_stopped=true;	mutex.unlock();	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Simulation completed successfully"));}void TimetableAllocateHoursForm::pause(){	mutex.lock();	simulation_paused=true;	mutex.unlock();}void TimetableAllocateHoursForm::write(){	if(simulation_running){		mutex.lock();		simulation_write_results=true;		mutex.unlock();	}	else{		TimeChromosome &c=gt.timePopulation.bestChromosome(gt.rules);		getStudentsTimetable(c);		getTeachersTimetable(c);		writeSimulationResults(c);		//update the string representing the conflicts		timeConflictsString = "";		timeConflictsString += QObject::tr("COMPULSORY CONSTRAINTS CONFLICTS (more important):\n");		c.hardFitness(gt.rules, &timeConflictsString);		timeConflictsString += "\n--------------------------\n\n";		timeConflictsString += QObject::tr("NON-COMPULSORY CONSTRAINTS CONFLICTS (less important):\n");		c.softFitness(gt.rules, &timeConflictsString);	}	QMessageBox::information(this, QObject::tr("FET information"),		QObject::tr("Simulation results should be successfully written. You may check now Timetable/View"));}void TimetableAllocateHoursForm::savePosition(){	simulation_save_position=true;}void TimetableAllocateHoursForm::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.timePopulation.initialized;	gt.timePopulation.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.timePopulation.read(gt.rules, OUTPUT_DIR+FILE_SEP+s+"_time_population_state.txt");	if(existing_file==false) //for versions older or equal with 3.9.21		existing_file=gt.timePopulation.read(gt.rules, OUTPUT_DIR+FILE_SEP+"time_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.timePopulation.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 TimetableAllocateHoursForm::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.internalStructureComputed)		if(!gt.rules.computeInternalStructure())			return;	gt.timePopulation.init(gt.rules, population_number);	gt.timePopulation.makeTimesUnallocated(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 TimetableAllocateHoursForm::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.internalStructureComputed)		if(!gt.rules.computeInternalStructure())			return;	gt.timePopulation.init(gt.rules, population_number);	gt.timePopulation.makeTimesRandom(gt.rules);	QMessageBox::information(this, QObject::tr("FET information"), 		QObject::tr("Initialized with random data - now you can start simulation"));	this->writeResultsPushButton->setEnabled(TRUE);}void TimetableAllocateHoursForm::closePressed(){	this->close();}

⌨️ 快捷键说明

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