Context: I am a CS student currently in a non-CS internship (logistics, supply chain).

My manager wants to leverage my knowledge of programming to build a program to solve the following problem:

As a company, we have different units of product that we have to distribute to our stores. Some stores are good at selling, others not so much. Sometimes, we don't have enough of our product to give every store what they need, therefore, we have to decide where to send the product so that it sells as fast as possible / makes the most profit. So the inputs would be the historical and current data of the performance of each store, as well as how many units we want to distribute and the output would be how many units to allocate in each store.

My approach is the following: Using historical data, use scipy.curve_fit function to fit the data of each store to a distribution (how do I pick which distribution to fit?) with sales and level of inventory for a day as the axis for each store. Then, from this function, construct a multi variable global profit function, and then maximize this function with the constraints (how many units we have to distribute) using scipy.optimize.

So for example, if we decide that a simple square root function fits our data the best, and after using scipy.cure_fit we estimate that for store A Profit = $2\sqrt{3x}$ and for Store B Profit = $5\sqrt{y}$, where $x$ and $y$ are the number of units in each store, then the global profit function would be Profit = $2\sqrt{3x} + 5\sqrt{y}$. If we only have 500 units to allocate for example, then we have to optimize the function $2\sqrt{3x} + 5\sqrt{y}$ with the constraint that $x + y \leq 500$.

My questions:

  1. Does my general approach make sense? Is there a better way to approach this?

  2. scipy.curve_fit takes a distribution for fitting. What is the best way to pick a distribution given my data?

  3. In my approach, I use SciPy a lot. Are there other technologies that would be better to use?

  4. How can I include lead time (time for the product to get to the store) in this model?

  5. Would Machine Learning be of possible use here? My manager is interested in ML and I think it would be kinda cool to include it somehow.

  • 2
    $\begingroup$ Whatever you do, just call it Machine Learning. Instead of fitting the data, you say the (same) algorithm learned your model - now it's Machine Learning. Yes, a lot (not all) of what is called Machine Learning is that shallow in terms of its Machine Learningness. A lot of old-fashioned optimization is now called Machine Learning or A.I. - after all, an optimization algorithm learns a heck of a lot about the function it is optimizing. $\endgroup$ Jun 25, 2019 at 20:33
  • $\begingroup$ Do different stores have different prices for the same product? How do you define what a store currently needs (i.e., is that based on current inventory and the time until you get the next shipment of products to distribute?). $\endgroup$ Jun 27, 2019 at 1:16
  • $\begingroup$ @ZoharStrinka every store has the same price for the products. Well, what it needs its subjective. As a business we want to maximize profits / how fast we can turn inventory. So we would want to send the product where this will most likely happen. $\endgroup$
    – Marco
    Jun 27, 2019 at 16:11

3 Answers 3


This is a very broad question and there is a lot going on here. So I will provide a few initial thoughts; hopefully others will chime in as well; and then you might want to post more specific questions, which will be easier for us to provide more concrete answers to.

The approach you outlined is focused on the inventory level (IL). It assumes that there is a function $f(x)$, which gives the (expected) profit if the inventory level is $x$. You are suggesting a statistical approach for estimating the $f(x)$ functions, and then an optimization approach to allocate the products among the stores according to the various stores' $f(x)$ functions.

A more standard supply chain-oriented approach would be instead to focus on the demand, or really on its probability distribution, at each store. Then use cost/revenue parameters to build a model $g(x)$ of the expected profit as a function of the inventory level; and then you could allocate the products accordingly, again using an optimization model. I'm not sure whether this approach will be better than yours, but here are a few advantages going for it:

  • It uses historical data to estimate a random variable (the demand) rather than something that is a function of the random variable (the profit).
  • It draws on well-established methods from the supply chain literature.
  • If the historical data contains profit data, it is probably an aggregate number that reflects many things that happened that affected the profit, such as promotions, bad weather, a sale by a competitor, a surprise endorsement from a Twitter celebrity, whatever. That makes your function $f(x)$ very noisy. But in the demand-centric approach, you build the function $g(x)$ from more primitive elements—the demand distribution and per-unit cost or revenue parameters, which are easier to estimate.

