Liberty BASIC Community Forum
« Paint - Jun. 08, 2011 »

Welcome Guest. Please Login or Register.
Dec 13th, 2017, 12:53pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Paint - Jun. 08, 2011  (Read 1106 times)
Noble D. Bell
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Paint - Jun. 08, 2011
« Thread started on: Jun 8th, 2011, 08:25am »

Greetings friends!!

Your paint inventory consists of 60 gallons of blue, 40 gallons of red, and 30 gallons of yellow. To make purple paint you mix equals parts of blue and red. To make orange paint you mix equal parts of red and yellow. To make green paint you mix equal parts of blue and yellow. Purple paint sells for $6 a gallon, orange for $20, and green for $9. There is a fixed disposal charge for every unused gallon.

Write an LB program that will determine how much of each of purple, orange, and green paint should you mix to maximize profits if the disposal cost is:

(a) $4 per gallon, and
(b) $6 per gallon.

Good luck and show your code.
User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14485
xx Re: Paint - Jun. 08, 2011
« Reply #1 on: Jun 8th, 2011, 08:34am »

Noble, do you mean that the base colors cannot be sold? The only salable paint is the mixed paint? Any leftover base colors incur a disposal fee?
User IP Logged

Noble D. Bell
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Re: Paint - Jun. 08, 2011
« Reply #2 on: Jun 8th, 2011, 1:43pm »

on Jun 8th, 2011, 08:34am, Alyce Watson wrote:
Noble, do you mean that the base colors cannot be sold? The only salable paint is the mixed paint? Any leftover base colors incur a disposal fee?


Yes. The mixed colors are the only salable paint. The base colors that are left over from the mixes will not be sold and have to be discarded.

Hope this helps.

User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: Paint - Jun. 08, 2011
« Reply #3 on: Jun 9th, 2011, 09:56am »

Quote:
(a) $4 per gallon, and
(b) $6 per gallon.


Do (a) and (b) refer to something?
What is the difference between (a) and (b)?
« Last Edit: Jun 9th, 2011, 09:56am by stefanhes » User IP Logged

http://www.soundofanimals.com
http://sincosin.com
Noble D. Bell
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Re: Paint - Jun. 08, 2011
« Reply #4 on: Jun 9th, 2011, 1:45pm »

It refers to the disposal cost.

The problem wants to know how much of the purple, orange, and yellow mixtures you can sell to generate the maximum profit.

It wants you to solve this for the disposal cost at (a) $4.00 and also if the disposal cost was (b) $6.00.

So you will have two answers:

a) purple=x1, orange=y1, yellow=z1 for a total of $r1.
b) purple=x2, orange=y2, yellow=z2 for a total of $r2.


Hope this helps.

User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: Paint - Jun. 08, 2011
« Reply #5 on: Jun 10th, 2011, 10:37am »

AH :A lineair programming problem.

x gallon Purple = 0.5x blue + 0.5x red
y gallon Orange = 0.5y red + 0.5y yellow
z gallon Green = 0.5z blue + 0.5z yellow

0.5x + 0.5z <= 60
0.5x + 0.5y <= 40
0.5y + 0.5z <= 30

x,y,x >= 0

maximize: 6x + 20y +9z - 4(130-x-y-z)
User IP Logged

http://www.soundofanimals.com
http://sincosin.com
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: Paint - Jun. 08, 2011
« Reply #6 on: Jun 11th, 2011, 4:30pm »

I think I have a working program, but I am not sure.

Noble, tell me, is this

solution: x=20, y=60, z=0
profit = 1120

a good solution for a) ??
User IP Logged

http://www.soundofanimals.com
http://sincosin.com
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: Paint - Jun. 08, 2011
« Reply #7 on: Jun 12th, 2011, 02:04am »

Code:
global true, false
true=1 : false =0

dim P(6,4)
dim M(3,3)
dim x(3)

P(1,1) = 0.5
P(1,2) = 0
P(1,3) = 0.5
P(1,4) = 60

P(2,1) = 0.5
P(2,2) = 0.5
P(2,3) = 0
P(2,4) = 40

P(3,1) = 0
P(3,2) = 0.5
P(3,3) = 0.5
P(3,4) = 30

P(4,1) = 1
P(4,2) = 0
P(4,3) = 0
P(4,4) = 0

P(5,1) = 0
P(5,2) = 1
P(5,3) = 0
P(5,4) = 0

P(6,1) = 0
P(6,2) = 0
P(6,3) = 1
P(6,4) = 0

nPoints = 20
p=1
bestprofit = 0
for plane1=1 to 4
for plane2=plane1+1 to 5
for plane3=plane2+1 to 6
   print "set ";p;" of 3 planes ",plane1,plane2,plane3
   print P(plane1,1);"x + ";P(plane1,2);"y + ";P(plane1,3);"z = ";P(plane1,4)
   print P(plane2,1);"x + ";P(plane2,2);"y + ";P(plane2,3);"z = ";P(plane2,4)
   print P(plane3,1);"x + ";P(plane3,2);"y + ";P(plane3,3);"z = ";P(plane3,4)
   call solve plane1,plane2,plane3
   print "solution: x=";x(1);",   y=";x(2);",   z=";x(3)

   good = true
   if   x(1)<0 or x(2)<0 or x(3)<0 or _
      ( P(1,1)*x(1) + P(1,2)*x(2) + P(1,3)*x(3) > P(1,4) ) or  _
      ( P(2,1)*x(1) + P(2,2)*x(2) + P(2,3)*x(3) > P(2,4) ) or _
      ( P(3,1)*x(1) + P(3,2)*x(2) + P(3,3)*x(3) > P(3,4) ) _
   then good = false
   if good _
   then
      profit = 6*x(1)+20*x(2)+9*x(3)-4*(130-x(1)-x(2)-x(3))
      if profit>bestprofit then bestprofit=profit : bestx=x(1) : besty=x(2) : bestz=x(3)
      print "profit = ";profit
   end if
      print
   p=p+1
next
next
next
print "bestprofit = ";bestprofit
print bestx;" gallon purple, ";besty;" gallon of orange, ";bestz;" gallon of green"
print "done"
print
print "And now for the brute force way:"
bestprofit=0
for i=1 to 100000
   x(1) = rnd(1)*60*2
   x(2) = rnd(2)*40*2
   x(3) = rnd(3)*30*2
   good = true
   if   x(1)<0 or x(2)<0 or x(3)<0 or _
      ( P(1,1)*x(1) + P(1,2)*x(2) + P(1,3)*x(3) > P(1,4) ) or  _
      ( P(2,1)*x(1) + P(2,2)*x(2) + P(2,3)*x(3) > P(2,4) ) or _
      ( P(3,1)*x(1) + P(3,2)*x(2) + P(3,3)*x(3) > P(3,4) ) _
   then good = false
   if good _
   then
      profit = 6*x(1)+20*x(2)+9*x(3)-4*(130-x(1)-x(2)-x(3))
      if profit>bestprofit _
      then
         bestprofit=profit : bestx=x(1) : besty=x(2) : bestz=x(3)
         print "profit = ";profit
         print bestx;" gallon purple, ";besty;" gallon of orange, ";bestz;" gallon of green"
      end if
   end if
next i
print "done, I tried ";i-1;" times."
print
print "Conclusion: math beats brute force, in precision and speed!"



end

sub solve a,b,c
   r(1)=a
   r(2)=b
   r(3)=c
   for i=0 to 3
      for row=1 to 3
         for col=1 to 3
            if col<>i then M(row,col) = P(r(row),col) else M(row,col) = P(r(row),4)
         next col
      next row
      determinant(i) = det()
      if i>0 and determinant(0)<>0 then x(i) = determinant(i)/determinant(0)
   next i
end sub


function det()
   det = M(1,1)*M(2,2)*M(3,3) + M(1,2)*M(2,3)*M(3,1) + M(1,3)*M(2,1)*M(3,2) - M(3,1)*M(2,2)*M(1,3) - M(3,2)*M(2,3)*M(1,1) - M(3,3)*M(2,1)*M(1,2)
end function


 
User IP Logged

http://www.soundofanimals.com
http://sincosin.com
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: Paint - Jun. 08, 2011
« Reply #8 on: Jun 12th, 2011, 02:12am »

For contest (b):

bestprofit = 1070
70 gallon purple, 10 gallon of orange, 50 gallon of green
User IP Logged

http://www.soundofanimals.com
http://sincosin.com
Noble D. Bell
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 932
xx Re: Paint - Jun. 08, 2011
« Reply #9 on: Jun 13th, 2011, 11:41am »

