<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdulaziz Abdujalilov</title>
    <description>The latest articles on DEV Community by Abdulaziz Abdujalilov (@abdulazizbalu).</description>
    <link>https://dev.to/abdulazizbalu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3962250%2Fd9128fbc-02e5-42a0-93f8-3fc2b1b09883.jpeg</url>
      <title>DEV Community: Abdulaziz Abdujalilov</title>
      <link>https://dev.to/abdulazizbalu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdulazizbalu"/>
    <language>en</language>
    <item>
      <title>How I built a quantum-inspired route optimizer in pure Python (no quantum hardware)</title>
      <dc:creator>Abdulaziz Abdujalilov</dc:creator>
      <pubDate>Mon, 01 Jun 2026 07:55:53 +0000</pubDate>
      <link>https://dev.to/abdulazizbalu/how-i-built-a-quantum-inspired-route-optimizer-in-pure-python-no-quantum-hardware-5bb1</link>
      <guid>https://dev.to/abdulazizbalu/how-i-built-a-quantum-inspired-route-optimizer-in-pure-python-no-quantum-hardware-5bb1</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Ever wondered how delivery companies figure out the best route for their drivers? &lt;br&gt;
It's called the Travelling Salesman Problem (TSP) — and it's brutally hard to solve &lt;br&gt;
optimally as the number of stops grows.&lt;/p&gt;

&lt;p&gt;I wanted to explore quantum-inspired approaches to this problem — algorithms that &lt;br&gt;
borrow ideas from quantum physics but run on regular CPUs. No quantum computer needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is QUBO?
&lt;/h2&gt;

&lt;p&gt;QUBO stands for Quadratic Unconstrained Binary Optimization. It's a mathematical &lt;br&gt;
framework where you express any optimization problem as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Binary variables (0 or 1)&lt;/li&gt;
&lt;li&gt;A matrix of coefficients&lt;/li&gt;
&lt;li&gt;Minimize the total "energy"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quantum annealers (like D-Wave) solve QUBO natively. But quantum-inspired algorithms &lt;br&gt;
simulate this classically — and that's exactly what I built.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;quasar-solver&lt;/strong&gt; — a pure Python QUBO optimizer with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;QUBO&lt;/code&gt; class: sparse dict representation, energy computation&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SimulatedAnnealingSolver&lt;/code&gt;: multiple restarts, tunable beta schedule&lt;/li&gt;
&lt;li&gt;TSP converter: encodes city routing as a QUBO matrix&lt;/li&gt;
&lt;li&gt;Interactive web demo — click to place cities, watch the solver find the route&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔴 &lt;strong&gt;&lt;a href="https://abdulazizbalu.github.io/quasar-solver/demos/web_demo.html" rel="noopener noreferrer"&gt;Live Demo&lt;/a&gt;&lt;/strong&gt; — no install needed, runs in browser&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;quasar_solver&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QUBO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SimulatedAnnealingSolver&lt;/span&gt;

&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QUBO&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# linear term
&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# linear term  
&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# quadratic term
&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimulatedAnnealingSolver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;best_sample&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# [1, 1]
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;best_energy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# -2.0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How TSP becomes QUBO
&lt;/h2&gt;

&lt;p&gt;The key insight: use one-hot encoding. Variable &lt;code&gt;x[i][t] = 1&lt;/code&gt; means city &lt;code&gt;i&lt;/code&gt; &lt;br&gt;
is visited at timestep &lt;code&gt;t&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Two constraint types become penalty terms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Each city visited exactly once&lt;/li&gt;
&lt;li&gt;Exactly one city per timestep&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The solver minimizes total distance + penalties simultaneously.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;On a 6-city random instance, the solver finds a valid tour in under 10ms on CPU. &lt;br&gt;
The web demo uses 2-opt moves in JavaScript for instant visual feedback.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;VRP support (multiple vehicles, capacity constraints)&lt;/li&gt;
&lt;li&gt;Schedule optimization demo&lt;/li&gt;
&lt;li&gt;FastAPI deployment&lt;/li&gt;
&lt;li&gt;PyPI release (&lt;code&gt;pip install quasar-solver&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  GitHub
&lt;/h2&gt;

&lt;p&gt;⭐ &lt;a href="https://github.com/abdulazizbalu/quasar-solver" rel="noopener noreferrer"&gt;github.com/abdulazizbalu/quasar-solver&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback welcome — especially on penalty tuning and SA parameters!&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>productivity</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
