首页 > 解决方案 > 多产品定价问题的约束优化

问题描述

我需要一些帮助来制定 Python 中的约束价格优化问题并选择正确的算法和库。

考虑要出售的 n 个数量 ( 客观的),其中每个数量取决于销售价格。目标是通过为每个数量设置最优价格来最大化 n 个数量的总和。让可能价格的向量由三个价格组成价格向量。最优价格分配的最终收益必须满足一个简单的约束。

以下提供了问题的数学公式:

客观的

受以下收入约束:

约束

其中c是一个取正值的常数。

让我提供一个包含 2 个数量和 2 个价格的简单代码示例:

# two prices
p1 = 5
p2 = 10

# q1 depending on price 
q1_p2 = 10
q1_p1 = 22

# q2 depending on price 
q2_p2 = 10
q2_p1 = 15

# Manual calculation of quantity and revenue for all possible price allocations

allocation1_quantity = q1_p2 +  q2_p2
allocation1_revenue = p2 * q1_p2 +  p2 * q2_p2

allocation2_quantity = q1_p2 +  q2_p1
allocation2_revenue = p2 * q1_p2 +  p2 * q2_p2

allocation3_quantity =  q1_p1 +  q2_p2
allocation3_revenue = p1 * q1_p1 +  p2 * q2_p2

allocation4_quantity = q1_p1 +  q2_p1
allocation4_revenue = p1 * q1_p1 +  p1 * q1_p2

# print results

print(allocation1_quantity, allocation1_revenue)
print(allocation2_quantity, allocation2_revenue)
print(allocation3_quantity, allocation3_revenue)
print(allocation4_quantity, allocation4_revenue)

20 200
25 200
32 210
37 160

 

现在,如果我们设置,例如,c=200最佳解决方案是为 q1 设置 p1,为 q2 设置 p2,因为这种分配 (32, 210) 在满足约束的同时最大化总量。

考虑到可能的组合数量在数量和价格的数量上迅速爆炸,我需要实现一个可以解决这个问题的算法。

任何关于合适的python库来解决这个问题的想法和使用上面的玩具示例的代码示例将不胜感激!

标签: pythonalgorithmoptimization

解决方案


There are a few options for libraries that can do this:

For smaller problems both Google OR-Tools or Scipy optimize can solve linear programming problems - I personally find the syntax of OR-Tools more intuitive but if you're more familiar with scipy in general that may be easier. Both of those links show code samples.

For larger problems you can use the Python library to interface with IBM Watson Decision Optimization although there's a limited amount you can do with free "trial" account.

For completeness there's also Gurobi but I'm not sure if they have a free/trial tier and licenses are very expensive so probably not the first solver to try.


推荐阅读