Вопрос

Lets say we have multiple sizes of bins defined by Length x Width , those could be called "raw material" sizes.

I need to cut certain amount of tables (rectangles, in guillotine form) out of that raw material so that the amount of raw material is minimized.

As the bins do not have the same size they should be somehow factored or prioritize to reflect their value - so a bigger bin is obviously "more expensive".

I know this is a NP-Complete problem and I don't expect a deterministic algorithm in a polynomial time.

I need an algorithm that solves the problem.

Any suggestions would be helpful!

Thanks

Это было полезно?

Решение

Well, the basics are: You first need to define well a goodness function. Only after that your problem can be considered clearly stated. Let us call any layout of rectangles on your material plate an "Arrangement". The goodnes function should map from the domain of Arrangements to the domain of real numbers, the bigger the better, let's say. The function should be decreasing with the amount of material "wasted" in the given Arrangement, and increasing with the amount and value of the rectangles satisfied by the Arranegement. I repeat, you are the one who has to define that goodness function, that is, relative value of material and the value of the individual rectangles, which, as you say, fulfill the saying "the bigger the better". You have to quantify it.

Once you do this, a plethora of algorithms opens for you, the first being the random algorithm: You distribute a non-overlapping Arrangement or rectangles randomly on your sheet of material, evaluate its goodness and store it in the memory. After you do this sufficiently many times, you pick the best one. The improvement of this algorithm would be to try to pick already good arrangements and "nudge around" the rectangles a bit to gain space for one more small rectangle. That's what Dylan might mean by using simulated annealing. And btw. don't read that Wikipedia page on Simulated annealing, it will only mess up your head.


Response to the comment:

Nick, obviously, you have to use all kinds of bins from the very beginning. Let's say you have the starting sheet of material defined (either as a bitmap, or by vectors). You'll do the following: 1. Randomly pick a point 2. Randomly pick a rectangle type 3. Randomly pick rotation 4. If the rectangle doesn't fit, go back to point 1. 5. If the rectangle fits, place it on the material sheet and try placing a second rectangle by the same method. 6. Then third, fourth etc., until you encounter too many failures and conclude that you hit a dead end. 7. Calculate the goodness of the Resulting arrangement 8. Go on to the next arrangment

Now it occurs to me, that maybe your cutting machine only allows one orientation (2 axis with no tool rotation), so rotation of the rectangles does not have to be taken into account. In that case, you will randomly pick the point not just anywhere, but on the side of the material sheet or on the side of another rectangle already on the sheet and you will place the next rectangle to this point so that it has adjacent side with the side of the sheet or with another rectangle. In this case (no rotation) you can randomly pick a direction and shift the new rectangle in the chosen direction until it hits any perpendicular wall. That way, you'll save computing work and create better arrangements from the get go. The last step is still computing the goodness function and picking the best.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top