Discrete Optimization Course Notes (3)—Partial Search

directory

1. Local Search

Case1: The Queens problem(Max/Min-Conflict)

2. Neighborhood exchange (swap neighborhood)

Case2: Car Sequencing problem(number of violations)

Case3: The Magic Square Problem(degree of violations)

​​​​​​3. Traveling Salesman Problem (TSP)

Case4:Warehouse Location

Case5:Traveling Salesman Problem(k-opt)

4. Graph coloring problem (graph coloring GCP)

5. Tour problem (traveling tournament problem TTP)

6. Connectivity

7. Heuristics

8. Metaheuristics

8.1 Iterated Local Search

8.2 Simulated Annealing

8.3 Tabu Search (Tabu Search)

9. Taboo Search Extension

Case2: car-sequencing(Transition Abstractions)

Case1: Queens Problem(Transition Abstractions)

10. TSP programming homework


1. Local Search

Constrained programming cuts the search space starting from constraints, and assigns values ​​to decision variables step by step, while local search directly performs local adjustments based on the initial solution until the adjusted solution satisfies the conditions or is optimal. For problems that only need to find a solution, you can start from an infeasible solution and slowly adjust to a feasible solution; for optimization problems, start from a suboptimal solution and adjust to the optimal solution; for optimization problems with constraints, there are also some The method will be described later.

The problem of satisfactory solution can be transformed into an optimization problem. The concept of violations is introduced to represent how many constraints the current solution does not satisfy. The process of finding the solution is the process of minimizing violations. Take 8 queens as an example to illustrate.

Case1: The Queens problem(Max/Min-Conflict)

Max/Min-Conflict: First select the variable with the most violations, and adjust the value of the variable to reduce violations.

Random initial solution, calculate the number of constraints that each queen does not satisfy, namely violations, select the variable with the most violations to adjust its position, as shown in the figure below, the violations in column 4 is 3, adjust its position, and calculate the adjustment to other positions in column 4 The total number of violations changes, adjust it to the grid where violations are reduced the most, and repeat the above operation until violations=0 to find a satisfactory solution.

 Use a graph to represent the local search, repeat the search for the neighborhood (neighborhood), update the current optimal solution, and then search the field. When the field of a certain solution is not better than itself, the search stops, so the local search finds a local optimum, which cannot guarantee the global optimum. Avoiding getting stuck in local optima is also a critical part of local search. 

2. Neighborhood exchange (swap neighborhood)

Case2: Car Sequencing problem(number of violations)

  • For each option, set a sliding window according to the capacity constraint, calculate the number of times each line does not meet the constraint, and mark the non-compliant option
  • Select the exchange of the two columns with the most violations, such as column 4 and column 10
  • Update two tables, repeat the above process

 It can be seen from this case that there are two types of constraints in the process of local search:

(1) hard constraints : It is always satisfied during the search process, for example, each solution meets the demand constraints

(2) soft constraints : may be violated during the search process, for example, the solution satisfies the capacity constraint

Case3: The Magic Square Problem(degree of violations)

 Use the same idea to solve the Magic Square problem. The hard constraint means that all values ​​are different, and the soft constraints are equal to or equal to 15. Calculate the number of violations in each row, column, and diagonal corner as 1, and then randomly choose to exchange two values. The total number of violations may remain unchanged after the exchange, 0/1 violations are sometimes useless, and most moves will be invalid, so degrees can be used instead of quantities. Calculate the difference between all sums and the target value of 15, and select the exchange value with a large gap to make it closer to the target value

​​​​​​3. Traveling Salesman Problem (TSP)

Case4:Warehouse Location

Warehouse set W, each warehouse construction cost fw, customer set C, there is transportation cost from each warehouse to the customer. There are two decision variables: whether each warehouse is open (0/1 variable); which warehouse each customer is assigned to. There are no constraints, and the total cost includes construction and transportation costs. Once the location of each warehouse is determined, assigning customers is simple. Neighborhood of solution: Flip the value of the 0/1 variable.

