Search code examples
pythonmathematical-optimizationlinear-programming

How to write cost slabs in objective function of Linear Programming?


Let say I have a variable Income per month, over a period of 1 to 12 months my total Income is 1700 $, I want to minimize tax on this income. How should I write this objective function in abstract algebra form Z = 1000 * 0.05 + 500 * 0.10 + 200 * 0.15

basically I want to put slab wise tax on total income, any suggestion ?

I have three slabs 0-1000, 1000-1500, >1500 tax per slab 0.05, 0.10, 0.15


Solution

  • Here is an example implementation in python:

    def tax(x):
        if (x <= 1000):
            return x * 0.05
        elif (x <= 1500):
            return 50 + (x - 1000) * 0.1
        else:
            return 100 + (x - 1500) * 0.15
    
    income = 100
    while (income < 5000):
        print ("Taxes on income of " + str(income) + ": " +  str(tax(income)))
        income += 250
    

    You could parameterize the steps and rates if you wanted.

    If you need to regress a piecewise function from results, you can use numpy.piecewise.