Last active
May 27, 2021 15:16
-
-
Save joshua-taylor/621f709d0202fc9d733c2a961c285bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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