Case5:Traveling Salesman Problem(k-opt)

Given the city and coordinates, find the minimum cost Hamiltonian circuit, that is, each point passes only once and returns to the origin, k-opt is a local search method

(1) 2-opt : Select two non-adjacent sides, exchange these two sides, and judge whether the cost is reduced

(2) 3-opt : 3 edges are also exchanged, the solution quality is higher than 2-opt but more time-consuming

(3) k-opt : The same idea, but don't focus on how to exchange, but search and exchange to find a better sequence, improve a little each time, k is a parameter, need to adjust to determine the best k value, randomly select a point Start, take the following picture as an example

  • Starting from point 1, the connecting side is (1,2), select the side (2,3) whose length is less than (1,2) and connect, remove the side (4,3) originally connected to point 3, and connect the side (1 ,4), but not really connected, calculate the new cost
  • Repeat the above process. The figure below shows the sequence of each update. The red solid line is the added edge, and the red dotted line indicates that the exchange sequence should be found from this edge. In the last step, starting from edge (1,8), no edge (8,~) can be found to be shorter, so stop and start to update another vertex

  • Starting from the new vertex, repeat the above process, the optimal solution has been found as shown in the figure below 

4. Graph coloring problem (graph coloring GCP)

There are two issues to consider when using local search to solve graph coloring problems:

  • Optimization (optimality): reduce the number of colors
  • Feasibility (feasibility): satisfy the constraints of adjacent different colors

There are three ways to integrate the two problems into LC

(1) sequence of feasibility problems (feasible solution sequence) 

Find the initial solution with k colors, eliminate color k, randomly replace the vertex with color k with color [1,k-1], and find the solution of k-1 colors by reducing violation

(2)staying in the feasible space 

Let C(i) be the vertex set with color i, the optimization goal is to minimize the number of colors, which can be transformed into maximizing the length of the vertex set, that is, let more points have the same color and be in the same set. The domain is to change the color of a certain vertex, but in order to ensure that the solution is feasible, changing the color of a certain vertex requires changing the color of other vertices. Here, the concept of Richer neighborhoods is proposed, that is, the domain starts from the problem structure and changes multiple Part, use Kemp Chains to modify the color to move to the neighborhoods 

(3)Explore both feasible and infeasible colorings 

During the search process, the number of colors must be reduced and the solution is feasible. Modify the objective function to balance feasibility and optimality. Define two edges with the same color as a bad edge, and B(i) is the set of bad edges in C(i). The objective function is as follows , minimize |B(i)|, maximize |C(i)|, the function is designed in this way to ensure that the local optimum of the objective must be a feasible solution.

The derivation process is as follows: Suppose the solution is C(1)....C(k), select an edge from a non-empty B(i)>=1, and change the color of one of the vertices of the edge to k+ 1, then the calculation shows that the objective function has been reduced by at least 2, indicating that for an infeasible solution, a method can always be found to reduce the objective function by 2, indicating that this is not a local optimum. A non-feasible solution must not be a local optimum, and a local optimum must be a feasible solution.

5. Tour problem (traveling tournament problem TTP)

n teams, each team plays twice with other teams, each team plays once a week, a@b means that a goes to the venue of b to play, there are two constraints:

  • atmost constraint: no more than three consecutive times at home or at other places
  • no repeat constraint: a@b cannot appear behind b@a, that is, the two teams cannot be the same for two consecutive weeks

