<s>
In	O
combinatorial	O
optimization	O
,	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
is	O
one	O
of	O
the	O
best	O
heuristics	B-Algorithm
for	O
solving	O
the	O
symmetric	O
travelling	B-Algorithm
salesman	I-Algorithm
problem	I-Algorithm
.	O
</s>
<s>
It	O
belongs	O
to	O
the	O
class	O
of	O
local	B-Algorithm
search	I-Algorithm
algorithms	I-Algorithm
,	O
which	O
take	O
a	O
tour	O
(	O
Hamiltonian	O
cycle	O
)	O
as	O
part	O
of	O
the	O
input	O
and	O
attempt	O
to	O
improve	O
it	O
by	O
searching	O
in	O
the	O
neighbourhood	O
of	O
the	O
given	O
tour	O
for	O
one	O
that	O
is	O
shorter	O
,	O
and	O
upon	O
finding	O
one	O
repeats	O
the	O
process	O
from	O
that	O
new	O
one	O
,	O
until	O
encountering	O
a	O
local	O
minimum	O
.	O
</s>
<s>
As	O
in	O
the	O
case	O
of	O
the	O
related	O
2-opt	B-Algorithm
and	O
3-opt	B-Algorithm
algorithms	O
,	O
the	O
relevant	O
measure	O
of	O
"	O
distance	O
"	O
between	O
two	O
tours	O
is	O
the	O
number	O
of	O
edges	O
which	O
are	O
in	O
one	O
but	O
not	O
the	O
other	O
;	O
new	O
tours	O
are	O
built	O
by	O
reassembling	O
pieces	O
of	O
the	O
old	O
tour	O
in	O
a	O
different	O
order	O
,	O
sometimes	O
changing	O
the	O
direction	O
in	O
which	O
a	O
sub-tour	O
is	O
traversed	O
.	O
</s>
<s>
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
is	O
adaptive	O
and	O
has	O
no	O
fixed	O
number	O
of	O
edges	O
to	O
replace	O
at	O
a	O
step	O
,	O
but	O
favours	O
small	O
numbers	O
such	O
as	O
2	O
or	O
3	O
.	O
</s>
<s>
For	O
a	O
given	O
instance	O
of	O
the	O
travelling	B-Algorithm
salesman	I-Algorithm
problem	I-Algorithm
,	O
tours	O
are	O
uniquely	O
determined	O
by	O
their	O
sets	O
of	O
edges	O
,	O
so	O
we	O
may	O
as	O
well	O
encode	O
them	O
as	O
such	O
.	O
</s>
<s>
In	O
the	O
main	O
loop	O
of	O
the	O
local	B-Algorithm
search	I-Algorithm
,	O
we	O
have	O
a	O
current	O
tour	O
and	O
are	O
looking	O
for	O
new	O
tour	O
such	O
that	O
the	O
symmetric	O
difference	O
is	O
not	O
too	O
large	O
and	O
the	O
length	O
of	O
the	O
new	O
tour	O
is	O
less	O
than	O
the	O
length	O
of	O
the	O
current	O
tour	O
.	O
</s>
<s>
The	O
key	O
idea	O
of	O
the	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
algorithm	I-Algorithm
is	O
to	O
remove	O
from	O
this	O
tree	O
all	O
alternating	O
trails	O
which	O
have	O
gain	O
.	O
</s>
<s>
As	O
an	O
enumeration	O
algorithm	O
this	O
is	O
slightly	O
flawed	O
,	O
because	O
it	O
may	O
report	O
the	O
same	O
trail	O
multiple	O
times	O
,	O
with	O
different	O
starting	O
points	O
,	O
but	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
does	O
not	O
care	O
because	O
it	O
mostly	O
aborts	O
the	O
enumeration	O
after	O
finding	O
the	O
first	O
hit	O
.	O
</s>
<s>
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
is	O
not	O
satisfied	O
with	O
just	O
having	O
found	O
a	O
closed	O
alternating	O
trail	O
of	O
positive	O
gain	O
,	O
it	O
additionally	O
requires	O
that	O
is	O
a	O
tour	O
.	O
</s>
<s>
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
also	O
restricts	O
the	O
search	O
in	O
various	O
ways	O
,	O
most	O
obviously	O
regarding	O
the	O
search	O
depth	O
(	O
but	O
not	O
only	O
in	O
that	O
way	O
)	O
.	O
</s>
<s>
The	O
basic	O
form	O
of	O
the	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
algorithm	I-Algorithm
not	O
only	O
does	O
a	O
local	B-Algorithm
search	I-Algorithm
counterpart	O
of	O
the	O
above	O
enumeration	O
,	O
but	O
it	O
also	O
introduces	O
two	O
parameters	O
that	O
narrow	O
the	O
search	O
.	O
</s>
<s>
The	O
literature	O
on	O
the	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
heuristic	I-Algorithm
uses	O
the	O
term	O
sequential	O
exchanges	O
for	O
those	O
that	O
are	O
described	O
by	O
a	O
single	O
alternating	O
trail	O
.	O
</s>
<s>
The	O
smallest	O
non-sequential	O
exchange	O
would	O
however	O
replace	O
4	O
edges	O
and	O
consist	O
of	O
two	O
cycles	O
of	O
4	O
edges	O
each	O
(	O
2	O
edges	O
added	O
,	O
2	O
removed	O
)	O
,	O
so	O
it	O
is	O
long	O
compared	O
to	O
the	O
typical	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
exchange	O
,	O
and	O
there	O
are	O
few	O
of	O
these	O
compared	O
to	O
the	O
full	O
set	O
of	O
4-edge	O
exchanges	O
.	O
</s>
<s>
The	O
literature	O
is	O
vague	O
on	O
exactly	O
what	O
is	O
included	O
in	O
the	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
heuristic	I-Algorithm
proper	O
,	O
and	O
what	O
constitutes	O
further	O
refinements	O
.	O
</s>
<s>
The	O
Lin	B-Algorithm
–	I-Algorithm
Kernighan	I-Algorithm
heuristic	I-Algorithm
checks	O
the	O
validity	O
of	O
tour	O
candidates	O
at	O
two	O
points	O
:	O
obviously	O
when	O
deciding	O
whether	O
a	O
better	O
tour	O
has	O
been	O
found	O
,	O
but	O
also	O
as	O
a	O
constraint	O
to	O
descending	O
in	O
the	O
search	O
tree	O
,	O
as	O
controlled	O
via	O
the	O
infeasibility	O
depth	O
.	O
</s>
