Turn | Tabu Search algorithm (Tabu Search) to solve the problem of vehicle routing with time window detailed explanation (with Java code)

The following article is from Data Magician, author Zhou Hang

To download the relevant code and examples in this article, please pay attention to the public number [program ape sound], the background reply [TSVRPJAVA] does not include []

Foreword

Hello everyone!

Seeing that 9102 is almost over, Xiao Bian also feels more and more anxious:

Why do you feel so Cai this year!

So quickly before the exam week came, I wrote out this article on the taboo search algorithm to solve VRPTW, temporarily holding the Buddha's feet, pretending to learn something this year.

This article comes with a detailed explanation of the Java code, which is modified from the C ++ code written by the past seniors:

Dry goods | Ten minutes to master the tabu search algorithm to solve the vehicle routing problem with time windows (with C ++ code and detailed code comments)

The new code incorporates the original contempt criteria forgotten , changes some redundant code to function calls, and adds large-scale comments. It is suitable for students who have not tried VRPTW (yes, it is myself).

The calculation example is in the above format, so it is recommended to browse the above before reading the code in this article carefully.

Let's start sharing today!

Introduction to VRPTW

The VRPTW problem can be described as follows: Suppose a distribution center provides distribution services to several customer locations in the surrounding geographical locations that have different requirements for the delivery time of the goods. Among them, the vehicles used by the distribution center are all of the same model (that is, have the same capacity and speed); the distribution center has restrictions on the time for vehicles to enter and exit. Our task is to find the route that minimizes the sum of all vehicles' travel paths.

More detailed introduction of VRPTW can refer to the previous tweet:

Dry goods | 10 minutes to master CPLEX to solve VRPTW mathematical model (with JAVA code and CPLEX installation process)

In order to maintain the independence of the article, and at the same time to facilitate subsequent explanations, here is an example of modeling (references are marked at the end of the article):

All requested vehicle routes must meet the following requirements:

On this basis, the route with the shortest total time for each vehicle (because the vehicle speed is the same, the shortest time is equivalent to the shortest distance). (Some vehicles are not allowed)

About Tabu Search

Tabu Search Algorithm (abbreviated as TS) originates from the imitation of human memory function and is a meta-heuristics. It starts with an initial feasible solution, explores a series of specific search directions (movements), and selects the movements that maximize the value of a specific objective function. In order to avoid falling into the local optimal solution, tabu search records the information of the search process that has been experienced, thus guiding the next search direction.

Taboo search is a manifestation of artificial intelligence and an extension of local search. Tabu search is based on local search, by setting up a tabu list to tabulate some operations that have been performed, and using contempt criteria to unblock some excellent solutions.

For the specific content of the tabu search algorithm, please refer to the previous tweets:

Dry goods | What kind of algorithm can make people so desperate?

Dry goods | Ten minutes quick review taboo search (c ++ version)

TS solves VRPTW

For neighborhood search algorithms, the search operator and evaluation function adopted are crucial. The following introduces the insertion operator and evaluation function for VRPTW in the code in detail.

Insert operator:

Evaluation function:

Algorithm overview

Detailed Java code

To download the relevant code and examples in this article, please pay attention to the public number [program ape sound], the background reply [TSVRPJAVA] does not include []

The code is mainly divided into the following categories:

Main, the main function;
CustomerType, store the information of the customer node;
RouteType, store the vehicle route information;
Parameter, store the global variable;
EvaluateRoute, process route method;
InitAndPrint, initialization and output corresponding method;
TS, tabu search method

Next, they are introduced separately.

Main: The entrance of the program.
CustomerType: Customer class. For each customer in the figure, build a customer class, store its own number, vehicle route, coordinate location, access time window, service duration and demand.

RouteType: Route type, which records the total carrying capacity, total length of the route, the total violation of the time window constraint, and the sequence of customer nodes on a single route.

Parameter: Parameter class, the variables about VRPTW and TS are stored here, and the data is modified here.

EvaluateRoute: The check function is a test of the resulting solution.

Since the solutions generated by the insertion operator do not all satisfy all the constraints, the better solutions generated by the local search need to determine whether the time window constraints and capacity constraints are satisfied before deciding whether they are feasible solutions.

In the process of checking the local optimal solution, modify the values ​​of the penalty coefficients Alpha and Beta.

The UpdateSubT function updates the amount of time window violations at each customer point in a vehicle route. The result is obtained by traversing the entire route and accumulating.

The Calculate function calculates the value of the objective function, and the penalty part is accumulated and multiplied by the penalty coefficient.

InitAndPrint: According to the calculated distance.

Read the study from the file (modify the study here, remember to modify the parameters in the Parameter class at the same time), and initialize each route of the current solution routes [], the starting and ending points are distribution centers.

The distance between customers is recorded and stored in the Graph array.

Construction constructs the initial solution. The initial solution is constructed according to the previous pseudocode, and the nodes are randomly selected each time (similar to disrupting the ordered number sequence).

Find the location that meets the capacity constraint for the node and the opening time of the time window meets the requirements, and insert the node. Remember to update the path to which the node belongs when inserting the node. Initialize the time window violation.

Finally, add a CheckAns function to check whether the output solution meets the time window constraint and the calculated distance is correct.

TS: First there are two auxiliary functions, addnode and removenode, which are the execution part of the insertion operator.

Now that everything is ready, I only owe it to the wind. I just need to integrate all the tools according to the taboo search routine and build a code framework.

Since we use the routes [] array to store the current solution, part of the data must be stored before the insertion operation, and the restoration operation must be performed after the objective function is calculated.

When updating the taboo table, the formula for the taboo step size can be changed flexibly.

Remember to judge the local optimal solution, and then select the feasible global optimal solution.

Calculation example

We use the standard solomon test data c101.txt for testing. (The calculation example can be downloaded in the message area)

VehicleNumber = 25;

Capacity=200;

Test the number of nodes 25, 50 and 100 respectively. The exact solutions are:

CustomerNumber=25:

CustomerNumber=50:

CustomerNumber=100:

It can be seen that the accuracy of our code is still very good ~~

Of course, we do not rule out bad luck and get a very poor solution. Do not believe your character can manually adjust the number of iterations IterMax.

The content of this issue is almost over here! Happy!

Here to remind everyone that in the learning process for heuristic algorithms, the ability to write code is very important. VRPTW is a good carrier. It is recommended that readers who have time to apply the learned algorithm knowledge to practice. The editor will learn and progress with you!

See you next time ヾ ( ̄ ▽  ̄) Bye Bye

references:

Cordeau, J. F. , Laporte, G. , & Mercier, A. . (2001). A unified tabu search heuristic for vehicle routing problems with time windows. Journal of the Operational Research Society**, 52(8), 928-936.

Code reference:

Dry goods | Ten minutes to master the tabu search algorithm to solve the vehicle routing problem with time windows (with C ++ code and detailed code comments)

Guess you like

Origin www.cnblogs.com/dengfaheng/p/12672771.html