Currently whenever I try to execute my code I receive a segmentation fault. Debbuging it using GDB I tracked the problem down to the checkConsecutive(), and with some more tests, the set tabooDays.
...insertEarly(...) //What comes previously is not important
set <int> tabooDays;
int day, firstSlot;
for(int i = 0; i < split; i++){
int roomId;
roomToDisc(discId, data, &roomId);
if(this->checkConsecutive(&day, &firstSlot, splitSize[i], 0, 0, 16, tabooDays, this->teacher[teacherId], this->grade[gradeId],this->room[roomId])){
tabooDays.insert(day);
for(int slot = firstSlot; slot < firstSlot + splitSize[i]; slot++){
this->grade[gradeId].schedule[day][slot] = discId+1;
this->teacher[teacherId].schedule[day][slot] = discId+1;
this->room[data->grades[gradeId]->room->id].schedule[day][slot] = discId+1;
this->room[roomId].schedule[day][slot] = discId+1;
this->grade[gradeId].discList.insert(discId);
}
}else{
return 1;
}
}
return 0;
}
bool Solution::checkConsecutive(int *day, int *firstSlot, int size, int dayStart, int slotStart, int slotEnd, set<int> tabooDays, Schedule teacher, Schedule grade, Schedule room){
for(int i = dayStart; i < 6; i++){
for(int j = slotStart; j <= slotEnd-size && !(tabooDays.count(i)) ; j++){
if(grade.checkDisponibility(i, j, j+size) && teacher.checkDisponibility(i, j, j+size) && room.checkDisponibility(i, j, j+size)){
*day = i;
*firstSlot = j;
return true;
}
}
}
for(auto it = tabooDays.begin(); it != tabooDays.end(); it++){
for(int j = slotStart; j <= slotEnd-size; j++){
if(grade.checkDisponibility((*it), j, j+size) && teacher.checkDisponibility((*it), j, j+size) && room.checkDisponibility((*it), j, j+size)){
*day = (*it);
*firstSlot = j;
return true;
}
}
}
return false;
}
GDB Error Message:
Starting program: /home/rafflezs/Documentos/IC University Timetable/exe
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.30-11.fc31.x86_64
Iniciando leitura de dados!
Solução: 1 || Ordered by Teacher
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ef8478 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0x7fffffffcdb0,
__str=<error reading variable: Cannot access memory at address 0x12d1268>)
at /usr/src/debug/gcc-9.3.1-2.fc31.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ext/new_allocator.h:83
83 new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { }
Aucun commentaire:
Enregistrer un commentaire