Omnet ++ Исключение cRuntimeError собирается быть брошенным std :: length_error: basic_string :: _ M_create

так что я получаю эту ошибку, когда я запускаю свой код

Ошибка в модуле (TraCIDemoRSU11p) RSUExampleScenario.rsu [0] .appl (id = 8) в событии # 4000, t = 45.40151998544: std :: length_error: basic_string :: _ M_create.
TRAPPING для исключения выше, из-за опции конфигурации debug-on-errors = true. Ваш отладчик готов?

это показывает, что у меня есть эта проблема в этой строке после многократного цикла

 VehTD = *iteh2;

Сообщите, что я пытаюсь удалить из этого списка транспортных средств другой список транспортных средств и удалить перемещенные элементы.

 std::list<std::pair<std::string,std::string>>::const_iterator iteh2 = waitingList.begin();
for (std::list<std::pair<std::string,std::string>>::const_iterator iteh = waitingList.begin(); iteh != waitingList.end() && !waitingList.empty(); ){
iteh2 = iteh;
cout<<"Veh ID TF 1:";
cout<<VehTD.first<<endl;
cout<<VehTD.second<<endl;
VehTD = *iteh2;
cout<<"Veh ID TF 2:";
cout<<VehTD.first<<endl;
cout<<VehTD.second<<endl;
CompareResult3 = Locks(Locked,VehTD.second);
if(CompareResult3.second == 1 || CompareResult3.second == 2 ){
//remove from waiting and add to crossing
std::string ehk = "";
simtime_t VehicleT = simTime();
std::pair<std::pair<std::string, std::string>, simtime_t> VehicleWithTime;
crossingList.push_back(VehTD);iteh2 = waitingList.erase(iteh2);
}
else{
++iteh;
}
}
}

Я использую Oment ++ 5.0 и вены 4.4

Я попытался поймать эту функцию, и похоже, что исключение происходит в конце списка.

Обновить:
У меня есть этот вывод:

WCounter 1
WCounter 2
Moving from waiting list Timer Function Exception
WCounter 1
WCounter 2
WCounter 3
Moving from waiting list Timer Function Exception
WCounter 1
WCounter 2
Moving from waiting list Timer Function Exception

WCounter — это переменная, показывающая, сколько раз он был зациклен, прежде чем возникнет исключение в точке, описанной ранее.