on Jun 11th, 2011, 4:30pm, stefanhes wrote:
I think I have a working program, but I am not sure.

Noble, tell me, is this

solution: x=20, y=60, z=0
profit = 1120

a good solution for a) ??


You are correct for both (a) and (b). Good job as always Stefan. wink
User IP Logged

Thank you and God bless,
Noble D. Bell
http://www.noblebell.com
GaRPMorE
Senior Member
ImageImageImageImage


member is offline

Avatar

"Not everything that counts can be counted, and not everything that can be counted counts." - Albert Einstein


PM


Posts: 289
xx Re: Paint - Jun. 08, 2011
« Reply #10 on: Jan 24th, 2013, 09:15am »

I came across this one in my files yesterday. I hadn't looked at it since I downloaded it
some 18 months ago. It afforded me a few hours of pondering. I offer it because the
"cat is skinned" in a different manner from the way I see Stephan used.
PAINT:
Your paint inventory consists of 60 gallons of blue, 40 gallons of red, and 30 gallons of yellow.
To make purple paint you mix equals parts of blue and red. To make orange paint you mix equal parts
of red and yellow. To make green paint you mix equal parts of blue and yellow. Purple paint sells
for $6 a gallon, orange for $20, and green for $9. There is a fixed disposal charge for every unused
gallon.
Write an LB program that will determine how much of each of purple, orange, and green paint should
you mix to maximize profits if the disposal cost is:
(a) $4 per gallon, and (b) $6 per gallon.
- - - - - - - - - - - - - - -

Obviously all the yellow will probably be used, since orange (and then green)
brings the highest price and yellow is the shortest supply.
The same reasoning may be applied to red, as it is the second smallest stock,
and is the other component of orange.
My approach will be to increment the orange mix, then mix as much green
and then blue as possible.
'
Code:
    bi=60:ri=40:yi=30 'initial stock: blue, red, orange
    o=20:g=9:p=6 'selling price per gallon for orange, green, purple
    '
    for dc=4 to 6 'disposal charge per gallon
        mxp=0 ' initialize maximum profit
        for org=1 to 60 ' gallons of orange
            b=bi:r=ri:y=yi 'initalize paint stock
            y=y-0.5*org:r=r-0.5*org ' diminish yellow & red stock
            grn=min(y,b) ' if both yellow and blue remain
            ' then mix green to the max
                y=y-grn:b=b-grn ' decrease yellow, blue stocks
                grn=grn*2 ' gallons of green
            pur=min(r,b) ' if both red and blue remain
            ' then mix purple to the max
                r=r-pur:b=b-pur
                pur=pur*2 ' gallons of purple
            inc=o*org+g*grn+p*pur ' sales income
            cst=dc*(y+r+b) ' disposal cost
            net=inc-cst ' net profit
            mxp=max(net,mxp) ' find maximum profit
            if mxp=net then ' remember quantities for latest mxp
                mpx$="orange: "+str$(org)+", green: "+_
                    str$(grn)+", purple "+str$(pur)
                rem$="yellow: "+str$(y)+", red: "+str$(r)+_
                    ", blue: "+str$(b)+" (total: "+str$(y+r+b)+")"
            end if
        next
        print "Maximum profit for $";dc;" disposal cost is $";mxp
        print "gallons mixed: ";mpx$
        print "gallons left:  ";rem$
        print
    next  

The output is:

Maximum profit for $4 disposal cost is $1120
gallons mixed: orange: 60, green: 0, purple 20
gallons left: yellow: 0, red: 0, blue: 50 (total: 50)

Maximum profit for $5 disposal cost is $1070
gallons mixed: orange: 60, green: 0, purple 20
gallons left: yellow: 0, red: 0, blue: 50 (total: 50)

Maximum profit for $6 disposal cost is $1070
gallons mixed: orange: 10, green: 50, purple 70
gallons left: yellow: 0, red: 0, blue: 0 (total: 0)
- - - - - -
It is interesting to note that the paint quantities for $4 to $5 disposal
costs are the same, while the best profit for both $5 and $6 are equal.

Over $6, nothing changes, since all the paint is sold, and there is no
disposal charge, while anywhere under $5, the mixes remain constant.
TEXT
« Last Edit: Feb 3rd, 2013, 8:10pm by GaRPMorE » User IP Logged

from the world according to GaRPMorE
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls