Originally posted by: SystemAdmin
[rdumeur said:]
Hi Pierre,
In ILOG CP, using IloBoxes, you need to write a specific search that tries to place boxes vertically or horizontally. As you end up with 2^N ways to rotate the boxes, you need a good heuristic.
Concerning pruning when using notOverlapInDimension on each box, the answer is that it shouldn't be the exactly the same, but similar.
In CP Optimizer, we don't have IloBox but you can write a simple model where, given N box width and height values, you have N decision variables that model, for each box:
- the X coordinate
- the Y coordinate
- the rotation status (boolean)
You can then define the rotated width and height of each box. For instance, if box i is rotated, then its width and height are exchanged. In OPL, you would write something like:
rwidth[i] == rotated[i]*height[i] + (1 - rotated[i])*width[i];
rheight[i] == rotated[i]*width[i] + (1 - rotated[j])*height[i];
Eventually, you need to specify non overlap constraints for two i,j boxes:
x[j] >= (x[i] + rwidth[i]) || (x[j] + rwidth[j]) <= x[i] || y[j] >= (x[i] + rheight[i]) || (y[j] + rheight[j]) <= y[i]<br />
You can use the length of the longest side of the smallest rectangle containing all the boxes as objective.
You can even add redundant constraints to express the fact that between two boxes, for a given axis, the distance is greater or equal to the smallest side you can find in the two boxes (for boxes can be rotated).
Using CP Optimizer's default search with such a simple model should already give you some interesting results.
I hope it helps.
Cheers!
#CPOptimizer#DecisionOptimization