Research Article
An Adaptive Data-Driven Approach to Solve Real-World Vehicle Routing Problems in Logistics
Pseudocode 6
Improvements within each route.
| for(int i = 0; i < num_of_iterations; i++){ | | int customer = −1; | | int place = −1; | | double theLowestCost = RouteCost(); | | for(int j = 0; j < customers.size(); j++){ | | vector<Customer∗> newRoute; | | for(int r = 0; r < j; r++){ | | newRoute.push_back(customers[r]); | | } | | for(int r = j + 1; r < customers.size(); r++){ | | newRoute.push_back(customers[r]); | | } | | for(int k = 0; k ≤ newRoute.size(); k++){ | | newRoute.insert(newRoute.begin()+k, customers[j]); | | Route ∗r = new Route(newRoute, routeVehicle, true); | | double routeCost = r->RouteCost(); | | if(routeCost < theLowestCost) | | customer = j; place = k; theLowestCost = routeCost; | | for(int u = 0; u < r->customers.size(); u++){ | | delete r->customers[u]; | | } | | delete r; | | newRoute.erase(newRoute.begin()+k); | | } | | } | | if(customer = = −1){ | | break; | | } | | Customer ∗k = customers[customer]; | | ExcludeCustomer(customer); | | InsertRouteToThePlace(new Route(k), place − 1); | | } |
|