A traveler gets diverted and has to make an unscheduled stop in what turns out to be Shangri La.   Opting to leave, he is allowed to take as much as he likes of the following items, so long as it will fit in his knapsack, and he can carry it.

He knows that he can carry no more than   25   'weights' in total;   and that the capacity of his knapsack is   0.25   'cubic lengths'.

Looking just above the bar codes on the items he finds their weights and volumes.   He digs out his recent copy of a financial paper and gets the value of each item.

ItemExplanationValue (each)weightVolume (each)panacea
(vials of)Incredible healing properties30000.30.025ichor
(ampules of)Vampires blood18000.20.015gold
(bars)Shiney shiney25002.00.002KnapsackFor the carrying of-<=25<=0.25 



He can only take whole units of any item, but there is much more of any item than he could ever carry



Task

Show how many of each item does he take to maximize the value of items he is carrying away with him.



Note
 
   There are four solutions that maximize the value taken.   Only one need be given.


Related tasks

   Knapsack problem/Bounded
   Knapsack problem/Continuous
   Knapsack problem/0-1


Define.f TotalWeight, TotalVolyme
Define.i maxPanacea, maxIchor, maxGold, maxValue
Define.i i, j ,k
Dim n.i(2)
 
Enumeration 
  #Panacea
  #Ichor
  #Gold
  #Sack
  #Current
EndEnumeration
 
Structure Bounty
  value.i
  weight.f
  volyme.f
EndStructure
 
Dim Item.Bounty(4)
CopyMemory(?panacea,@Item(#Panacea),SizeOf(Bounty))
CopyMemory(?ichor,  @Item(#Ichor),  SizeOf(Bounty))
CopyMemory(?gold,   @Item(#gold),   SizeOf(Bounty))
CopyMemory(?sack,   @Item(#Sack),   SizeOf(Bounty))
 
Procedure.f min(a.f, b.f)
  If a<b
    ProcedureReturn a
  Else
    ProcedureReturn b
  EndIf
EndProcedure
 
maxPanacea=min(Item(#Sack)\weight/Item(#Panacea)\weight,Item(#Sack)\volyme/Item(#Panacea)\volyme)
maxIchor  =min(Item(#Sack)\weight/Item(#Ichor)\weight,  Item(#Sack)\volyme/Item(#Ichor)\volyme)
maxGold   =min(Item(#Sack)\weight/Item(#Gold)\weight,   Item(#Sack)\volyme/Item(#Gold)\volyme)
 
For i=0 To maxPanacea 
  For j=0 To maxIchor
    For k=0 To maxGold
      Item(#Current)\value=k*Item(#Gold)\value  +j*item(#Ichor)\value +i*item(#Panacea)\value
      Item(#Current)\weight=k*Item(#Gold)\weight+j*Item(#Ichor)\weight+i*Item(#Panacea)\weight
      Item(#Current)\volyme=k*Item(#Gold)\volyme+j*Item(#Ichor)\volyme+i*Item(#Panacea)\volyme
      If Item(#Current)\weight>Item(#Sack)\weight Or Item(#Current)\volyme>Item(#Sack)\volyme
        Continue
      EndIf
      If Item(#Current)\value>maxValue
        maxValue=Item(#Current)\value
        TotalWeight=Item(#Current)\weight
        TotalVolyme=Item(#Current)\volyme
        n(#Panacea)=i: n(#Ichor)=j: n(#Gold)=k
      EndIf
    Next k
  Next j
Next i
 
If OpenConsole()
  Define txt$
  txt$="Maximum value achievable is "+Str(maxValue)+#CRLF$
  txt$+"This is achieved by carrying "+Str(n(#Panacea))+" panacea, "
  txt$+Str(n(#Ichor))+" ichor and "+Str(n(#Gold))+" gold items."+#CRLF$
  txt$+"The weight to carry is "+StrF(totalWeight,2)
  txt$+" and the volume used is "+StrF(TotalVolyme,2)
  PrintN(txt$)
 
  Print(#CRLF$+"Press Enter to quit"): Input()
EndIf
 
DataSection
panacea:
  Data.i 3000
  Data.f 0.3, 0.025
ichor:
  Data.i 1800
  Data.f 0.2, 0.015
gold:
  Data.i 2500
  Data.f 2.0, 0.002
sack:
  Data.i  0
  Data.f  25.0, 0.25
EndDataSection