📄 timetableallocatehoursform.cpp
字号:
//teachers s=OUTPUT_DIR+FILE_SEP+s2+"_"+TEACHERS_TIMETABLE_1_DAYS_HORIZONTAL_FILENAME_HTML; writeTeachersTimetable1DaysHorizontalHtml(s); s=OUTPUT_DIR+FILE_SEP+s2+"_"+TEACHERS_TIMETABLE_1_DAYS_VERTICAL_FILENAME_HTML; writeTeachersTimetable1DaysVerticalHtml(s); s=OUTPUT_DIR+FILE_SEP+s2+"_"+TEACHERS_TIMETABLE_2_FILENAME_HTML; writeTeachersTimetable2Html(s); cout<<"Writing simulation results to disk completed successfully"<<endl;}void TimetableAllocateHoursForm::getStudentsTimetable(TimeChromosome &c){ assert(gt.timePopulation.initialized); assert(gt.rules.initialized && gt.rules.initialized); //assert(c.HFitness()==0); - for perfect solutions c.getSubgroupsTimetable(gt.rules, students_timetable_week1, students_timetable_week2); best_time_chromosome.copy(gt.rules, c); students_schedule_ready=true;}void TimetableAllocateHoursForm::getTeachersTimetable(TimeChromosome &c){ assert(gt.timePopulation.initialized); assert(gt.rules.initialized && gt.rules.initialized); //assert(c.HFitness()==0); - for perfect solutions c.getTeachersTimetable(gt.rules, teachers_timetable_week1, teachers_timetable_week2); best_time_chromosome.copy(gt.rules, c); teachers_schedule_ready=true;}/**Function writing the students' timetable in xml format to a file*/void TimetableAllocateHoursForm::writeStudentsTimetableXml(const QString& xmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.timePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready); //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=>.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=>.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 << "</" << protect(STUDENTS_TIMETABLE_TAG) << ">\n"; file.close();}/**Function writing the teachers' timetable xml format to a file*/void TimetableAllocateHoursForm::writeTeachersTimetableXml(const QString& xmlfilename){ 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(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=>.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=>.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 << "</" << protect(TEACHERS_TIMETABLE_TAG) << ">\n"; file.close();}/**Function writing the students' timetable in html format to a file.Days horizontal*/void TimetableAllocateHoursForm::writeStudentsTimetable1DaysHorizontalHtml(const QString& htmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.timePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready); //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=>.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/>"; } else tos<<" "; ai=students_timetable_week2[subgroup][k][j]; //activity index if(ai!=UNALLOCATED_ACTIVITY){ tos<<"/<br/>"; //Activity* act=gt.rules.activitiesList.at(ai); Activity* act=>.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/>"; } tos<<"</td>\n"; } tos<<"</tr>\n"; } tos<<"</table>\n"; } tos<<"<p/>"<<endl; time_t ltime; tzset(); time(<ime); tos<<QObject::tr("Timetable generated with FET %1 on %2").arg(FET_VERSION).arg(ctime(<ime)); tos<<"</body>\n</html>\n"; file.close();}/**Function writing the students' timetable in html format to a file.Days vertical*/void TimetableAllocateHoursForm::writeStudentsTimetable1DaysVerticalHtml(const QString& htmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.timePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready); //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=>.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/>"; } else tos<<" "; ai=students_timetable_week2[subgroup][k][j]; //activity index if(ai!=UNALLOCATED_ACTIVITY){ tos<<"/<br/>"; //Activity* act=gt.rules.activitiesList.at(ai); Activity* act=>.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/>"; } tos<<"</td>\n"; } tos<<"</tr>\n"; } tos<<"</table>\n"; } tos<<"<p/>"<<endl; time_t ltime; tzset(); time(<ime); tos<<QObject::tr("Timetable generated with FET %1 on %2").arg(FET_VERSION).arg(ctime(<ime)); tos<<"</body>\n</html>\n"; file.close();}/**Function writing the students' timetable (with rooms) html format to a file (var. 2)*/void TimetableAllocateHoursForm::writeStudentsTimetable2Html(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.nInternalSubgroups; i++){ tos<<"<tr>\n"; tos << "<td>" << gt.rules.internalSubgroupsList[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=students_timetable_week1[i][k][j]; //activity index //Activity* act=gt.rules.activitiesList.at(ai); if(ai!=UNALLOCATED_ACTIVITY){ Activity* act=>.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/>"; } else tos<<" "; ai=students_timetable_week2[i][k][j]; //activity index //act=gt.rules.activitiesList.at(ai); if(ai!=UNALLOCATED_ACTIVITY){ Activity* act=>.rules.internalActivitiesList[ai]; tos<<"/<br/>"; for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.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(<ime); tos<<QObject::tr("Timetable generated with FET %1 on %2").arg(FET_VERSION).arg(ctime(<ime)); tos<<"</body>\n</html>\n"; file.close();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -