-3

I have a problem like following to be implemented in java.

item    Profit      Availability    Quality
1         20          6               55 
2         18          8               67 
3         16          7               70 
4         13          9               80 
5         17          8               85

I have data here in above format. I have desired value for Profit, Availability and quality to be achieved.

Aim is to have a solution consisting of items that satisfy my desired values of profit, availability and quality.

My Approach: I have to apply some algo. by passing Profit and availability with maximum limit of Availability as M,for example M=10. Now it will give me some items to be taken as part of my solution.

Now I have to apply some algorithm to obtain maximum value of quality on the solution achieved by above algorithm. I can interchange some items which have been included in my solution to increase my quality parameter. but I have to ensure that these modifications should not drastically change profit and availability. please recommend if there any better solution for this requirement.

earthmover
  • 4,395
  • 10
  • 43
  • 74
  • 1
    Please state your optimization goal *precisely*. What is the function you want to optimize and what are the restrictions? – Niklas B. May 27 '14 at 11:21
  • You can't optimise the solution unless you can differentiate between two solutions. Perhaps you want to ensure that the profit is max and quality is a secondary factor. Perhaps you want to maximise their sum or product. Unless you can differentiate between two possible solutions, you cant find the answer. – shebang May 27 '14 at 11:49
  • What does "availability" even mean? If it's just the number of times you can select that item, you can convert to 0/1 knapsack (using k copies of an item with availability k). – harold May 27 '14 at 12:03

1 Answers1

0

Simple DP with knapsack approach (optimizing max quality with boundary on minimal profit):

int dp[N][MAX_PROFIT]; /// dp[i][j] - maximum quality obtained by using first i products which have j profit in total;
for (int i = 0; i < n; ++i) {
  for (int p = 0; p <= MAX_PROFIT; ++p) {
      for (int j = 0; j <= Available[j]; ++j) {
          int const newProfit = p + j * Profit[i];
          if (newProfit <= MAX_PROFIT)
              dp[i + 1][newProfit] = max(dp[i + 1][newProfit], dp[i][p] + j * Quality[i]);
      }
  }
}

Then just find maximum over j >= minProfit from dp[N][j].

juver
  • 236
  • 2
  • 8