на основе запроса я добавил функцию блокировки:

  std::pair<std::list<std::string>,int> TraCIDemoRSU11p::Locks(std::list<std::string> alreadyLocked, std::string laneNo){
bool debugL;
//create variables for the lanes for easier use
try{
debugL = false;
zero = "171270266#0_0";
one = "171270266#0_1";
two = "-171270025#1_0";
three = "-171270025#1_1";
four = "-171270266#1_0";
five = "-171270266#1_1";
six = "171270025#0_0";
seven = "171270025#0_1";//create lists of locks

Locks0 = Locks1 = Locks2 = Locks3 = Locks4 = Locks5 = Locks6 = Locks7 = RequestToLock = {};
CounterOfSimilarLanes = 0;

//set of 0 ,Locks0;
Locks0.push_back(zero);
Locks0.push_back(five);
Locks0.push_back(seven);
//set of 1 ,Locks1;
Locks1.push_back(one);
Locks1.push_back(three);
Locks1.push_back(six);
//set of 2 ,Locks2;
Locks2.push_back(one);
Locks2.push_back(two);
Locks2.push_back(seven);
//set of 3 ,Locks3;
Locks3.push_back(zero);
Locks3.push_back(three);
Locks3.push_back(five);
//set of 4 ,Locks4;
Locks4.push_back(one);
Locks4.push_back(three);
Locks4.push_back(four);
//set of 5 ,Locks5;
Locks5.push_back(two);
Locks5.push_back(five);
Locks5.push_back(seven);
//set of 6 ,Locks6;
Locks6.push_back(three);
Locks6.push_back(five);
Locks6.push_back(six);
//set of 7 ,Locks7;
Locks7.push_back(one);
Locks7.push_back(four);
Locks7.push_back(seven);
//This is the request to lock from the vehicle using its lane number
if (laneNo == zero ){
RequestToLock.insert(RequestToLock.end(),Locks0.begin(),Locks0.end());
}else if (laneNo == one){
RequestToLock.insert(RequestToLock.end(),Locks1.begin(),Locks1.end()) ;
}else if (laneNo == two){
RequestToLock.insert(RequestToLock.end(),Locks2.begin(),Locks2.end()) ;
}else if (laneNo == three){
RequestToLock.insert(RequestToLock.end(),Locks3.begin(),Locks3.end()) ;
}else if (laneNo == four){
RequestToLock.insert(RequestToLock.end(),Locks4.begin(),Locks4.end()) ;
}else if (laneNo == five){
RequestToLock.insert(RequestToLock.end(),Locks5.begin(),Locks5.end()) ;
}else if (laneNo == six){
RequestToLock.insert(RequestToLock.end(),Locks6.begin(),Locks6.end()) ;
}else if (laneNo == seven){
RequestToLock.insert(RequestToLock.end(),Locks7.begin(),Locks7.end()) ;
}

}   //if the already locked from the controller is empty so we take the requested lock
catch(const std::exception &e){
cout<<"Preparing Locks Algorithm Exception"<<endl;
}
try{
if (alreadyLocked.empty()){

markOfLocks = 0;
alreadyLocked.insert(alreadyLocked.end(),RequestToLock.begin(),RequestToLock.end()) ;
Locked.insert(Locked.end(),RequestToLock.begin(),RequestToLock.end()) ;
if (debugL == true){
cout<<"First Lock in the locking algorithm"<<endl;
//  dumplistLock(Locked);
}
ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);

}else{ // if the already locked by the controller isnt empty, so we need to compare the request with it
//Search for similar items in the 2 lists
for(std::list<std::string>::/*const_*/iterator it_1 = alreadyLocked.begin();it_1 != alreadyLocked.end();)
{
for(std::list<std::string>::/*const_*/iterator it_2 = RequestToLock.begin(); it_2 != RequestToLock.end();)
{
if(*it_1 == *it_2)
{
++CounterOfSimilarLanes;
}

++it_2;

}
++it_1;
}if (RequestToLock == alreadyLocked){
markOfLocks = 1;
Locked.clear();
Locked = {};
Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
if (debugL == true){
cout<<"Same Lane"<<endl;
dumplistLock(Locked);
}
ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);

}else if(CounterOfSimilarLanes == 0){ //if the request is concurrent meaning totally different locks
markOfLocks = 2;
//alreadyLocked.insert(alreadyLocked.end(),RequestToLock.begin(),RequestToLock.end()) ;
Locked.clear();
Locked = {};
Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
if (debugL == true){
cout<<"Concurrent Lane"<<endl;
dumplistLock(Locked);
}

}else if(CounterOfSimilarLanes == 1  ||  CounterOfSimilarLanes == 2){ // if there's a similarity is 1 lock at least so it leads to conflict
markOfLocks = 3;
Locked.clear();
Locked = {};
Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
if (debugL == true){
cout<< "opposite Lane"<<endl;
dumplistLock(Locked);
}
ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
}else{
markOfLocks = 1;
Locked.clear();
Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
if (debugL == true){
cout<<"default case"<<endl;
dumplistLock(Locked);
}
ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
}

}
}catch(const std::exception &e){
cout<<"Lock Cases Exceptions"<<endl;
}

try{
return ReturnOfLocks;
}catch(const std::exception &e){
cout<<"No Return of Locks in Locks Alg Exception"<<endl;
}

}

-1

Решение

поэтому я изменил цикл for на цикл while, и он не показывал исключение, и не уверен почему.

поэтому цикл теперь выглядит так:

     //while loop instead.
std::list<std::pair<std::string,std::string>>::iterator iterwil = waitingList.begin();
std::pair<std::string, std::string> Vehwil ;
while (iterwil != waitingList.end()){
Vehwil = *iterwil;
CompareResult3 = Locks(Locked,Vehwil.second);
if(CompareResult3.second == 1 || CompareResult3.second == 2 ){
crossingList.push_back(Vehwil);
waitingList.erase(iterwil++);
}else{
++iterwil;
}

}

если у кого-то есть веская причина объяснить мне, почему цикл while работает без исключения, в отличие от цикла for, это было бы здорово. ^^»

0

Другие решения

Вы должны использовать iterator вместо const_iterator потому что вы изменяете (то есть удаляете) указанный элемент.
Кстати, в коде iteh2 не нужно — iteh достаточно, а также VehicleT а также ehk переменные не используются и могут быть удалены.

0

По вопросам рекламы [email protected]