public double [ ] cceua ( double s [ ] [ ] , double sf [ ] , double bl [ ] , double bu [ ] ) { int nps = s . length ; int nopt = s [ 0 ] . length ; int n = nps ; int m = nopt ; double alpha = 1.0 ; double beta = 0.5 ; // Assign the best and worst points: double sb [ ] = new double [ nopt ] ; double sw [ ] = new double [ nopt ] ; double fb = sf [ 0 ] ; double fw = sf [ n - 1 ] ; for ( int i = 0 ; i < nopt ; i ++ ) { sb [ i ] = s [ 0 ] [ i ] ; sw [ i ] = s [ n - 1 ] [ i ] ; } // Compute the centroid of the simplex excluding the worst point: double ce [ ] = new double [ nopt ] ; for ( int i = 0 ; i < nopt ; i ++ ) { ce [ i ] = 0 ; for ( int j = 0 ; j < n - 1 ; j ++ ) { ce [ i ] += s [ j ] [ i ] ; } ce [ i ] /= ( n - 1 ) ; } // Attempt a reflection point double snew [ ] = new double [ nopt ] ; for ( int i = 0 ; i < nopt ; i ++ ) { snew [ i ] = ce [ i ] + alpha * ( ce [ i ] - sw [ i ] ) ; } // Check if is outside the bounds: int ibound = 0 ; for ( int i = 0 ; i < nopt ; i ++ ) { if ( ( snew [ i ] - bl [ i ] ) < 0 ) { ibound = 1 ; } if ( ( bu [ i ] - snew [ i ] ) < 0 ) { ibound = 2 ; } } if ( ibound >= 1 ) { snew = randomSampler ( ) ; } double fnew = funct ( snew ) ; // Reflection failed; now attempt a contraction point: if ( fnew > fw ) { for ( int i = 0 ; i < nopt ; i ++ ) { snew [ i ] = sw [ i ] + beta * ( ce [ i ] - sw [ i ] ) ; } fnew = funct ( snew ) ; } // Both reflection and contraction have failed, attempt a random point; if ( fnew > fw ) { snew = randomSampler ( ) ; fnew = funct ( snew ) ; } double result [ ] = new double [ nopt + 1 ] ; for ( int i = 0 ; i < nopt ; i ++ ) { result [ i ] = snew [ i ] ; } result [ nopt ] = fnew ; return result ; }
bu upper bound