Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose there are 5 components, and there is a random supply of each component:

-------------------
| Comp | Quantity |
|------|----------|
| C1   | 500      |
| C2   | 700      |
| C3   | 400      |
| C4   | 1000    |
| C5   | 850      |
-------------------
And my factory can produce 25 different products, each of them needing a different number of each component:

--------------------------------------------
| Product | Price | C1 | C2 | C3 | C4 | C5 |
|---------|-------|----|----|----|----|----|
| P1      | $450  | 6  | 7  | 2  | 9  | 4  |
| P2      | $300  | 8  | 5  | 3  | 3  | 7  |
| P3      | $100  | 2  | 4  | 9  | 4  | 6  |
| P4      | $500  | 4  | 1  | 0  | 9  | 8  |
| ..         | ..            | ..  | .. |   .. | .. | ..    |
--------------------------------------------
I need to determine how many of each product do I need to build in order to maximize the final revenue while not exceeding the supply of each component?

What I have tried:

<pre>Best algorithm I have written so far loops through each product and finds the maximum quantity of it can be produced, and then takes the product with highest revenue (price * max quantity), then removed that product from the list and subtracts that number of components from supply, then repeats the process with the rest of the products.

Here is the pseudo code I have so far:

foreach (var product in productList)
{
    product.MaxQty = MaxQty(product, supply);
    product.Revenue = product.Price * product.MaxQty;
}
// Take product with highest Revenue;
// Update supply;
// Repeat the loop;

I know this is not the best approach because sometimes it’s not optimal to take the product with highest revenue, because my goal is to have the greatest sum of all products produced instead of just one product at a time
Posted
Updated 23-Jun-19 12:00pm
Comments
[no name] 23-Jun-19 14:43pm    
https://www.codeproject.com/Articles/1183168/Solving-optimization-problems-with-Microsoft-Solve

1 solution

Quote:
Can someone help find a better approach than a greedy algorithms to this optimization problem?

This kind of problem fit in category Integer Programming/Linear Programming, this a NP-Complete problem (hard problem).
As Gerry said, for you, the easiest way to solve the problem is probably to use the solver in Excel.
Solving optimization problems with Microsoft Solver Foundation[^]
There is no simple solution to this problem, it is a matter for books.
Integer programming - Wikipedia[^]
Linear programming - Wikipedia[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900