How to use constraint programming for optimizing shopping baskets?

☆樱花仙子☆ 提交于 2019-12-04 07:23:32

I have implemented this problem in MiniZinc (a high level constraint programming language): shopping_basket.mzn. It is quite forward and maybe could be used as a model for your Java model.

For the Choco model, have you tried different search strategies? A different strategy may be faster.

By the way, one other Java constraint programming solver you may want to check out is JaCoP.

What you are asking about is in essence the k-knapsack problem. The wikipedia page I liked has a wealth of resources on solutions for it. The problem is however NP-Complete to solve in entirety, so what you may wish to do is look for a close to best solution through simulated annealing or other forms for search through the problem space.

The first thing to remember is that in constraint problems you will probably end up taking a good chunk of time to generate a solution. In your previous example, though five items and ten stores seems small it, in reality, generates a large problem space (on the order of 1e5 not including the added complication of the conditional pricing which further engrosses the problem).

The constraints on the problem are that you buy one of each item. The goal is minimal price. I think what you have is fairly good, though I'm not too sure about bullet points one and two.

  • each price "p xy" is defined in the domain (0, c) where c is the price of the item in this shop
  • only one price in a line should be non zero
  • I would consider amortizing the shipping over the cost of the items bought rather than adding it on as a total value when doing the calculations.

    I'm not too sure this is a k-knapsack problem. The question did mention the words "shopping baskets" but did not specify a capacity to any given shipment. If you specified a maximum shipment size, then the problem starts looking more like a knapsack problem.

    The problem is really just a basic network flow problem with transporation costs on the arcs and costs at the origin. Because you have a clear objective function - minimize transportation + product cost and because there is likely to be only one solution, CP may not be the best approach.

    Consider solving as linear programming problem:

    Min: Transportation + Product Cost

    ST: Total product shipped >= Demand (for each product)

    You might need to develop some piecewise linear equations for the transportation cost, but that shouldn't be a problem.

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!