As shown on the right: Assuming that there are 6 teams, there are 10 weeks in total. For example, team 1 played 6 games in the first week, and went to venue 2 and played 2 games in the second week. The two constraints are reflected in the scheduling table as follows: The @ or no @ cells in each row cannot appear more than three times in a row, and the numbers in the two adjacent grids in each row are different. There is also a redundancy constraint. If ab appears in a column, b@a must also be satisfied. The optimization goal is to minimize the total travel.

 There are 5 ways to move to Neighborhood:

  • Swap Homes: a@b becomes ab, ab becomes a@b

  •  Swap Rounds: Exchange a two-week arrangement

  • Swap Teams: Select two teams to exchange each other's arrangements, excluding the games of the two teams themselves, adjust the feasible solution after the exchange

  •  Swap Partial Rounds: Exchange a team's arrangement for a certain two weeks and then adjust to a feasible solution 

  •  Swap Partial Teams: Exchange the game objects of two teams in a certain week and then adjust to a feasible solution

6. Connectivity

For local search, its final effect also depends on the characteristics of the search space (solution space), as shown in the figure below, the optimal solution is represented by dark color. When the solution space is on the left, it can transfer to the optimal solution through local search; when the solution space is on the middle, it is easy to fall into the local optimum, and some methods can be used to jump out of the local optimum; when the solution space is on the right, the space is not connected, No local search can find the optimal solution. Therefore, when using LC to solve a problem, it is first necessary to determine whether the solution space is connected.

The Graph Coloring, Car Sequencing, and Traveling Salesman Problems encountered earlier all satisfy connectivity. Taking the 2-opt of TSP as an example, after each exchange, the sequence between two vertices is actually flipped, by flipping each position All vertices are possible, that is, any solution can be reached from an initial solution.

7. Heuristics

 First, review the basic local search process. Starting from a certain solution (state), find its neighborhood N(s), and select a legal and feasible neighborhood L(N(s),s) from N(s). ), select a solution S(L(N(s),s),s) from the feasible neighborhood as the moving target.

 How to choose the next neighbor is a very important part, including the following two categories

  • Heuristics: According to the current state and neighborhood information, determine the next neighbor, so that the search is in the direction of the local optimum, such as 2-opt
  • Metaheuristics (Metaheuristics): Based on the heuristic method, avoid falling into the local optimum and make the search towards the global optimum, such as GA, SA

 This section only introduces the heuristic method. The neighbor of a certain solution may be locally improved, or may remain the same, or may have potential degradation, from L(N(s),s) to S(L(N(s), s), s) have the following ideas

  • Best neighbor: choose the best solution after exploring all feasible neighbors

  • First neighbor: choose the first feasible solution and avoid exploring all feasible neighbors

  •  Multi-Stage Heuristics: It is implemented in multiple steps. For example, in the 8 Queens problem, first select the variable and then assign the value. In the first step, choose to use greedy to select the variable with the most violations, or randomly select a variable
  • Random Walks: random selection

8. Metaheuristics

8.1 Iterated Local Search

Start iterative search from different starting points multiple times, as shown in the figure below, update the optimal value after each execution of S(L(N(s),s),s), and then regenerate the initial solution. Iterative local search can be combined with other meta-heuristic algorithms to achieve multiple restart searches.

8.2 Simulated Annealing

Simulated annealing SA is derived from the Metropolis Heuristic method. Select a neighborhood solution. If the target value of the solution is better than the target value of the original solution, you can directly move to the solution. Otherwise, select the solution according to a certain probability. The probability is the index of the ratio of the difference between the original target value and the new target value and t, where t is the hyperparameter that needs to be adjusted. 

 In the Metropolis Heuristic method, if t is relatively large, the probability of receiving a degenerate solution will also increase. If t is relatively small, the probability of receiving a degenerate solution will decrease, but it is also easy to fall into a local optimum. Therefore, referring to the crystal production process, in order to reduce defects, the production temperature will slowly drop. Therefore, the value of t can be dynamically adjusted in Metropolis Heuristic, which is the idea of ​​the simulated annealing algorithm. At the beginning of the search, t is relatively large, and it is more inclined to explore new solutions, gradually reduce the value of t, and finally make local improvements.

 Simulated Annealing can guarantee convergence to the global optimum, but in some scenarios it is slower than brute force global search. In practical applications, the test sets with better SA performance include TTP, scheduling, etc. In order to speed up the search, the descending speed of t can be adjusted appropriately. Some tips that can be used in SA: reset the initial solution, reset the temperature, etc.

