private int [ ] [ ] calculateInstanceAccommodationMatrix ( ) { if ( this . availableInstanceTypes == null ) { LOG . error ( "Cannot compute instance accommodation matrix: availableInstanceTypes is null" ) ; return null ; } final int matrixSize = this . availableInstanceTypes . length ; final int [ ] [ ] am = new int [ matrixSize ] [ matrixSize ] ; // Populate matrix for ( int i = 0 ; i < matrixSize ; i ++ ) { for ( int j = 0 ; j < matrixSize ; j ++ ) { if ( i == j ) { am [ i ] [ j ] = 1 ; } else { final InstanceType sourceType = this . availableInstanceTypes [ i ] ; InstanceType targetType = this . availableInstanceTypes [ j ] ; // How many times can we accommodate source type into target type? final int cores = targetType . getNumberOfCores ( ) / sourceType . getNumberOfCores ( ) ; final int cu = targetType . getNumberOfComputeUnits ( ) / sourceType . getNumberOfComputeUnits ( ) ; final int mem = targetType . getMemorySize ( ) / sourceType . getMemorySize ( ) ; final int disk = targetType . getDiskCapacity ( ) / sourceType . getDiskCapacity ( ) ; am [ i ] [ j ] = Math . min ( cores , Math . min ( cu , Math . min ( mem , disk ) ) ) ; } } } return am ; }
Calculates the instance accommodation matrix which stores how many times a particular instance type can be accommodated inside another instance type based on the list of available instance types .