src/main/java/dev/rsoliveira/tools/binpacking/simulation/PalletPackingSimulation.java
/**
     * Lists all possible layer heights, giving a weight value to each layer.
     */
Lists all possible layer heights, giving a weight value to each layer.
Lists all possible layer heights giving a weight value to each layer .
private List<Layer> listCandidateLayers(PalletPackingState state, Volume orientation) {
        long examinedDimension, dimension2, dimension3;
        double weight;
        List<Layer> layers = new ArrayList<>();
        layers.add(new Layer(-1, 0));
        for (Item item : state.getInputItems()) {
            int max;
            switch (item.getRotation()) {
                case FULL: max = 3; break;
                case HORIZONTAL: max = 2; break;
                case NONE:
                default: max = 1; break;
            }
            for (int y = 1; y <= max; y++) {
                switch (y) {
                    case 2:
                        examinedDimension = item.getDimension2();
                        dimension2 = item.getDimension1();
                        dimension3 = item.getDimension3();
                        break;
                    case 3:
                        examinedDimension = item.getDimension3();
                        dimension2 = item.getDimension1();
                        dimension3 = item.getDimension2();
                        break;
                    default:
                        examinedDimension = item.getDimension1();
                        dimension2 = item.getDimension2();
                        dimension3 = item.getDimension3();
                        break;
                }
                if ((examinedDimension > orientation.getDimension2()) ||
                    (((dimension2 > orientation.getDimension1()) || (dimension3 > orientation.getDimension3())) &&
                     ((dimension3 > orientation.getDimension1()) || (dimension2 > orientation.getDimension3())))) {
                    continue;
                }
                long finalExaminedDimension = examinedDimension;
                if (layers.stream().anyMatch(p -> p.getDimension() == finalExaminedDimension)) {
                    continue;
                }
                weight = 0;
                for (Item item2 : state.getInputItems()) {
                    if (item.getId() == item2.getId()) continue;
                    weight = getDimensionDiff(examinedDimension, weight, item2);
                }
                layers.add(new Layer(weight, examinedDimension));
            }
        }
        layers.sort(Comparator.comparing(Layer::getWeight));
        return layers;
    }
private List < Layer > listCandidateLayers ( PalletPackingState state , Volume orientation ) { long examinedDimension , dimension2 , dimension3 ; double weight ; List < Layer > layers = new ArrayList < > ( ) ; layers . add ( new Layer ( - 1 , 0 ) ) ; for ( Item item : state . getInputItems ( ) ) { int max ; switch ( item . getRotation ( ) ) { case FULL : max = 3 ; break ; case HORIZONTAL : max = 2 ; break ; case NONE : default : max = 1 ; break ; } for ( int y = 1 ; y <= max ; y ++ ) { switch ( y ) { case 2 : examinedDimension = item . getDimension2 ( ) ; dimension2 = item . getDimension1 ( ) ; dimension3 = item . getDimension3 ( ) ; break ; case 3 : examinedDimension = item . getDimension3 ( ) ; dimension2 = item . getDimension1 ( ) ; dimension3 = item . getDimension2 ( ) ; break ; default : examinedDimension = item . getDimension1 ( ) ; dimension2 = item . getDimension2 ( ) ; dimension3 = item . getDimension3 ( ) ; break ; } if ( ( examinedDimension > orientation . getDimension2 ( ) ) || ( ( ( dimension2 > orientation . getDimension1 ( ) ) || ( dimension3 > orientation . getDimension3 ( ) ) ) && ( ( dimension3 > orientation . getDimension1 ( ) ) || ( dimension2 > orientation . getDimension3 ( ) ) ) ) ) { continue ; } long finalExaminedDimension = examinedDimension ; if ( layers . stream ( ) . anyMatch ( p -> p . getDimension ( ) == finalExaminedDimension ) ) { continue ; } weight = 0 ; for ( Item item2 : state . getInputItems ( ) ) { if ( item . getId ( ) == item2 . getId ( ) ) continue ; weight = getDimensionDiff ( examinedDimension , weight , item2 ) ; } layers . add ( new Layer ( weight , examinedDimension ) ) ; } } layers . sort ( Comparator . comparing ( Layer :: getWeight ) ) ; return layers ; }
Lists all possible layer heights, giving a weight value to each layer.
Lists all possible layer heights giving a weight value to each layer .
// face down = yz // face down = zy // face down = xz