# 2-opt

In optimization, 2-opt is a simple local search algorithm for solving the traveling salesman problem.The 2-opt algorithm was first proposed by Croes in 1958, although the basic move had already been suggested by Flood. The main idea behind it is to take a route that crosses over itself and reorder it so that it does not. - A B - - A - B - × ==> - C D - - C - D - A complete 2-opt local search will compare every possible valid combination of the swapping mechanism. This technique can be applied to the traveling salesman problem as well as many related problems. These include the vehicle routing problem (VRP) as well as the capacitated VRP, which require minor modification of the algorithm. This is the mechanism by which the 2-opt swap manipulates a given route. Here v1 and v2 are the first vertices of the edges you wish to swap when traversing through the route: procedure 2optSwap(route, v1, v2) { 1. take route[0] to route[v1] and add them in order to new_route 2. take route[v1+1] to route[v2] and add them in reverse order to new_route 3. take route[v2+1] to route[end] and add them in order to new_route return new_route;} Here is an example of the above with arbitrary input: * Example route: A → B → E → D → C → F → G → H → A * Example parameters: v1=1, v2=4 (assuming starting index is 0) * Contents of new_route by step: 1. * (A → B) 2. * A → B → (C → D → E) 3. * A → B → C → D → E → (F → G → H → A) This is the complete 2-opt swap making use of the above mechanism: repeat until no improvement is made { best_distance = calculateTotalDistance(existing_route) start_again: for (i = 0; i <= number of nodes eligible to be swapped - 1; i++) { for (j = i + 1; j <= number of nodes eligible to be swapped; j++) { new_route = 2optSwap(existing_route, i, j) new_distance = calculateTotalDistance(new_route) if (new_distance < best_distance) { existing_route = new_route best_distance = new_distance goto start_again } } }} Note: If you start/end at a particular node or depot, then you must remove this from the search as an eligible candidate for swapping, as reversing the order will cause an invalid path. For example, with depot at A: A → B → C → D → A Swapping using node[0] and node[2] would yield C → B → A → D → A which is not valid (does not leave from A, the depot). (Wikipedia).

Linear and quadratic approximations -- Calculus II

This lecture is on Calculus II. It follows Part II of the book Calculus Illustrated by Peter Saveliev. The text of the book can be found at http://calculus123.com.

From playlist Calculus II

Differential Equation - 2nd Order Linear (1 of 17) Introduction

Visit http://ilectureonline.com for more math and science lectures! In this video I will introduce 2nd order linear homogeneous and non-homogeneous differential equations. Next video in the series can be seen at: http://youtu.be/aA4TNJKvFCQ

From playlist DIFFERENTIAL EQUATIONS 9 - 2nd ORDER INTRODUCTION

Electrical Engineering: Ch 9: 2nd Order Circuits (72 of 76) Duality in a 2nd Order Circuit (Part 3)

Visit http://ilectureonline.com for more math and science lectures! http://www.ilectureonline.com/donate https://www.patreon.com/user?u=3236071 We will learn what is duality in 2 second order circuits, where the voltage and current are “interchangeable”; and where the power of the circui

From playlist ELECTRICAL ENGINEERING 9: SECOND ORDER CIRCUITS

MATH1131 Calculus Chapter 6 Q1

Showing that two functions are inverses by calculating their composition.

From playlist Mathematics 1A (Calculus)

Calculus 1 Lecture 3.4: The Second Derivative Test for Concavity of Functions

Calculus 1 Lecture 3.4: The Second Derivative Test for Concavity of Functions

From playlist Calculus 1 (Full Length Videos)

Second Derivative of Vector-Valued Function Example 2

Please Subscribe here, thank you!!! https://goo.gl/JQ8Nys Second Derivative of Vector-Valued Function Example 2

From playlist Calculus

Electrical Engineering: Ch 9: 2nd Order Circuits (74 of 76) Duality in a 2nd Order Circuit

Visit http://ilectureonline.com for more math and science lectures! http://www.ilectureonline.com/donate https://www.patreon.com/user?u=3236071 We will use transform a 2nd order circuit to a duality 2nd order circuit. In other words, a circuit that will do the same thing electronically,

From playlist ELECTRICAL ENGINEERING 9: SECOND ORDER CIRCUITS

Second Derivative of Vector-Valued Function Example 1

Please Subscribe here, thank you!!! https://goo.gl/JQ8Nys Second Derivative of Vector-Valued Function Example 1

