While I am writing this, the exact criterion that we are trying to optimize has not been resolved. But whichever criterion is ultimately resolved, the following heuristic (i.e., generally suboptimal) approach may be useful:
Consider only a small number of "layouts" for combining a small number of rectangles into one large rectangle. Then, recursively consider ways to combine these new rectangles into even larger rectangles, using only as many layouts until only one rectangle remains.
This does not guarantee an optimal solution, because some subsets of photographs are limited to form subelements in the final solution. But it seems likely that he will give reasonable quality solutions.
For example, for the three rectangles A, B, and C, consider the following 4 layouts:
A B C ABC AB (ie A appears on the left) AC AA (ie A appears on the top) BC
Crop will only happen in the first round, when we combine groups of 3 photos. For this step, each subset of 3 photos should be taken into account under each of the 4 layouts above, and the optimal scaling and cropping are determined for each, given that the resulting rectangle can be increased or decreased at later stages. (A good choice of the optimality criterion should have the property that the ideal amount of scaling and cropping for each of A, B, and C under a certain layout does not depend on how much the resulting rectangle scales, so this should not be a problem.)
Subsequent combinations of rounds will behave the same, but without cropping. For a complete solution, round 2 includes an attempt to combine all sets of three rectangles created in the first round, in which all 9 photos are different from each other, but after this approach will lead to exponential bloating. This is enough to save only the best designs for each subset of photos. Please note that it is important that each photo is displayed in at least one of the rectangles created by each round.
j_random_hacker
source share