📄 timetableallocateroomsform.cpp
字号:
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 teachers' timetable (with rooms) html format to a file (var. 2)*/void TimetableAllocateRoomsForm::writeTeachersTimetableWithRooms2Html(const QString& htmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.timePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready && rooms_schedule_ready); SpaceChromosome& c=gt.spacePopulation.bestChromosome(gt.rules); //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=>.rules.internalActivitiesList[ai]; for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++) tos<<protect2(*it)<<"<br/>"; int ri=c.rooms[ai]; //room index QString roomName; if(ri==UNALLOCATED_SPACE) roomName="UNALLOCATED_SPACE"; else roomName=protect2(gt.rules.roomsList.at(ri)->name); tos<<roomName<<"<br/>"; } else tos<<" "; 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<<"/<br/>"; for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++) tos << protect2(*it) <<"<br/>"; int ri=c.rooms[ai]; //room index QString roomName; if(ri==UNALLOCATED_SPACE) roomName="UNALLOCATED_SPACE"; else roomName=protect2(gt.rules.roomsList.at(ri)->name); tos<<roomName<<"<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 rooms' timetable in html format to a file.Days horizontal.*/void TimetableAllocateRoomsForm::writeRoomsTimetableDaysHorizontalHtml(const QString& htmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.spacePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready); assert(rooms_schedule_ready); //Writing the timetable in xml 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> </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=>.rules.internalActivitiesList[ai]; for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++) tos << protect2(*it) << "<br/>"; } else tos<<" "; ai=rooms_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->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(<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 rooms' timetable in html format to a file.Days vertical.*/void TimetableAllocateRoomsForm::writeRoomsTimetableDaysVerticalHtml(const QString& htmlfilename){ assert(gt.rules.initialized && gt.rules.internalStructureComputed); assert(gt.spacePopulation.initialized); assert(students_schedule_ready && teachers_schedule_ready); assert(rooms_schedule_ready); //Writing the timetable in xml 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> </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=>.rules.internalActivitiesList[ai]; for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++) tos << protect2(*it) << "<br/>"; } else tos<<" "; ai=rooms_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->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(<ime); tos<<QObject::tr("Timetable generated with FET %1 on %2").arg(FET_VERSION).arg(ctime(<ime)); tos<<"</body>\n</html>\n"; file.close();}void TimetableAllocateRoomsForm::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.spacePopulation.initialized){ QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("You didn't initialize or load the initial state")); return; } if(!(students_schedule_ready && teachers_schedule_ready)){ QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("You didn't allocate the hours prior to allocating the rooms")); return; } spaceSolvingThread.callingForm=this; spaceSolvingThread.start();}void TimetableAllocateRoomsForm::stop(){ mutex.lock(); simulation_stopped=true; mutex.unlock(); QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Simulation completed successfully"));}void TimetableAllocateRoomsForm::pause(){ mutex.lock(); simulation_paused=true; mutex.unlock();}void TimetableAllocateRoomsForm::write(){ if(simulation_running){ mutex.lock(); simulation_write_results=true; mutex.unlock(); } else{ SpaceChromosome &c=gt.spacePopulation.bestChromosome(gt.rules); getRoomsTimetable(c); writeSimulationResults(c); //update the string representing the conflicts spaceConflictsString = ""; spaceConflictsString += "COMPULSORY CONSTRAINTS CONFLICTS (more important):\n"; c.hardFitness(gt.rules, gt.spacePopulation.days, gt.spacePopulation.hours, &spaceConflictsString); spaceConflictsString += "\n--------------------------\n\n"; spaceConflictsString += "NON-COMPULSORY CONSTRAINTS CONFLICTS (less important):\n"; c.softFitness(gt.rules, gt.spacePopulation.days, gt.spacePopulation.hours, &spaceConflictsString); } QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Simulation results should be successfully written. You may check now Timetable/View"));}void TimetableAllocateRoomsForm::savePosition(){ simulation_save_position=true;}void TimetableAllocateRoomsForm::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; } bool prev_state=gt.spacePopulation.initialized; gt.spacePopulation.init(gt.rules, population_number, gt.timePopulation.bestChromosome(gt.rules)); QString s=INPUT_FILENAME_XML.right(INPUT_FILENAME_XML.length()-INPUT_FILENAME_XML.findRev(FILE_SEP)-1); bool existing_file=gt.spacePopulation.read(gt.rules, OUTPUT_DIR+FILE_SEP+s+"_space_population_state.txt"); if(existing_file==false) //for versions older or equal to 3.9.21 existing_file=gt.spacePopulation.read(gt.rules, OUTPUT_DIR+FILE_SEP+"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.spacePopulation.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 TimetableAllocateRoomsForm::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; } assert(gt.rules.internalStructureComputed); assert(students_schedule_ready && teachers_schedule_ready); gt.spacePopulation.init(gt.rules, population_number, gt.timePopulation.bestChromosome(gt.rules)); gt.spacePopulation.makeRoomsUnallocated(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 TimetableAllocateRoomsForm::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; } assert(gt.rules.internalStructureComputed); assert(students_schedule_ready && teachers_schedule_ready); gt.spacePopulation.init(gt.rules, population_number, gt.timePopulation.bestChromosome(gt.rules)); gt.spacePopulation.makeRoomsRandom(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 + -