algorithm - Methods of comparing prices -


i create list of products wish buy. let's given unique reference code. have list of suppliers can buy , convenience each supplier uses same reference code each product.

some suppliers charge shipping. others charge shipping if spend less amount. suppliers discount products if buy them more once there may restrictions (such 1 1 free).

it extremely easy take list of products want buy , tally total cost buy of them each supplier. want though create script work out whether better split order.

for example:

retailer charges:
product - £5
product b - £10
product c - £10
product d - £10
shipping - £5

retailer b charges:
product - £5
product b - £12
product c - £12
product d - £30
shipping - £5 - free if spending £20 or more

in case, if wanted buy product c only, cheapest retailer a.

if wanted buy:
1x product a
2x product b
1x product d

the cheapest retailer b (because of free delivery) products , b , split order , purchase product d retailer (as price delivery lower delivery included).

so in head it's not complex task , can work out on paper. question is, how translate code. i'm not looking code - guidance on theory of how implement it.

if restrict problem choosing vendor buy each product from, , vendor-dependent reduction in shipping cost if spend vendor-dependent amount, can formulate problem integer linear program (ip or ilp), strategy problems suspected np-hard because there has been lot of research , software packages developed try solve ilp fast in practice. can read linear programming , ilp online. ilp problem instance has variables, linear constraints on variables, , linear objective want minimize or maximize. here's ilp set problem:

for each product vendor sells, have 1 vendor-product variable tells how many of product purchase vendor. each of these variables have constraint variable must >= 0. each product wish buy, have constraint sum of vendor-product variables product must equal total number of product wish buy.

then each vendor offers shipping discount, have shipping discount variable either 0 if don't discount, or 1 if do. each 1 of these shipping discount variables, have constraints variable must >=0 , <= 1; have constraint says when multiply each vendor-product variable vendor vendor's price product, , add vendor (so total amount spending @ vendor), amount >= vendor's shipping discount variable multiplied vendor's minimum amount need spend discount.

you have each vendor vendor variable 1 if use vendor, , 0 if don't. each of these vendor variables a, have constraints 1 >= > =0 , each vendor-product variable b vendor, have constraint >= b/n, n total number of items want buy.

finally objective want maximize made multiplying each vendor-product variable vendor's price product, adding (call part of objective x), , multiplying each vendor's shipping discount variable shipping cost reduction if discount, adding (call part of objective y), , multiplying each vendor variable vendor's undiscounted shipping cost, adding (call part of objective z) objective minimize x - y + z. need define ilp, can feed ilp solver , solution quickly.


Comments