src/main/java/dev/rsoliveira/tools/binpacking/simulation/PalletPackingSimulation.java
/**
     * Finds a proper layer thickness by looking at the unpacked boxes and the remaining container space.
     *
     * @param thickness the layer thickness.
     */
Finds a proper layer thickness by looking at the unpacked boxes and the remaining container space.
@param thickness the layer thickness.
Finds a proper layer thickness by looking at the unpacked boxes and the remaining container space . @param thickness the layer thickness .
private void findLayer(PalletPackingState state, Volume orientation, double thickness) {
        long examinedDimension, dimension2, dimension3;
        double layereval, eval = 100000000;
        int max;
        state.setLayerThickness(0);
        Item[] toPack = Arrays.stream(state.getItemsToPack()).filter(j -> !j.isPacked()).toArray(Item[]::new);
        for (int x = 0; x < toPack.length; x++) {
            switch (toPack[x].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 = toPack[x].getDimension2();
                        dimension2 = toPack[x].getDimension1();
                        dimension3 = toPack[x].getDimension3();
                        break;
                    case 3:
                        examinedDimension = toPack[x].getDimension3();
                        dimension2 = toPack[x].getDimension1();
                        dimension3 = toPack[x].getDimension2();
                        break;
                    default:
                        examinedDimension = toPack[x].getDimension1();
                        dimension2 = toPack[x].getDimension2();
                        dimension3 = toPack[x].getDimension3();
                        break;
                }
                layereval = 0;
                if ((examinedDimension <= thickness) && (((dimension2 <= orientation.getDimension1()) &&
                    (dimension3 <= orientation.getDimension3())) ||
                    ((dimension3 <= orientation.getDimension1()) && (dimension2 <= orientation.getDimension3())))) {
                    for (int z = 0; z < toPack.length; z++) {
                        if (x != z) {
                            Item otherItem = toPack[z];
                            layereval = getDimensionDiff(examinedDimension, layereval, otherItem);
                        }
                    }
                    if (layereval < eval) {
                        eval = layereval;
                        state.setLayerThickness(examinedDimension);
                    }
                }
            }
        }
        if (state.getLayerThickness() == 0 || state.getLayerThickness() > state.getMaxAvailableThickness()) {
            state.setPacking(false);
        }
    }
private void findLayer ( PalletPackingState state , Volume orientation , double thickness ) { long examinedDimension , dimension2 , dimension3 ; double layereval , eval = 100000000 ; int max ; state . setLayerThickness ( 0 ) ; Item [ ] toPack = Arrays . stream ( state . getItemsToPack ( ) ) . filter ( j -> ! j . isPacked ( ) ) . toArray ( Item [ ] :: new ) ; for ( int x = 0 ; x < toPack . length ; x ++ ) { switch ( toPack [ x ] . 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 = toPack [ x ] . getDimension2 ( ) ; dimension2 = toPack [ x ] . getDimension1 ( ) ; dimension3 = toPack [ x ] . getDimension3 ( ) ; break ; case 3 : examinedDimension = toPack [ x ] . getDimension3 ( ) ; dimension2 = toPack [ x ] . getDimension1 ( ) ; dimension3 = toPack [ x ] . getDimension2 ( ) ; break ; default : examinedDimension = toPack [ x ] . getDimension1 ( ) ; dimension2 = toPack [ x ] . getDimension2 ( ) ; dimension3 = toPack [ x ] . getDimension3 ( ) ; break ; } layereval = 0 ; if ( ( examinedDimension <= thickness ) && ( ( ( dimension2 <= orientation . getDimension1 ( ) ) && ( dimension3 <= orientation . getDimension3 ( ) ) ) || ( ( dimension3 <= orientation . getDimension1 ( ) ) && ( dimension2 <= orientation . getDimension3 ( ) ) ) ) ) { for ( int z = 0 ; z < toPack . length ; z ++ ) { if ( x != z ) { Item otherItem = toPack [ z ] ; layereval = getDimensionDiff ( examinedDimension , layereval , otherItem ) ; } } if ( layereval < eval ) { eval = layereval ; state . setLayerThickness ( examinedDimension ) ; } } } } if ( state . getLayerThickness ( ) == 0 || state . getLayerThickness ( ) > state . getMaxAvailableThickness ( ) ) { state . setPacking ( false ) ; } }
Finds a proper layer thickness by looking at the unpacked boxes and the remaining container space.
Finds a proper layer thickness by looking at the unpacked boxes and the remaining container space .