I have an integer programming problem. I have a pipe, 10m long. I want to cut out as many 1.2meter pieces as I can and then cut the rest of the pipe in 100mm pieces. I have to leave 100mm for the machine to grab. How do I optimize this in mathematica? I can solve it as an equality i guess but if i just want the answer straight out. Basically, as many y's as possible, then x:es.
Maximize[{x*100+y*1200, x*100+y*1200<9900},{x,y},Integers] just gives me an inequality plot.
And yes, I have checked instructions at wolfram.
As 9900 and 1200 are both multiples of 100, the algorithm is just
TotLen = 9900;
numberOf1200pieces = IntegerPart[TotLen/1200];
numberOf100pieces = IntegerPart[(TotLen - 1200 numberOf1200pieces)/100];
Print["Number of 1200mm pieces: ", numberOf1200pieces];
Print["Number of 100mm pieces: ", numberOf100pieces];
Print["Leftover: ", 9900 - numberOf1200pieces 1200 - numberOf100pieces 100,"mm"];
Number of 1200mm pieces: 8
Number of 100mm pieces: 3
Leftover: 0mm
You may also try:
Maximize[{x*100 + y*1200, x*100 + y*1200 == 9900}, {x, y}, Integers]
->{9900, {x -> 3, y -> 8}}
Use assume on x,y etc to be >0 etc and you will finally be able to get a value with //N
Mathematica doesnt assume you are in the Real world!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With