Container pre-marshalling is a kind of transportation operation. In container terminal operation, containers are usually stacked with a certain number of layers. If the containers to be picked up are pressed down by other containers, the barrier boxes on them must be removed at this time. Due to the uncertainty in wharf operation, unpacking is almost inevitable. The average number of unpacking is an indicator to measure the level of wharf operation management. Different from previous literature, this paper designs a new algorithm to solve this problem by integrating heuristic algorithm and rule constraint. All kinds of indicators to evaluate the current layout are used as the coding part of the genetic algorithm, and the whole unpacking process is realized by constantly iterating to find the appropriate weight coefficient and emptying the stack rules. Finally, an example is given to prove the effectiveness of the algorithm.