Skip to content

Instantly share code, notes, and snippets.

@joshua-taylor
Last active May 27, 2021 15:16
Show Gist options
  • Save joshua-taylor/621f709d0202fc9d733c2a961c285bc4 to your computer and use it in GitHub Desktop.
Save joshua-taylor/621f709d0202fc9d733c2a961c285bc4 to your computer and use it in GitHub Desktop.
from scipy.optimize import minimize, LinearConstraint, basinhopping
from math import floor
import numpy as np
#Setting up the pricing amounts for each supplier
supplierPrice = [10.5,11,10]
supplierDiscountAmount = [0.1,0.35,0.05]
supplierDiscountThreshold = [100,260,300]
n_suppliers = len(supplierPrice)
#Our minimum order amount
requiredOrder = 500
#The below function produces a total cost given an order amount for each supplier
#It expects an list input with an order amount for each supplier, eg: [100,100,100]
def func(orders,supplierPrice=supplierPrice,supplierDiscountAmount=supplierDiscountAmount,supplierDiscountThreshold=supplierDiscountThreshold):
totalCost = []
for i,j in enumerate(orders):
itemsAtDiscount = floor(j/supplierDiscountThreshold[i])*supplierDiscountThreshold[i]
discountCost = itemsAtDiscount*supplierPrice[i]*(1-supplierDiscountAmount[i])
nonDiscountCost = (j-itemsAtDiscount)*supplierPrice[i]
totalCost.append(discountCost+nonDiscountCost)
return sum(totalCost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment