# How can I have minimum amount of resources wasted in this resource allocation problem?

I have a demand, $$d$$

I also have supply from 1000 sources. The supplies from those $$N$$ (for example, $$N=1000$$) sources are given by

$$s_1,s_2,s_3,\cdots,s_N$$. So,the total supply is : $$s_1+s_2+\cdots+s_N$$

How can I meet the demand with least amount of resources wasted?

so, the objective is to have minimum $$(d-supply)$$. The supply can come from any number of sources.

A heuristic approach is welcome.

• I think you meant to minimize supply minus demand instead of the other way around. – RobPratt Sep 7 '20 at 13:54

## 1 Answer

Introduce a binary variable $$x_i$$ for each supply and nonnegative waste variable $$w$$. The problem is to minimize $$w$$ subject to $$\sum_i s_i x_i -w= d$$.

A heuristic approach is to sort the supplies in decreasing order and greedily take the largest ones until the sum satisfies the demand. Then, if the demand is not met exactly, exchange the last added supply with the smallest remaining supply that satisfies the demand.

• Thanks. In fact, I am looking for some heuristic approach. – dipak narayanan Sep 7 '20 at 13:59
• will $\min\hspace{3mm}\sum_{n=1}^Nx_n$ subject to $d\le \sum_{n=1}^N s_nx_n$ do the job? – dipak narayanan Sep 7 '20 at 14:01
• You need $s_n x_n$ in the summand for the objective. With that correction, this is equivalent to my suggestion but with more coefficients and objective parallel to the constraint. – RobPratt Sep 7 '20 at 14:05