Может ли кто-нибудь помочь найти лучший подход, чем жадные алгоритмы к этой задаче оптимизации?
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
Gerry Schmitz
https://www.codeproject.com/Articles/1183168/Solving-optimization-problems-with-Microsoft-Solve