One problem with the demand-centric approach is censoring: If the store ran out of inventory, then you don't know what the actual demand was, you only know that the demand was $\ge$ the inventory level. There are methods to deal with this (google "censored demand data") but they are imperfect, obviously.

Essentially what I am proposing is as follows:

  1. Estimate the demand distribution at each store using historical data and any forecasting/estimation techniques you like. If you want to use ML, this is a perfect spot to do it.
  2. Estimate the per-unit parameters like the cost to buy each item from the supplier, the cost to hold each item in inventory, the revenue from selling each item, etc. This might require talking to the company's supply chain managers and/or accountants. But most companies are used to thinking about these parameters; it shouldn't be a foreign concept.
  3. The classical newsvendor problem would give you the optimal inventory level at each store if there were no constraints on how much you could send to each store. But of course there are, in particular you have a finite number of units that you want to distribute to the stores. Therefore:
  4. Build some kind of optimization model for doing the allocation. The model would basically have the form $$\begin{align} \text{maximize} \quad & \mathbb{E}\left[\sum_n g_n(x_n)\right] \\ \text{subject to} \quad & \sum_n x_n = [\text{number of units available}] \end{align}$$ where $x_n$ is the inventory level allocated to store $n$ and $g_n(\cdot)$ is the profit function for store $n$. ($g_n(x)$ is essentially the newsvendor expected-profit function.) The objective function will be concave, but since this is a maximization problem, it might still be tractable. You can formulate it in a modeling language like AMPL or GAMS, or using a package like PuLP for Python, and then solve it using a commercial solver like CPLEX or Gurobi, or an open-source solver.

Hope this helps, and good luck!

  • $\begingroup$ Hey thank you thats a great response ! One quick question tho, which data would I use to find the demand distribution? Would it no be sales?And if so, how does it protect from "noisy" data due to seasonal changes and such? And just to clarify, when you say demand distribution, you mean something like units demanded on the x axis and the pdf on the y-axis? How would I obtain such a distribution? $\endgroup$
    – Marco
    Jun 27, 2019 at 16:07
  • $\begingroup$ Yes, demand distribution is basically probability of each demand value, so units demanded on the x-axis and pdf on the y-axis. You can estimate the distribution by building a simple histogram from historical data, but there are more sophisticated approaches too. If there are seasonal changes, etc., you will need to "de-seasonalize" or segregate the time periods based on the season. If you have further questions about these, you should post them as separate questions. But do some digging about these topics on your own and see where you get. $\endgroup$ Jun 27, 2019 at 19:24
  • $\begingroup$ @LarrySnyder610 If I may ask: is this the sort of problem that a person working in OR/Industrial Engineering would solve on a day to day basis? Or is this a very simple, baby problem? $\endgroup$
    – Ovi
    Dec 3, 2020 at 14:33
  • $\begingroup$ This is absolutely the type of problem that a "real-world" OR/IE person might work on. It's not a baby problem. $\endgroup$ Dec 3, 2020 at 16:00

One possible way to estimate the distribution function or fitting curve from the historical data is to use ‎some of the statistical software such as R or Minitab. They have some facilities (and also easy to use) ‎to estimate them. AFAIK, they have a free or academic licence.

For optimization, ‎if you don't have any force to construct a global profit function (as you said), ‎you might use some of the inventory optimization models with your own constraints ‎and using the optimization software (as Larry said) to solve the model.


Your approach could make sense if a customer's likelihood to buy depends on the number of units on the shelf. Typical inventory optimization assumes people arrive planning to buy a product or not, and either it's available when they get there or not.

If management does think that customer demand depends on inventory, you have a good use case for ML to see if they are correct. You would use some stats and regression models to demonstrate whether inventory being 5 is different than 50. At that point, you can decide on your next step.

If inventory level does matter, I still probably wouldn't try to infer unique profit functions for each store. I would instead add some kind of heuristic constraint like "any store we stock should have at least $1/2$ the optimal order-up-to level of inventory." If inventory level doesn't matter, you would follow something closer to Larry's proposed approach.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.