<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Heuristic Algorithms on JinerX blog</title><link>https://jinerx.github.io/tags/heuristic-algorithms/</link><description>Recent content in Heuristic Algorithms on JinerX blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>© 2026 Jędrzej Sajnóg</copyright><lastBuildDate>Thu, 19 Mar 2026 19:04:21 +0100</lastBuildDate><atom:link href="https://jinerx.github.io/tags/heuristic-algorithms/index.xml" rel="self" type="application/rss+xml"/><item><title>Local search</title><link>https://jinerx.github.io/learning_log/local-search/</link><pubDate>Thu, 19 Mar 2026 19:04:21 +0100</pubDate><guid>https://jinerx.github.io/learning_log/local-search/</guid><description>&lt;p&gt;Local search is a simple approximation algorithm, which doesn&amp;rsquo;t necessarirly lead to the best result, instead it has a tendency to get stuck in a local minimum. Still if combined with other techniques like for example use of heuristics it can cheaply with low overhead improve the quality of the found solution.&lt;/p&gt;
&lt;p&gt;pseudocode:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;function local_search:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;INPUT: graph of the state G = (V,E), cost function f
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;OUTPUT: found state
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;s &amp;lt;- generate_initial_state()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;while (true): // we might want iteration amount limit in case the state space is infinite and the optimum unreachable
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s&amp;#39; &amp;lt;- s
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; for n in get_neighbors(s):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if f(n) &amp;lt; f(s&amp;#39;):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s&amp;#39; &amp;lt;- n
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if (s&amp;#39; /= s):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; s &amp;lt;- s&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; else:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; break
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;return s&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This pseudocode was written for a graph but can easily be generalized to any general solution space. Simply instead of looking at neighbours of a state we at states we can possibly &amp;ldquo;go to&amp;rdquo;.&lt;/p&gt;</description></item></channel></rss>