kanimbla
kanimbla

Reputation: 890

Constrained Optimization for Multi-Product Pricing Problem

I need some help in formulating a constrained price optimization problem in python and choosing the right algorithm and library.

Consider n quantities (objective) to be sold where each quantity depends on the sales price. The objective is to maximize the sum of n quantities by setting an optimal price for each quantity. Let the vector of possible prices consist of three prices price_vector. The resulting revenue of the optimal price allocation must satisfy a simple constraint.

The following provides the mathematical formulation of the problem:

objective

subject to the following constraint on revenue:

constraint

where c is a constant that takes some positive value.

Let me provide a simple code example with 2 quantities and 2 prices:

# 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

 

Now if we set, for example, c=200 the optimal solution would be to set p1 for q1 and p2 for q2 as this allocation (32, 210) maximizes total quantity while satisfying the constraint.

Considering that the number of possible combinations quickly explodes in the number of quantities and prices I need to implement an algorithm that can address this problem.

Any ideas on suitable python libraries to solve this problem and code example using the toy example from above would be highly appreciated!

Upvotes: 1

Views: 1190

Answers (2)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

If I understand it correctly this is a linear model. It is always best to first write down the mathematical model:

Consider the parameters (data):

 p(k) : prices
 q(i,k) : quantities when price k is used
 r(i,k) = p(k)*q(i,k) : revenue matrix
 c : minimum revenue

Introduce a binary variable x(i,k) indicating which price is selected. Then we have:

 max sum((i,k), q(i,k)*x(i,k))
 subject to 
       sum((i,k), r(i,k)*x(i,k)) >= C
       sum(k, x(i,k)) = 1  for all i
       x(i,k) ∈ {0,1}

This is a simple MIP (Mixed Integer Programming) model. This can be easily modeled with tools like PuLP, OR-tools, CVXPY and solved with any reasonable MIP solver.

Upvotes: 2

Michoel
Michoel

Reputation: 874

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.

Upvotes: 2

Related Questions