src/main/java/dev/rsoliveira/tools/binpacking/service/PackingService.java
/**
     * Simulates packing a list of items into a list of containers, resulting in a list of solutions.
     * Each simulation iteration results in 2 lists of packed and unpacked items, and the next iteration uses
     * the unpacked items simulate the packing, until all containers were used.
     * If there are unpacked items at the of simulations, the last solution will have the remaining ones.
     * It is best to use this method when the list of containers is known.
     * @param containers the list of containers to use on the simulation; each container can be used for one simulation
     *                   only.
     * @param items the list of all items that will be packed.
     * @return a list of possible packings, containing position and direction for each item inside the containers.
     */
Simulates packing a list of items into a list of containers, resulting in a list of solutions.
Each simulation iteration results in 2 lists of packed and unpacked items, and the next iteration uses
the unpacked items simulate the packing, until all containers were used.
If there are unpacked items at the of simulations, the last solution will have the remaining ones.
It is best to use this method when the list of containers is known.
@param containers the list of containers to use on the simulation; each container can be used for one simulation
only.
@param items the list of all items that will be packed.
@return a list of possible packings, containing position and direction for each item inside the containers.
Simulates packing a list of items into a list of containers resulting in a list of solutions . Each simulation iteration results in 2 lists of packed and unpacked items and the next iteration uses the unpacked items simulate the packing until all containers were used . If there are unpacked items at the of simulations the last solution will have the remaining ones . It is best to use this method when the list of containers is known . @param containers the list of containers to use on the simulation ; each container can be used for one simulation only . @param items the list of all items that will be packed . @return a list of possible packings containing position and direction for each item inside the containers .
public static List<Solution> simulate(List<Container> containers, List<Item> items) {
        List<Solution> solutions = new ArrayList<>();
        List<Item> remaining = new ArrayList<>(items);
        for (Container container : containers) {
            if (!remaining.isEmpty()) {
                Solution solution = simulator.simulate(container, remaining);
                solutions.add(solution);
                if (solution.isCompletePacking()) {
                    remaining.clear();
                    break;
                }
                remaining = new ArrayList<>(solution.getRemainingItems());
            }
        }
        return solutions;
    }
public static List < Solution > simulate ( List < Container > containers , List < Item > items ) { List < Solution > solutions = new ArrayList < > ( ) ; List < Item > remaining = new ArrayList < > ( items ) ; for ( Container container : containers ) { if ( ! remaining . isEmpty ( ) ) { Solution solution = simulator . simulate ( container , remaining ) ; solutions . add ( solution ) ; if ( solution . isCompletePacking ( ) ) { remaining . clear ( ) ; break ; } remaining = new ArrayList < > ( solution . getRemainingItems ( ) ) ; } } return solutions ; }
Simulates packing a list of items into a list of containers, resulting in a list of solutions.
Simulates packing a list of items into a list of containers resulting in a list of solutions .