比较价格的方法 [英] Methods of comparing prices

查看:160
本文介绍了比较价格的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建的,我想购买的产品清单。比方说,他们都赋予一个唯一的参考code。我有供应商,我可以买一个列表,并为方便各供应商使用相同的参考code每个产品。

I will create a list of products that I wish to buy. Let's say they are all given a unique reference code. I have a list of suppliers I can buy from and for convenience each supplier uses the same reference code for each product.

一些供应商收取运费。如果你花不到一定量的其他人只收取运费。一些供应商折扣的某些产品,如果你购买他们不止一次,但可能有限制(如1送1)。

Some suppliers charge shipping. Others only charge shipping if you spend less than a certain amount. Some suppliers discount certain products if you buy them more than once but there may be restrictions (such as by 1 get 1 free).

这是非常容易把产品我想购买,并从中总结出它的成本从每一个供应商购买所有的人的总名单。我想要做的虽然是创建一个脚本来计算出它是否会更好地分割订单。

It is extremely easy to take the list of products I want to buy and tally up the total it would cost to buy all of them from each supplier. What I want to do though is create a script to work out whether it would be better to split the order.

例如:

零售商收费:
产品A - £5
产品B - £10个
产品C - £10个
D产品 - £10个
海运 - £5

Retailer A charges:
Product A - £5
Product B - £10
Product C - £10
Product D - £10
Shipping - £5

零售商乙费用:
产品A - £5
产品B - £12个
产品C - £12个
D产品 - £30个
海运 - £5 - 免费的,如果花£20以上

Retailer B charges:
Product A - £5
Product B - £12
Product C - £12
Product D - £30
Shipping - £5 - free if spending £20 or more

在这种情况下,如果我想购买产品C只,最便宜的是从零售商。

In this case, if I wanted to buy Product C only, the cheapest would be from retailer A.

如果我想买:
1个产品A
2个产品B
1个D产品

If I wanted to buy:
1x Product A
2x Product B
1x Product D

最便宜的是零售商B(因为免费送货)产品A和B,并再拆来自零售商的订单和采购的产品D(因为即使交付价格显著甚至更低交货含税)。

The cheapest would be retailer B (because of the free delivery) for products A and B and to then split the order and purchase product D from retailer A (as the price even with delivery is significantly lower even with delivery included).

所以,在我的脑海这不是一个复杂的任务,我可以解决这个问题很容易在纸上。现在的问题是,我怎么把它理解code。我不是找code做的 - 在如何实现它的理论只是一些指导

So in my head it's not a complex task and I can work it out very easily on paper. The question is, how I would translate this into code. I'm not looking for the code to do it - just some guidance on the theory of how to implement it.

推荐答案

如果我们限制的问题,简单地选择购买从每个产品的供应商,你会得到的运输成本与供应商依赖性降低,如果你花了于供应商相关的量,那么你可以制定你的问题,作为一个整数线性规划(IP或ILP),这是问题的一个很好的策略,怀疑是NP难是因为有大量的开发研究和软件包,尝试解决ILP快速在实践中。你可以阅读有关线性规划ILP在线。一个ILP问题的实例有变量,线性约束的变量,一个线性目标要最小化或最大化。这里的ILP设置您的问题:

If we restrict the problem to simply choosing which vendor to buy each product from, and you get a vendor-dependent reduction in shipping cost if you spend a vendor-dependent amount, then you can formulate your problem as an integer linear program (IP or ILP), which is a good strategy for problems suspected to be NP-hard because there has been a lot of research and software packages developed that try to solve ILP fast in practice. You can read about linear programming and ILP online. An ILP problem instance has variables, linear constraints on the variables, and a linear objective you want to minimize or maximize. Here's the ILP set up for your problem:

对于每个供应商销售产品,你有一个供应商的产品变量,告诉多少的产品,你会购买从供应商。对于这些变量的,你有一个约束变量必须> = 0。对于您想购买的每个产品,你有一个约束,所有的供应商的产品变量为产品之和必须等于的总数产品,你想购买。

For each product that a vendor sells, you have one vendor-product variable that tells how many of the product you will purchase from the vendor. For each of these variables you have a constraint that the variable must be >= 0. For each product you wish to buy, you have a constraint that the sum of all the vendor-product variables for that product must equal the total number of the product that you wish to buy.

然后对于每个供应商,提供了一个航运折扣,你有一个航运折扣的变量,这将是0,如果你没有得到的折扣,或1如果你这样做。对于这些航运折扣变量中的每一个,你有约束变量必须> = 0和< = 1;你也有一个约束说,当你的供应商的供应商的价格,该产品乘以每个供应商产品的变量,并添加一切,为供应商(所以你得到你所花的供应商的总金额),此量> =供应商的出货折扣变量乘以供应商的,你需要花费来获得折扣最低金额。

Then for each vendor that offers a shipping discount, you have a shipping discount variable which will be either 0 if you don't get the discount, or 1 if you do. For each one of these shipping discount variables, you have constraints that the variable must be >=0 and <= 1; you also have a constraint that says when you multiply each vendor-product variable for the vendor by the vendor's price for that product, and add it all up for the vendor (so you get the total amount you are spending at the vendor), this amount is >= the vendor's shipping discount variable multiplied by the vendor's minimum amount you need to spend to get the discount.

您还可以对每个供应商0厂商变量为1,如果你使用的供应商,如果你不这样做。对于每个厂商变量,你必须限制1> = A> = 0,也为供应商的每个供应商的产品变量B,你有一个约束A> = B / N,其中N是项目总数你想购买。

You also have for each vendor a vendor variable which is 1 if you use the vendor, and 0 if you don't. For each of these vendor variables A, you have constraints 1 >= A > =0 and also for each vendor-product variable B for the vendor, you have a constraint A >= B/N, where N is the total number of items you want to buy.

最后,你想最大化是由供应商的价格是产品的每一个供应商的产品变量乘做的目的,加入了这一切(称这部分目标的X),再由每个供应商的出货折扣变量乘以运输成本降低,如果你拿到的折扣,你得到的,添加了这一切(称这部分目标的Y),并乘以供应商的未贴现的运费每家供应商的变量,加入了这一切(称这部分目标的Z ),那么你的目标只是尽量减少X - Y + Z。这是所有你需要定义ILP,那么你可以把它送入一个ILP求解器,并希望得到一个快速的解决方案。

Finally the objective you want to maximize is made by multiplying each vendor-product variable by the vendor's price for that product, adding it all up (call this part of the objective X), and then multiplying each vendor's shipping discount variable by the shipping cost reduction you get if you get the discount, adding it all up (call this part of the objective Y), and multiplying each vendor variable by the vendor's undiscounted shipping cost, adding it all up (call this part of the objective Z) then your objective is simply to minimize X - Y + Z. This is all you need to define the ILP, then you can feed it into an ILP solver and hopefully get a solution quickly.

这篇关于比较价格的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