R
R
Rodion Almetov2018-12-06 21:25:09
Algorithms
Rodion Almetov, 2018-12-06 21:25:09

Any ideas how to optimize the algorithm in combinatorics?

There is an arbitrary number of rectangles of different sizes (Height, Width, Thickness).
It is necessary to form "packs" with some restrictions in such a way as to obtain the minimum number of "packs".
Restrictions:
1) One rectangle can be placed on another according to certain conditions (for example, the width should not exceed the width of another by 30 conventional units, and there are several such conditions - but this is not the point)
2) The pack should not exceed the total thickness of, say, 300 conventional units.
Ideally, the rectangles should go from largest to smallest.
I'm racking my brains and can't come up with a satisfying result.
So far, I have come up with only a few ways to select rectangles:
1) By dimensions
2) By height (previously turning them over so that the height is always greater than the width)
3) Calculating the delta between width and height
4) Sort by the principle of "squareness"
I will be glad to any ideas.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2018-12-06
@radar4ick

Take the task of a backpack and adapt it to your conditions.
If there are less than a hundred rectangles, a complete search with the choice of the optimal solution will take a few seconds.
If not, look for where you messed up.
If you do not find it, change the language to one that does not create objects in memory without asking.

D
Dmitry, 2018-12-07
@dimoff66

Rodion Almetov ,
1) Sort by the first parameter, which is "not the essence" + by thickness
2) Loop through the sorted array, calculating for each rectangle the nearest neighbors that do NOT satisfy the neighborhood condition. Let's say for rectangle No. 5 these will be No. 2 and No. 7, which means that the rectangle can only be connected with numbers 3, 4, and 6.
Having this information, we begin to fill packs starting from the thickest. As soon as the thickness has been exceeded, we look for the details of the nearest thinner neighbors for each rectangle, with which we can replace them so that the pack is a
) of the required thickness
b) With a minimum difference between the thickness of the pack and the maximum thickness.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question