8.3 Tabu Search (Tabu Search)

Use the tabu list to save the explored solution tabu node, each time select a feasible solution in the neighborhood that is not in the tabu list, see the next section for more details. In addition to the above three meta-heuristic methods, there are variable neighborhood search, guided local search, ant-colony optimization, hybrid evolutionary algorithms, Scatter search (scatter search), etc.

9. Taboo Search Extension

(1)Short-Term Memory​​​​​​​+Transition Abstractions

The core idea of ​​tabu search has been described above: do not escape to explore the nodes that have been explored. Therefore, a tabu list is required to store all explored nodes. There is a problem with this idea: maintaining all tabu nodes in the tabu list is very time-consuming and memory-consuming, so the Short-Term Memory method is proposed, which has two improvements

  • tabu list size: only keep a part of the nodes that have been explored; the size of the list can be dynamically adjusted
  • tabu node storage structure: save the transfer abstraction of the state instead of the state itself

The process is illustrated by a car-sequencing case

Case2: car-sequencing(Transition Abstractions)

Assuming that each move just exchanges two slots, use (a(i),b(i)) to indicate that a(i) and b(i) are exchanged at step i, if a field solution can be exchanged (a (i), b(i)) is obtained, then the solution is forbidden. How to achieve? Assuming that the current iteration count is it, the length of the tabu list is L, and the data structure tabu[i,j] is used to indicate that i and j will be exchanged in the next iteration. If tabu[i,j] > it, then this exchange is allowed , tabu[i,j] is updated to it+L. That is, the taboo is no longer the entire solution (combination), but a certain exchange operation. Even if all moves in a certain step are prohibited, as the iteration step increases, there will always be exchange operations that are not prohibited. This change will not make the solution quality of each exchange better, but it can greatly improve the computational efficiency. As shown in the left figure below, first find NotTabu and then update tabu[i,j] and tabu[j,i], and decide whether to update the current optimal solution according to the value of the objective function. 

 Using this transfer abstraction and restricting length as a taboo choice can be strong or weak:

  • Too weak: Only considering the fixed-length tabu list may repeatedly explore the previously explored nodes
  • Too strong: It may prevent searching for unexplored nodes, so the taboo is the exchange operation, which is stronger than tabooing a complete solution

In order to strengthen this transfer abstraction, each transfer and the value of the objective function can be stored, (ai, bi, fi, fi+1) means that ai and bi are exchanged at step i, and the value of the objective function changes from fi to fi+1, so if It is possible to exchange (ai,bi) or a feasible solution in a certain neighborhood, and f(s)=fi and f(n)=fi+1, then the solution is forbidden.

Case1: Queens Problem(Transition Abstractions)

In the same way, storing (x, v) in the tabu list in the Queens Problem means that a certain column cannot be assigned a value v, which is faster than directly storing all solutions

(2)Aspiration 

 If a certain move is prohibited, but the result becomes better, it can also be used, taking into account the tabu list and the objective function value

(3)Long-Term Memory 

  • Intensification: Store high-quality solutions and return to these solutions in stages
  • Diversification: If the current search does not find an improvement, change the current state, such as randomly changing the value of some variables
  • Strategic oscillation: Adjust the search time ratio between feasible solutions and infeasible solutions

These tricks can also be used in SA 

10. TSP programming homework

For the solution time, the solution quality requirements are relatively high, use 2-opt, k-opt, SA solution respectively, the code can be found in my github

For details on the implementation of TSP-related algorithms, see Implementing Lin-Kernighan in Python

Guess you like

Origin blog.csdn.net/weixin_45526117/article/details/128018731