<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Salmasarhan on Medium]]></title>
        <description><![CDATA[Stories by Salmasarhan on Medium]]></description>
        <link>https://medium.com/@salmasarhan676?source=rss-7b9f6b8f977c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fzhJR9IlF7S51tcG</url>
            <title>Stories by Salmasarhan on Medium</title>
            <link>https://medium.com/@salmasarhan676?source=rss-7b9f6b8f977c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:58:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@salmasarhan676/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adaptive Budgeting Using Greedy Algorithm]]></title>
            <link>https://medium.com/@salmasarhan676/adaptive-budgeting-using-greedy-algorithm-e8cbb242d091?source=rss-7b9f6b8f977c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8cbb242d091</guid>
            <dc:creator><![CDATA[Salmasarhan]]></dc:creator>
            <pubDate>Tue, 10 Feb 2026 00:26:11 GMT</pubDate>
            <atom:updated>2026-02-10T00:26:11.194Z</atom:updated>
            <content:encoded><![CDATA[<h3>1️⃣ What Adaptive Budgeting really is</h3><p>If one category breaks its budget, where can we safely borrow money from without breaking the total monthly budget?</p><p>So the system must:</p><ol><li>Detect overspending</li><li>Decide if it’s acceptable (emergency vs impulse)</li><li>Choose donor categories</li><li>Reallocate money</li><li>Explain the decision to the user</li></ol><p>This is <strong>constraint-based optimization</strong>, not prediction.</p><h3>2️⃣ Core Data Model (from scratch)</h3><h3>Budget Categories</h3><p>Each category needs:</p><p>- name</p><p>- monthly_limit</p><p>- spent_so_far</p><p>- priority (1 = essential, 3 = optional)</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*QeqqzFWE5QDpuJfu6cQVgQ.png" /></figure><p>3️⃣ Step-by-Step System Logic</p><h3>Step 1: Detect Overspending</h3><p>overspend = spent_so_far — monthly_limit</p><p>If overspend &gt; 0, trigger Adaptive Budgeting.</p><h3>Step 2: Classify the Expense (Rule-Based)</h3><p>You do <strong>not</strong> need NLP or LLMs.</p><p>IF category in [Health, Rent, Utilities]</p><p>→ emergency = true</p><p>ELSE</p><p>→ emergency = false</p><h3>Step 3: Protect the Total Budget (Hard Constraint)</h3><p>SUM(all category limits) = total_monthly_budget</p><p>This must never change.</p><h3>Step 4: Find Donor Categories</h3><p>Rules:</p><ol><li>Only take from <strong>least priorities</strong> categories</li><li>Never drop a category below a minimum safety buffer(30%)</li><li>Prefer lowest-priority categories</li></ol><p>Example buffer:</p><p>minimum_remaining = 30% of category limit</p><h3>Step 5: Reallocation Algorithm (Greedy and Simple)</h3><p>Pseudocode:</p><p>remaining_amount = overspend</p><p>FOR category in flexible_categories_sorted_by_priority:</p><p>available = category.limit — category.spent — minimum_buffer</p><p>IF available &gt; 0:</p><p>transfer = min(available, remaining_amount)</p><p>category.limit -= transfer</p><p>target_category.limit += transfer</p><p>remaining_amount -= transfer</p><p>IF remaining_amount == 0:</p><p>BREAK</p><p>If you run out of donors → warn user instead.</p><h3>4️⃣ Starter Python Implementation</h3><h3>Data Setup</h3><pre>categories = {<br>&quot;Health&quot;: {&quot;limit&quot;: 200, &quot;spent&quot;: 250, &quot;priority&quot;: 1, &quot;flexible&quot;: False},<br>&quot;Food&quot;: {&quot;limit&quot;: 300, &quot;spent&quot;: 270, &quot;priority&quot;: 1, &quot;flexible&quot;: False},<br>&quot;Transport&quot;: {&quot;limit&quot;: 150, &quot;spent&quot;: 120, &quot;priority&quot;: 2, &quot;flexible&quot;: True},<br>&quot;Entertainment&quot;: {&quot;limit&quot;: 200, &quot;spent&quot;: 80, &quot;priority&quot;: 3, &quot;flexible&quot;: True}<br>}</pre><h3>Adaptive Budget Function</h3><pre>def adaptive_budget(categories, target):<br>  overspend = categories[target][&quot;spent&quot;] - categories[target][&quot;limit&quot;]<br>  if overspend &lt;= 0:<br>    return &quot;No adjustment needed&quot;<br>  donors = sorted(<br>    [c for c in categories if categories[c][&quot;flexible&quot;]],<br>    key=lambda x: categories[x][&quot;priority&quot;],<br>    reverse=True<br>  )<br>  for donor in donors:<br>    donor_data = categories[donor]<br>    buffer = 0.3 * donor_data[&quot;limit&quot;]<br>    available = donor_data[&quot;limit&quot;] - donor_data[&quot;spent&quot;] - buffer<br>    if available &gt; 0:<br>      transfer = min(available, overspend)<br>      donor_data[&quot;limit&quot;] -= transfer<br>      categories[target][&quot;limit&quot;] += transfer<br>      overspend -= transfer<br>    if overspend &lt;= 0:<br>      break<br>  if overspend &gt; 0:<br>    return &quot;Warning: Unable to fully rebalance budget&quot;<br>  return categories</pre><pre>result = adaptive_budget(categories, “Health”)<br>print(result)</pre><p>✔ Output matches our scenario:</p><p>“Moved $50 from Entertainment to Health”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8cbb242d091" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>