Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer optimization in Mathematica?

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.

like image 523
johnny Avatar asked Jan 23 '26 08:01

johnny


2 Answers

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}}
like image 192
Dr. belisarius Avatar answered Jan 26 '26 01:01

Dr. belisarius


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!

like image 27
stefan Avatar answered Jan 26 '26 01:01

stefan