1

So, I have an optimization problem that can perhaps be solved by linear programming (with PuLP?). My experience with this line of work is limited so perhaps another solution would be better.

The problem is as follows:

There are 37 items that need to be bought. Each item must be bought in a specific quantity, in a specific color. For each item I have a variable number of stores that sell that item. There are about 8000 stores that combined sell the 37 items. There's not a single store that sells all 37 items. Each store has a variable quantity of that item available (if it is available) and a variable price. Also, each store has a minimum-buy amount.

In python I have two dataframes that should have all the information that I need. (store names are 'blurred')

wanted.head()
    item_color_id   item_id item_qty
0   86              21837   1
1   5               2431    2
2   11              2444    6
3   11              2476    4
4   3               2654    2

stores.head()
    item_color_id   item_id store_min_buy   store_name  store_price store_qty
0   86              21837   20.00           fda         0.18        100
1   86              21837   10.00           asdfa       0.52        89
2   86              21837   10.00           ghsde       0.55        64
3   86              21837   9.14            j5rs        0.41        31
4   86              21837   10.00           pjvds       0.44        26

The stores dataframe is already preprocessed so it does not contain any NaN values. Note that store_min_buy is the minimum amount of money that needs to be spend in that store.

The challenge is to minimize the cost of buying the 37 items. In addition to that I need the actual solution: Which items need to be bought from which stores.

2
  • Does color mean anything special or can we treat a combination of item id and color id as a new unique item? Does the store_min_buy apply to just the one thing or across the sum of all the things you buy at this store? What does it even mean that there's a min_buy of 9.14, can I buy 9 and 14% of an item somehow? Commented Oct 30, 2015 at 9:49
  • @harold I'm sorry for the confusion. To your first question: yes, the combination of item_id and color_id makes a new unique item. store_min_buy is the minimum amount of money need to be spend in that store. So a min_buy of 9.14 means that at least 9.14 euro/dollar need to be spend at that store. Commented Oct 30, 2015 at 10:00

1 Answer 1

2

The min_buy constraint is a bit annoying, the rest is more obvious.

So have some decision variables:

x[i,j] = number of item i to buy at store j
u[j]   = store j is used at all

Then the obvious constraint:

sum(x[i,any]) >= wanted[i]  (>= because the min_buy constraint may force you to buy extra)

The min_buy constraint. Well this is annoying, because it's sort of like a conditional constraint.

sum(x[any,j]) <= M * u[j]  (ban u[j]=0 if some item is bought here)
min_buy[j] * u[j] <= sum(x[i,j] * price[i]) (force buying enough)

You can transform that to a legal constraint format the obvious way. M is some big number, big enough that the constraint will be always satisfied if a store is used (so at least as big as the maximum number of items you might but there).

I don't really like this model. The linear phase will abuse that M as much as it can, and probably trivially satisfy the last two constraints by choosing u tiny but nonzero. That will cause a lot of grief in the integer phase because it means the fractional solution will probably underestimate the cost by a lot.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.