From playlist Calculus

Niv Buchbinder: Deterministic Algorithms for Submodular Maximization Problems

Randomization is a fundamental tool used in many theoretical and practical areas of computer science. We study here the role of randomization in the area of submodular function maximization. In this area most algorithms are randomized, and in almost all cases the approximation ratios obtai

From playlist HIM Lectures 2015

GDPR Compliance Explained | What Is GDPR Compliance? | GDPR Explained | Email Marketing |Simplilearn

🔥Explore our FREE Courses: https://www.simplilearn.com/skillup-free-online-courses?utm_campaign=EmailMarketing&utm_medium=DescriptionFirstFold&utm_source=youtube This "GDPR Explained" video will help you understand the meaning of GDPR, implications of GDPR, data activities included in GDPR

Markov Decision Processes 2 - Reinforcement Learning | Stanford CS221: AI (Autumn 2019)

For more information about Stanford’s Artificial Intelligence professional and graduate programs, visit: https://stanford.io/2Zv1JpK Topics: Reinforcement learning, Monte Carlo, SARSA, Q-learning, Exploration/exploitation, function approximation Percy Liang, Associate Professor & Dorsa Sa

Nexus Trimester - Harry Lang (Johns Hopkins University)

Data Reduction for Clustering on Streams Harry Lang (Johns Hopkins University) March 08, 2016 Abstract: We explore clustering problems in the streaming sliding window model in both general metric spaces and Euclidean space. We present the first polylogarithmic space O(1)-approximation to

Seffi Naor: Recent Results on Maximizing Submodular Functions

I will survey recent progress on submodular maximization, both constrained and unconstrained, and for both monotone and non-monotone submodular functions. The lecture was held within the framework of the Hausdorff Trimester Program: Combinatorial Optimization.

From playlist HIM Lectures 2015

Calculus 1 Lecture 4.2: Integration by Substitution

Calculus 1 Lecture 4.2: Integration by Substitution

From playlist Calculus 1 (Full Length Videos)

Lec 14 | MIT 6.046J / 18.410J Introduction to Algorithms (SMA 5503), Fall 2005

Lecture 14: Competitive Analysis: Self-organizing Lists View the complete course at: http://ocw.mit.edu/6-046JF05 License: Creative Commons BY-NC-SA More information at http://ocw.mit.edu/terms More courses at http://ocw.mit.edu

The Traveling Salesman Problem: When Good Enough Beats Perfect

Use the code "reducible" to get CuriosityStream for less than \$15 a year! https://curiositystream.com/reducible The Traveling Salesman Problem (TSP) is one of the most notorious problems in all of computer science. In this video, we dive into why the problem presents such a challenge for

From playlist Graph Theory

Stanford Seminar - Learning, Memory, and Metacognitive Control

Mark Steyvers University of California, Irvine Dynamic professionals sharing their industry experience and cutting edge research within the human-computer interaction (HCI) field will be presented in this seminar. Each week, a unique collection of technologists, artists, designers, and ac

From playlist Stanford Seminars

Basic Terminology | Email Marketing Tutorial For Beginners | Simplilearn

🔥Digital Marketing Specialist Program (Discount Code - YTBE15): https://www.simplilearn.com/advanced-digital-marketing-certification-training-course?utm_campaign=BaiscTerminologyEmailMarketing-mhlGlUK4vDM&utm_medium=Descriptionff&utm_source=youtube 🔥Professional Certificate Program In Dig

From playlist Email Marketing Training [2022 Updated]

Electrical Engineering: Ch 9: 2nd Order Circuits (71 of 76) Duality in a 2nd Order Circuit (Part 2)

Visit http://ilectureonline.com for more math and science lectures! http://www.ilectureonline.com/donate https://www.patreon.com/user?u=3236071 We will learn what is duality in a second order circuit, where R and 1/R, L and C, and v and i are all “interchangeable”; where node and mesh, s

From playlist ELECTRICAL ENGINEERING 9: SECOND ORDER CIRCUITS

CMU Discrete Mathematics 4/12

Due to the COVID-19 pandemic, Carnegie Mellon University is protecting the health and safety of its community by holding all large classes online. People from outside Carnegie Mellon University are welcome to tune in to see how the class is taught, but unfortunately Prof. Loh will not be o

From playlist CMU 21-228 Discrete Mathematics

## Related pages

Lin–Kernighan heuristic | Local search (optimization) | Vehicle routing problem | 3-opt