Skip to content

Commit

Permalink
Added Tabu Search. Corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharma-n committed May 17, 2020
1 parent 2dfc0df commit 88d4f54
Show file tree
Hide file tree
Showing 20 changed files with 1,907 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.ipynb_checkpoints/*
**/__pycache__/*
8. Tabu Search.ipynb
**/*.mp4
**/*.mp4
.vscode/
9 changes: 5 additions & 4 deletions 1. Greedy Search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"metadata": {},
"source": [
"#### Selecting the neighborhood size\n",
" * Advatage of a large neighborhood is that you are more likely to find a better next value for $s$ than with a small neighborhood and less likely to get cuaght in a local minimum.\n",
" * Advantage of a large neighborhood is that you are more likely to find a better next value for $s$ than with a small neighborhood and less likely to get cuaght in a local minimum.\n",
" * Disadvantage is that you may have to evaluate *cost(s)* many times and this may be computationally demanding.\n",
" \n",
"## Hard Problems and Heuristics\n",
Expand All @@ -245,12 +245,13 @@
" * In addition there are many problems for which no optimization method exists except heuristic methods.\n",
" \n",
"## Random Walk / Random Search / Greedy Deterministic / Greedy Stochastic\n",
"Based on the observations above, 4 simple algorithms are implemented. FOr the purposes of using an example, the **cost function** we will optimize for is\n",
"Based on the observations above, 4 simple algorithms are implemented. For the purposes of using an example, the **cost function** we will optimize for is\n",
"$$Cost(s) = (400-(s-21)^2)\\cdot \\sin(s\\pi/6)$$\n",
"The constraint on $s: s\\in\\mathbb{N}, 0\\leq s\\leq 500$.\n",
"The **negihbourhood function** that is implements below for step 2 considers $\\forall s, s.t. max(s_{current}-25, 0)\\leq s \\leq \\min(s_{current}+25, 500)$\n",
"The **neighbourhood function** that is implements below for step 2 considers $\\forall s, s.t. max(s_{current}-25, 0)\\leq s \\leq \\min(s_{current}+25, 500)$\n",
"\n",
"The 4 algorithms implemented differ in their implementation of step 3, the improvement algorithm:\n",
"\n",
"1. **Random Walk (RW)**: In RW, the next value of $s$ is chosen at random from the set of negihbours of $s_{current}$. The best value seen until now is saved as $s_{best}$, along with $cost(s_{best})$.\n",
"2. **Random Sampling (RS)**: In RW, the next value of $s$ is chosen at random from ALL possible values of $s (0\\leq s\\leq 500)$. As before, we save $s_{best}$ and $cost(s_{best})$.\n",
"3. **Greedy Deterministic (GD)**: Same as presented above, we select $s = \\min_s cost(s), \\forall s\\in neigh(s_{current})$\n",
Expand Down Expand Up @@ -528,4 +529,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
5 changes: 3 additions & 2 deletions 2. Simulated Annealing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"source": [
"# Simulated Annealing\n",
"Simulated Annealing uses the process of cooling of a substance that leads to the a stronger molecular structure. The heuristic algorithm uses two parameters:\n",
"\n",
"1. Temperature, $T$: \"temperature\" which is dropped in a very controlled fashion.\n",
"2. Rate, $\\alpha$: the rate of cooling\n",
"\n",
Expand All @@ -16,7 +17,7 @@
" * For downhill move: go downhill\n",
" * For uphill move: with probability $p$, go uphill, otherwise stay\n",
" \n",
" Therefore, the important distinction between greedy search and simulated annealing is that **sometimes you will accept an uphill move**. The probability of accepting such an uphill movement should depend on:\n",
"Therefore, the important distinction between greedy search and simulated annealing is that **sometimes you will accept an uphill move**. The probability of accepting such an uphill movement should depend on:\n",
" * The size of the uphill move\n",
" * The number of iterations in the search that have already been performed\n",
" * A random variable\n",
Expand Down Expand Up @@ -410,4 +411,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
84 changes: 39 additions & 45 deletions 4. Genetic Algorithms Examples.ipynb

Large diffs are not rendered by default.

792 changes: 792 additions & 0 deletions 8. Tabu Search.ipynb

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions 9. DDS.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Dynamically Dimensioned Search (DDS)\n"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": 3
},
"orig_nbformat": 2
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added Images/vrp_greedy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/vrp_tabu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Global optimization attempts to find the global minima / maxima of a function or
* Simulated Annealing (with and without automatic parameter selection)
* Genetic Algorithms for Path Finding and Travelling Salesman Problem
* Multi Objective Optimization using Elitist Non-Dominated Sorting Genetic Algorithm (NSGA-II)
* Tabu Search for Travelling Salesman Problem and Capacitated Vehicle Routing Problem

## Some visualizations
* **Simulated Annealing:** Below we see the comparison between simulated annealing (SA) and greedy search (GS) on an example objective. The search algorithm attempts to minimize the function based on two variables. In the image, green areas are maximas and purple areas are minimas, with teh intensity representing magnitude.
* **Simulated Annealing:** Below we see the comparison between simulated annealing (SA) and greedy search (GS) on an example objective. The search algorithm attempts to minimize the function based on two variables. In the image, green areas are maximas and purple areas are minimas, with the intensity representing magnitude.

![Simulated Annealing example](Images/simulated_annealing.PNG)
![Simulated Annealing example](Images/simulated_annealing.png)

* **Genetic Algorithsm**: Below shows the evolution of the solutions for two problems solved using genetic algorithms: path finding and travelling salesman problem:

Expand All @@ -33,8 +34,17 @@ Global optimization attempts to find the global minima / maxima of a function or
![Path finding using genetic algorithm](Images/nsga_kursawe.gif) | ![TSP using genetic algorithms](Images/nsga_viennet.gif)
</center>

* **Tabu Search**: Below compares an optimal solution found using Tabu search vs. greedy search for the [Vehicle Routing Problem](https://en.wikipedia.org/wiki/Vehicle_routing_problem).

<center>

Greedy Search | Tabu Search
:-------------------------:|:-------------------------:
![VRP optimal solution using Greedy search](Images/vrp_greedy.png) | ![VRP optimal solution using Tabu search](Images/vrp_tabu.png)
</center>

## Running the Code
The code is avaialble as separate Jupyter notebooks, which can be run indeendenat on one another.
The code is available as separate Jupyter notebooks, which can be run independent on one another.

## Acknowledgements
The theoretical details for the algorithms have been taken from the course [Surrogate and Metaheuristic Global Optimization](https://ivle.nus.edu.sg/V1/lms/public/view_moduleoutline.aspx?CourseID=1D86508F-95B6-4BD2-AC09-6A895C581EBF&ClickFrom=StuViewBtn) offered in [NUS](http://www.nus.edu.sg), taught by [Prof. Christine Shoemaker](https://www.eng.nus.edu.sg/isem/staff/christine-a-shoemaker/)
76 changes: 76 additions & 0 deletions data/VRP/A-n32-k5.vrp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
NAME : A-n32-k5
COMMENT : (Augerat et al, Min no of trucks: 5, Optimal value: 784)
TYPE : CVRP
DIMENSION : 32
EDGE_WEIGHT_TYPE : EUC_2D
CAPACITY : 100
NODE_COORD_SECTION
1 82 76
2 96 44
3 50 5
4 49 8
5 13 7
6 29 89
7 58 30
8 84 39
9 14 24
10 2 39
11 3 82
12 5 10
13 98 52
14 84 25
15 61 59
16 1 65
17 88 51
18 91 2
19 19 32
20 93 3
21 50 93
22 98 14
23 5 42
24 42 9
25 61 62
26 9 97
27 80 55
28 57 69
29 23 15
30 20 70
31 85 60
32 98 5
DEMAND_SECTION
1 0
2 19
3 21
4 6
5 19
6 7
7 12
8 16
9 6
10 16
11 8
12 14
13 21
14 16
15 3
16 22
17 18
18 19
19 1
20 24
21 8
22 12
23 4
24 8
25 24
26 24
27 2
28 20
29 15
30 2
31 14
32 9
DEPOT_SECTION
1
-1
EOF
78 changes: 78 additions & 0 deletions data/VRP/A-n33-k6.vrp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
NAME : A-n33-k6
COMMENT : (Augerat et al, Min no of trucks: 6, Optimal value: 742)
TYPE : CVRP
DIMENSION : 33
EDGE_WEIGHT_TYPE : EUC_2D
CAPACITY : 100
NODE_COORD_SECTION
1 34 31
2 45 55
3 70 80
4 81 70
5 85 61
6 59 55
7 45 60
8 50 64
9 80 64
10 75 90
11 25 40
12 9 66
13 1 44
14 50 54
15 35 45
16 71 84
17 1 9
18 25 54
19 45 59
20 45 71
21 66 84
22 11 35
23 81 46
24 85 10
25 75 20
26 15 21
27 90 45
28 15 0
29 31 26
30 10 95
31 6 6
32 51 5
33 26 36
DEMAND_SECTION
1 0
2 26
3 17
4 6
5 15
6 7
7 5
8 15
9 16
10 17
11 1
12 21
13 66
14 25
15 16
16 11
17 7
18 17
19 17
20 22
21 10
22 25
23 16
24 7
25 21
26 11
27 21
28 11
29 21
30 22
31 25
32 2
33 22
DEPOT_SECTION
1
-1
EOF
108 changes: 108 additions & 0 deletions data/VRP/A-n48-k7.vrp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
NAME : A-n48-k7
COMMENT : (Augerat et al, Min no of trucks: 7, Best value: 1073)
TYPE : CVRP
DIMENSION : 48
EDGE_WEIGHT_TYPE : EUC_2D
CAPACITY : 100
NODE_COORD_SECTION
1 47 5
2 1 19
3 97 35
4 23 79
5 77 87
6 3 9
7 5 27
8 41 53
9 51 87
10 67 73
11 89 45
12 71 99
13 11 1
14 85 85
15 57 11
16 57 85
17 71 33
18 61 13
19 39 15
20 13 59
21 43 99
22 87 73
23 11 37
24 21 11
25 77 81
26 3 63
27 47 95
28 53 75
29 73 55
30 81 71
31 89 75
32 11 9
33 27 37
34 95 59
35 63 63
36 37 21
37 33 47
38 23 63
39 13 55
40 47 93
41 45 43
42 83 7
43 69 91
44 13 11
45 37 15
46 53 59
47 97 83
48 75 31
DEMAND_SECTION
1 0
2 20
3 14
4 5
5 11
6 22
7 25
8 2
9 18
10 10
11 26
12 14
13 22
14 9
15 11
16 18
17 24
18 15
19 23
20 16
21 14
22 8
23 5
24 12
25 8
26 16
27 12
28 15
29 9
30 2
31 10
32 2
33 3
34 20
35 3
36 13
37 25
38 23
39 8
40 16
41 9
42 14
43 4
44 13
45 7
46 16
47 18
48 16
DEPOT_SECTION
1
-1
EOF
Loading

0 comments on commit 88d4f54

Please sign in to comment.