0
I’m trying to call a function I’ve done, but always this error appears:
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: deque
EXECUTAR FINISHED; Abort trap: 6; tempo real: 230ms; usuário: 0ms; sistema: 0ms
Follow the function code:
int Perturba(deque<int>* sack_profit, deque<int>* sack_weight, int items_profit[], int items_weight[], int num_items, int T)
{
deque<int> solution_profitV;
deque<int> solution_weightV;
int item_position;
int sack_total_weight = 0;
int sack_total_profit = 0;
int total_weightV = 0;
int total_profitV = 0;
int i = 0;
int delta;
while(i <= sack_weight->size())
{
solution_profitV.push_back(sack_profit->at(i));
solution_weightV.push_back(sack_weight->at(i));
i++;
}
srand( (unsigned) time (NULL) );
item_position = rand() % num_items;
solution_profitV.push_back(items_profit[item_position]);
solution_weightV.push_back(items_weight[item_position]);
i=0;
while(i <= sack_weight->size())
{
sack_total_weight += sack_weight->at(i);
sack_total_profit += sack_profit->at(i);
i++;
}
i = 0;
while(i <= solution_weightV.size())
{
total_weightV += solution_weightV[i];
total_profitV += solution_profitV[i];
i++;
}
delta = total_profitV - sack_total_profit + total_weightV - sack_total_profit;
if(delta <= 0 || exp(-delta/T) > Random())
{
sack_profit->swap(solution_profitV);
sack_weight->swap(solution_weightV);
return 1;
}
else
return 0;
}
This function basically randomly modifies the current combination of items on the previous deck if it satisfies the condition specified in the code.
I believe the problem is in modifying the decks passed as pointers, but I’m not sure whether it’s this or how to solve.
How can I solve this problem?