| while(num_of_iterations --){ |
| vector<int> randPermutation = RandomPermutation (currentSolution.size()); |
| for(int i = 0; i < randPermutation.size(); i++){ |
| vector<Route∗> routeCopy = currentSolution; |
| for(int j = 0; j < routeCopy.size(); j++){ |
| routeCopy[j] = new Route(currentSolution[j]->customers, currentSolution[j]->routeVehicle, true); |
| } |
| double totalConsumption = 0; |
| bool possible = true; |
| for(int k = 0; k < routeCopy[randPermutation[i]]->customers.size(); k++){ |
| double minConsumption = CONSTANT; |
| int route_number = −1, place = −1; |
| for(int u = 0; u < routeCopy.size(); u++){ |
| if(u ! = randPermutation[i]){ |
| for(int = −1; = = −1 || < routeCopy[u]->customers.size();++){ |
| if(routeCopy[u]->IsItpossibleToAddCustomer(routeCopy[randPermutation[i]]->customers[k],) |
| && minConsumption > routeCopy[u]->AdditionalConsumptionWithCustomerAtPlace |
| (routeCopy[randPermutation[i]]->customers[k],)){ |
| minConsumption = routeCopy[u]->AdditionalConsumptionWithCustomerAtPlace |
| (routeCopy[randPermutation[i]]->customers[k],); |
| route_number = u; |
| place = ; |
| } |
| } |
| } |
| } |
| if(route_number = = −1){ |
| possible = false; |
| break; |
| } |
| routeCopy[route_number]-> |
| InsertRouteToThePlace(new Route(routeCopy[randPermutation[i]]->customers[k]), place); |
| totalConsumption += minConsumption; |
| } |
| double savings = currentSolution[randPermutation[i]]->RouteCost(); |
| if(possible && (savings-totalConsumption > 0)){ |
| routeCopy.erase(routeCopy.begin() + randPermutation[i]); |
| currentSolution = routeCopy; |
| break; |
| } |
| } |
| } |