idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
31,600 | static public double griewank ( double [ ] x ) { double sum = 0.0 ; double product = 1.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { sum += ( ( x [ i ] * x [ i ] ) / 4000.0 ) ; product *= Math . cos ( x [ i ] / m_iSqrt [ i ] ) ; } return ( sum - product + 1.0 ) ; } | Griewank s function | 100 | 6 |
31,601 | static public double ackley ( double [ ] x ) { double sum1 = 0.0 ; double sum2 = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { sum1 += ( x [ i ] * x [ i ] ) ; sum2 += ( Math . cos ( PIx2 * x [ i ] ) ) ; } return ( - 20.0 * Math . exp ( - 0.2 * Math . sqrt ( sum1 / ( ( double ) x . length ) ) ) - Math . exp ( sum2 / ( ( double ) x . length ) ) + 20.0 + Math . E ) ; } | Ackley s function | 143 | 5 |
31,602 | static public double myRound ( double x ) { return ( Math . signum ( x ) * Math . round ( Math . abs ( x ) ) ) ; } | 0 . Use the Matlab version for rounding numbers | 34 | 10 |
31,603 | static public double myXRound ( double x , double o ) { return ( ( Math . abs ( x - o ) < 0.5 ) ? x : ( myRound ( 2.0 * x ) / 2.0 ) ) ; } | 1 . o is provided | 51 | 5 |
31,604 | static public double rastrigin ( double [ ] x ) { double sum = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { sum += ( x [ i ] * x [ i ] ) - ( 10.0 * Math . cos ( PIx2 * x [ i ] ) ) + 10.0 ; } return ( sum ) ; } | Rastrigin s function | 83 | 6 |
31,605 | static public double rastriginNonCont ( double [ ] x ) { double sum = 0.0 ; double currX ; for ( int i = 0 ; i < x . length ; i ++ ) { currX = myXRound ( x [ i ] ) ; sum += ( currX * currX ) - ( 10.0 * Math . cos ( PIx2 * currX ) ) + 10.0 ; } return ( sum ) ; } | Non - Continuous Rastrigin s function | 101 | 9 |
31,606 | static public double ScafferF6 ( double x , double y ) { double temp1 = x * x + y * y ; double temp2 = Math . sin ( Math . sqrt ( temp1 ) ) ; double temp3 = 1.0 + 0.001 * temp1 ; return ( 0.5 + ( ( temp2 * temp2 - 0.5 ) / ( temp3 * temp3 ) ) ) ; } | Scaffer s F6 function | 90 | 6 |
31,607 | static public double EScafferF6 ( double [ ] x ) { double sum = 0.0 ; for ( int i = 1 ; i < x . length ; i ++ ) { sum += ScafferF6 ( x [ i - 1 ] , x [ i ] ) ; } sum += ScafferF6 ( x [ x . length - 1 ] , x [ 0 ] ) ; return ( sum ) ; } | Expanded Scaffer s F6 function | 88 | 8 |
31,608 | static public double EScafferF6NonCont ( double [ ] x ) { double sum = 0.0 ; double prevX , currX ; currX = myXRound ( x [ 0 ] ) ; for ( int i = 1 ; i < x . length ; i ++ ) { prevX = currX ; currX = myXRound ( x [ i ] ) ; sum += ScafferF6 ( prevX , currX ) ; } prevX = currX ; currX = myXRound ( x [ 0 ] ) ; sum += ScafferF6 ( prevX , currX ) ; return ( sum ) ; } | Non - Continuous Expanded Scaffer s F6 function | 142 | 11 |
31,609 | private int hammingDistance ( BinarySolution solutionOne , BinarySolution solutionTwo ) { int distance = 0 ; for ( int i = 0 ; i < problem . getNumberOfVariables ( ) ; i ++ ) { distance += hammingDistance ( solutionOne . getVariableValue ( i ) , solutionTwo . getVariableValue ( i ) ) ; } return distance ; } | Calculate the hamming distance between two solutions | 77 | 10 |
31,610 | private double er ( Front front , Front referenceFront ) throws JMetalException { int numberOfObjectives = referenceFront . getPointDimensions ( ) ; double sum = 0 ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { Point currentPoint = front . getPoint ( i ) ; boolean thePointIsInTheParetoFront = false ; for ( int j = 0 ; j < referenceFront . getNumberOfPoints ( ) ; j ++ ) { Point currentParetoFrontPoint = referenceFront . getPoint ( j ) ; boolean found = true ; for ( int k = 0 ; k < numberOfObjectives ; k ++ ) { if ( currentPoint . getValue ( k ) != currentParetoFrontPoint . getValue ( k ) ) { found = false ; break ; } } if ( found ) { thePointIsInTheParetoFront = true ; break ; } } if ( ! thePointIsInTheParetoFront ) { sum ++ ; } } return sum / front . getNumberOfPoints ( ) ; } | Returns the value of the error ratio indicator . | 233 | 9 |
31,611 | @ Override public int compare ( Point pointOne , Point pointTwo ) { if ( pointOne == null ) { throw new JMetalException ( "PointOne is null" ) ; } else if ( pointTwo == null ) { throw new JMetalException ( "PointTwo is null" ) ; } // Determine the first i such as pointOne[i] != pointTwo[i]; int index = 0 ; while ( ( index < pointOne . getDimension ( ) ) && ( index < pointTwo . getDimension ( ) ) && pointOne . getValue ( index ) == pointTwo . getValue ( index ) ) { index ++ ; } int result = 0 ; if ( ( index >= pointOne . getDimension ( ) ) || ( index >= pointTwo . getDimension ( ) ) ) { result = 0 ; } else if ( pointOne . getValue ( index ) < pointTwo . getValue ( index ) ) { result = - 1 ; } else if ( pointOne . getValue ( index ) > pointTwo . getValue ( index ) ) { result = 1 ; } return result ; } | The compare method compare the objects o1 and o2 . | 236 | 12 |
31,612 | public double randNormal ( double mean , double standardDeviation ) { double x1 , x2 , w , y1 ; do { x1 = 2.0 * randomGenerator . nextDouble ( ) - 1.0 ; x2 = 2.0 * randomGenerator . nextDouble ( ) - 1.0 ; w = x1 * x1 + x2 * x2 ; } while ( w >= 1.0 ) ; w = Math . sqrt ( ( - 2.0 * Math . log ( w ) ) / w ) ; y1 = x1 * w ; y1 = y1 * standardDeviation + mean ; return y1 ; } | Use the polar form of the Box - Muller transformation to obtain a pseudo random number from a Gaussian distribution Code taken from Maurice Clerc s implementation | 141 | 29 |
31,613 | public double [ ] randSphere ( int dimension , double center , double radius ) { int d = dimension ; double [ ] x = new double [ dimension ] ; double length = 0 ; for ( int i = 0 ; i < dimension ; i ++ ) { x [ i ] = 0.0 ; } // --------- Step 1. Direction for ( int i = 0 ; i < d ; i ++ ) { x [ i ] = randNormal ( 0 , 1 ) ; length += length + x [ i ] * x [ i ] ; } length = Math . sqrt ( length ) ; // --------- Step 2. Random radius double r = randomGenerator . nextDouble ( 0 , 1 ) ; for ( int i = 0 ; i < d ; i ++ ) { x [ i ] = center + radius * r * x [ i ] / length ; } return x ; } | Ger a random point from an hypersphere Code taken from Maurice Clerc s implementation | 182 | 17 |
31,614 | public float [ ] t1 ( float [ ] z , int k ) { float [ ] result = new float [ z . length ] ; float [ ] w = new float [ z . length ] ; for ( int i = 0 ; i < w . length ; i ++ ) { w [ i ] = ( float ) 1.0 ; } for ( int i = 0 ; i < z . length - 1 ; i ++ ) { int head = i + 1 ; int tail = z . length - 1 ; float [ ] subZ = subVector ( z , head , tail ) ; float [ ] subW = subVector ( w , head , tail ) ; float aux = ( new Transformations ( ) ) . rSum ( subZ , subW ) ; result [ i ] = ( new Transformations ( ) ) . bParam ( z [ i ] , aux , ( float ) 0.98 / ( float ) 49.98 , ( float ) 0.02 , ( float ) 50 ) ; } result [ z . length - 1 ] = z [ z . length - 1 ] ; return result ; } | WFG9 t1 transformation | 233 | 6 |
31,615 | public float [ ] t2 ( float [ ] z , int k ) { float [ ] result = new float [ z . length ] ; for ( int i = 0 ; i < k ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . sDecept ( z [ i ] , ( float ) 0.35 , ( float ) 0.001 , ( float ) 0.05 ) ; } for ( int i = k ; i < z . length ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . sMulti ( z [ i ] , 30 , 95 , ( float ) 0.35 ) ; } return result ; } | WFG9 t2 transformation | 144 | 6 |
31,616 | public float [ ] t3 ( float [ ] z , int k , int M ) { float [ ] result = new float [ M ] ; for ( int i = 1 ; i <= M - 1 ; i ++ ) { int head = ( i - 1 ) * k / ( M - 1 ) + 1 ; int tail = i * k / ( M - 1 ) ; float [ ] subZ = subVector ( z , head - 1 , tail - 1 ) ; result [ i - 1 ] = ( new Transformations ( ) ) . rNonsep ( subZ , k / ( M - 1 ) ) ; } int head = k + 1 ; int tail = z . length ; int l = z . length - k ; float [ ] subZ = subVector ( z , head - 1 , tail - 1 ) ; result [ M - 1 ] = ( new Transformations ( ) ) . rNonsep ( subZ , l ) ; return result ; } | WFG9 t3 transformation | 205 | 6 |
31,617 | public double repairSolutionVariableValue ( double value , double lowerBound , double upperBound ) { if ( lowerBound > upperBound ) { throw new JMetalException ( "The lower bound (" + lowerBound + ") is greater than the " + "upper bound (" + upperBound + ")" ) ; } double result = value ; if ( value < lowerBound ) { result = lowerBound ; } if ( value > upperBound ) { result = upperBound ; } return result ; } | Checks if the value is between its bounds ; if not the lower or upper bound is returned | 101 | 19 |
31,618 | public double evalG ( DoubleSolution solution ) { double g = 0.0 ; for ( int var = 1 ; var < solution . getNumberOfVariables ( ) ; var ++ ) { g += Math . pow ( solution . getVariableValue ( var ) , 2.0 ) + - 10.0 * Math . cos ( 4.0 * Math . PI * solution . getVariableValue ( var ) ) ; } double constant = 1.0 + 10.0 * ( solution . getNumberOfVariables ( ) - 1 ) ; return g + constant ; } | Returns the value of the ZDT4 function G . | 119 | 11 |
31,619 | private void createNeighborhoods ( ) { neighbours = new ArrayList < List < Integer > > ( solutionListSize ) ; for ( int i = 0 ; i < solutionListSize ; i ++ ) { neighbours . add ( new ArrayList < Integer > ( ) ) ; neighbours . get ( i ) . add ( i ) ; } } | Initialize all the neighborhoods adding the current solution to them . | 72 | 12 |
31,620 | private void addRandomNeighbors ( ) { for ( int i = 0 ; i < solutionListSize ; i ++ ) { while ( neighbours . get ( i ) . size ( ) <= numberOfRandomNeighbours ) { int random = randomGenerator . getRandomValue ( 0 , solutionListSize - 1 ) ; neighbours . get ( i ) . add ( random ) ; } } } | Add random neighbors to all the neighborhoods | 82 | 7 |
31,621 | protected double evalG ( DoubleSolution solution ) { double g = 0.0 ; for ( int var = 1 ; var < solution . getNumberOfVariables ( ) ; var ++ ) { g += solution . getVariableValue ( var ) ; } g = g / ( solution . getNumberOfVariables ( ) - 1 ) ; g = Math . pow ( g , 0.25 ) ; g = 9.0 * g ; g = 1.0 + g ; return g ; } | Returns the value of the ZDT6 function G . | 103 | 11 |
31,622 | public List < BinarySolution > doCrossover ( double probability , BinarySolution parent1 , BinarySolution parent2 ) { List < BinarySolution > offspring = new ArrayList <> ( 2 ) ; offspring . add ( ( BinarySolution ) parent1 . copy ( ) ) ; offspring . add ( ( BinarySolution ) parent2 . copy ( ) ) ; if ( crossoverRandomGenerator . getRandomValue ( ) < probability ) { // 1. Get the total number of bits int totalNumberOfBits = parent1 . getTotalNumberOfBits ( ) ; // 2. Calculate the point to make the crossover int crossoverPoint = pointRandomGenerator . getRandomValue ( 0 , totalNumberOfBits - 1 ) ; // 3. Compute the variable containing the crossover bit int variable = 0 ; int bitsAccount = parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) ; while ( bitsAccount < ( crossoverPoint + 1 ) ) { variable ++ ; bitsAccount += parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) ; } // 4. Compute the bit into the selected variable int diff = bitsAccount - crossoverPoint ; int intoVariableCrossoverPoint = parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) - diff ; // 5. Apply the crossover to the variable; BinarySet offspring1 , offspring2 ; offspring1 = ( BinarySet ) parent1 . getVariableValue ( variable ) . clone ( ) ; offspring2 = ( BinarySet ) parent2 . getVariableValue ( variable ) . clone ( ) ; for ( int i = intoVariableCrossoverPoint ; i < offspring1 . getBinarySetLength ( ) ; i ++ ) { boolean swap = offspring1 . get ( i ) ; offspring1 . set ( i , offspring2 . get ( i ) ) ; offspring2 . set ( i , swap ) ; } offspring . get ( 0 ) . setVariableValue ( variable , offspring1 ) ; offspring . get ( 1 ) . setVariableValue ( variable , offspring2 ) ; // 6. Apply the crossover to the other variables for ( int i = variable + 1 ; i < parent1 . getNumberOfVariables ( ) ; i ++ ) { offspring . get ( 0 ) . setVariableValue ( i , ( BinarySet ) parent2 . getVariableValue ( i ) . clone ( ) ) ; offspring . get ( 1 ) . setVariableValue ( i , ( BinarySet ) parent1 . getVariableValue ( i ) . clone ( ) ) ; } } return offspring ; } | Perform the crossover operation . | 540 | 6 |
31,623 | private int getNeighbor ( int solution , int [ ] neighbor ) { int row = getRow ( solution ) ; int col = getColumn ( ( solution ) ) ; int r ; int c ; r = ( row + neighbor [ 0 ] ) % this . rows ; if ( r < 0 ) r = rows - 1 ; c = ( col + neighbor [ 1 ] ) % this . columns ; if ( c < 0 ) c = columns - 1 ; return this . mesh [ r ] [ c ] ; } | Returns the neighbor of solution | 107 | 5 |
31,624 | private List < S > findNeighbors ( List < S > solutionSet , int solution , int [ ] [ ] neighborhood ) { List < S > neighbors = new ArrayList <> ( neighborhood . length + 1 ) ; for ( int [ ] neighbor : neighborhood ) { int index = getNeighbor ( solution , neighbor ) ; neighbors . add ( solutionSet . get ( index ) ) ; } return neighbors ; } | Returns a solutionSet containing the neighbors of a given solution | 86 | 11 |
31,625 | double betaFunction ( List < Double > x , int type ) { double beta ; beta = 0 ; int dim = x . size ( ) ; if ( dim == 0 ) { beta = 0 ; } if ( type == 1 ) { beta = 0 ; for ( int i = 0 ; i < dim ; i ++ ) { beta += x . get ( i ) * x . get ( i ) ; } beta = 2.0 * beta / dim ; } if ( type == 2 ) { beta = 0 ; for ( int i = 0 ; i < dim ; i ++ ) { beta += Math . sqrt ( i + 1 ) * x . get ( i ) * x . get ( i ) ; } beta = 2.0 * beta / dim ; } if ( type == 3 ) { double sum = 0 , xx ; for ( int i = 0 ; i < dim ; i ++ ) { xx = 2 * x . get ( i ) ; sum += ( xx * xx - Math . cos ( 4 * Math . PI * xx ) + 1 ) ; } beta = 2.0 * sum / dim ; } if ( type == 4 ) { double sum = 0 , prod = 1 , xx ; for ( int i = 0 ; i < dim ; i ++ ) { xx = 2 * x . get ( i ) ; sum += xx * xx ; prod *= Math . cos ( 10 * Math . PI * xx / Math . sqrt ( i + 1 ) ) ; } beta = 2.0 * ( sum - 2 * prod + 2 ) / dim ; } return beta ; } | control the distance | 335 | 3 |
31,626 | double psfunc3 ( double x , double t1 , double t2 , int dim , int type ) { // type: the type of curve // css: the class of index double beta ; beta = 0.0 ; dim ++ ; if ( type == 31 ) { double xy = 4 * ( x - 0.5 ) ; double rate = 1.0 * dim / nvar ; beta = xy - 4 * ( t1 * t1 * rate + t2 * ( 1.0 - rate ) ) + 2 ; } if ( type == 32 ) { double theta = 2 * Math . PI * t1 + dim * Math . PI / nvar ; double xy = 4 * ( x - 0.5 ) ; beta = xy - 2 * t2 * Math . sin ( theta ) ; } return beta ; } | control the PS shapes of 3 - D instances | 180 | 9 |
31,627 | @ Override public int compare ( S solution1 , S solution2 ) { int result ; if ( solution1 == null ) { if ( solution2 == null ) { result = 0 ; } else { result = 1 ; } } else if ( solution2 == null ) { result = - 1 ; } else if ( solution1 . getNumberOfObjectives ( ) <= objectiveId ) { throw new JMetalException ( "The solution1 has " + solution1 . getNumberOfObjectives ( ) + " objectives " + "and the objective to sort is " + objectiveId ) ; } else if ( solution2 . getNumberOfObjectives ( ) <= objectiveId ) { throw new JMetalException ( "The solution2 has " + solution2 . getNumberOfObjectives ( ) + " objectives " + "and the objective to sort is " + objectiveId ) ; } else { Double objective1 = solution1 . getObjective ( this . objectiveId ) ; Double objective2 = solution2 . getObjective ( this . objectiveId ) ; if ( order == Ordering . ASCENDING ) { result = Double . compare ( objective1 , objective2 ) ; } else { result = Double . compare ( objective2 , objective1 ) ; } } return result ; } | Compares two solutions according to a given objective . | 266 | 10 |
31,628 | @ Override public boolean add ( S solution ) { boolean solutionInserted = false ; if ( solutionList . size ( ) == 0 ) { solutionList . add ( solution ) ; solutionInserted = true ; } else { Iterator < S > iterator = solutionList . iterator ( ) ; boolean isDominated = false ; boolean isContained = false ; while ( ( ( ! isDominated ) && ( ! isContained ) ) && ( iterator . hasNext ( ) ) ) { S listIndividual = iterator . next ( ) ; int flag = dominanceComparator . compare ( solution , listIndividual ) ; if ( flag == - 1 ) { iterator . remove ( ) ; } else if ( flag == 1 ) { isDominated = true ; // dominated by one in the list } else if ( flag == 0 ) { int equalflag = equalSolutions . compare ( solution , listIndividual ) ; if ( equalflag == 0 ) // solutions are equals isContained = true ; } } if ( ! isDominated && ! isContained ) { solutionList . add ( solution ) ; solutionInserted = true ; } return solutionInserted ; } return solutionInserted ; } | Inserts a solution in the list | 250 | 7 |
31,629 | private static boolean checkAboutNormalization ( String args [ ] ) { boolean normalize = false ; if ( args . length == 4 ) { if ( args [ 3 ] . equals ( "TRUE" ) ) { normalize = true ; } else if ( args [ 3 ] . equals ( "FALSE" ) ) { normalize = false ; } else { throw new JMetalException ( "The value for normalizing must be TRUE or FALSE" ) ; } } return normalize ; } | Checks if normalization is set | 103 | 7 |
31,630 | private static QualityIndicator < List < PointSolution > , Double > getIndicatorFromName ( String name , List < QualityIndicator < List < PointSolution > , Double > > list ) { QualityIndicator < List < PointSolution > , Double > result = null ; for ( QualityIndicator < List < PointSolution > , Double > indicator : list ) { if ( indicator . getName ( ) . equals ( name ) ) { result = indicator ; } } if ( result == null ) { throw new JMetalException ( "Indicator " + name + " not available" ) ; } return result ; } | Given an indicator name finds the indicator in the list of indicator | 128 | 12 |
31,631 | @ Override public double getDistance ( S solution , L solutionList ) { List < Double > listOfDistances = knnDistances ( solution , solutionList ) ; listOfDistances . sort ( Comparator . naturalOrder ( ) ) ; int limit = Math . min ( k , listOfDistances . size ( ) ) ; double result ; if ( limit == 0 ) { result = 0.0 ; } else { double sum = 0.0 ; for ( int i = 0 ; i < limit ; i ++ ) { sum += listOfDistances . get ( i ) ; } result = sum / limit ; } return result ; } | Computes the knn distance . If the solution list size is lower than k then k = size in the computation | 136 | 23 |
31,632 | private List < Double > knnDistances ( S solution , L solutionList ) { List < Double > listOfDistances = new ArrayList <> ( ) ; for ( int i = 0 ; i < solutionList . size ( ) ; i ++ ) { double distanceBetweenSolutions = distance . getDistance ( solution , solutionList . get ( i ) ) ; if ( distanceBetweenSolutions != 0 ) { listOfDistances . add ( distanceBetweenSolutions ) ; } } return listOfDistances ; } | Computes the distance between a solution and the solutions of a list . Distances equal to 0 are ignored . | 109 | 22 |
31,633 | @ Override public int compare ( S solution1 , S solution2 ) { int result ; if ( solution1 == null ) { if ( solution2 == null ) { result = 0 ; } else { result = 1 ; } } else if ( solution2 == null ) { result = - 1 ; } else { int rank1 = Integer . MAX_VALUE ; int rank2 = Integer . MAX_VALUE ; if ( ranking . getAttribute ( solution1 ) != null ) { rank1 = ( int ) ranking . getAttribute ( solution1 ) ; } if ( ranking . getAttribute ( solution2 ) != null ) { rank2 = ( int ) ranking . getAttribute ( solution2 ) ; } if ( rank1 < rank2 ) { result = - 1 ; } else if ( rank1 > rank2 ) { result = 1 ; } else { result = 0 ; } } return result ; } | Compares two solutions according to the ranking attribute . The lower the ranking the better | 187 | 16 |
31,634 | public float [ ] calculateX ( float [ ] t ) { float [ ] x = new float [ m ] ; for ( int i = 0 ; i < m - 1 ; i ++ ) { x [ i ] = Math . max ( t [ m - 1 ] , a [ i ] ) * ( t [ i ] - ( float ) 0.5 ) + ( float ) 0.5 ; } x [ m - 1 ] = t [ m - 1 ] ; return x ; } | Gets the x vector | 103 | 5 |
31,635 | public static < S > int findIndexOfBestSolution ( List < S > solutionList , Comparator < S > comparator ) { if ( solutionList == null ) { throw new NullSolutionListException ( ) ; } else if ( solutionList . isEmpty ( ) ) { throw new EmptySolutionListException ( ) ; } else if ( comparator == null ) { throw new JMetalException ( "The comparator is null" ) ; } int index = 0 ; S bestKnown = solutionList . get ( 0 ) ; S candidateSolution ; int flag ; for ( int i = 1 ; i < solutionList . size ( ) ; i ++ ) { candidateSolution = solutionList . get ( i ) ; flag = comparator . compare ( bestKnown , candidateSolution ) ; if ( flag == 1 ) { index = i ; bestKnown = candidateSolution ; } } return index ; } | Finds the index of the best solution in the list according to a comparator | 185 | 16 |
31,636 | public static List < ? extends Solution < ? > > normalize ( List < ? extends Solution < ? > > solutions , double [ ] minValues , double [ ] maxValues ) { List < Solution < ? > > normalizedSolutions = new ArrayList <> ( solutions . size ( ) ) ; for ( Solution < ? > solution : solutions ) { normalizedSolutions . add ( SolutionUtils . normalize ( solution , minValues , maxValues ) ) ; } return normalizedSolutions ; } | This method receives a list of non - dominated solutions and maximum and minimum values of the objectives and returns a normalized set of solutions . | 103 | 26 |
31,637 | public static < S extends Solution < ? > > double [ ] [ ] distanceMatrix ( List < S > solutionSet ) { double [ ] [ ] distance = new double [ solutionSet . size ( ) ] [ solutionSet . size ( ) ] ; for ( int i = 0 ; i < solutionSet . size ( ) ; i ++ ) { distance [ i ] [ i ] = 0.0 ; for ( int j = i + 1 ; j < solutionSet . size ( ) ; j ++ ) { distance [ i ] [ j ] = SolutionUtils . distanceBetweenObjectives ( solutionSet . get ( i ) , solutionSet . get ( j ) ) ; distance [ j ] [ i ] = distance [ i ] [ j ] ; } } return distance ; } | Returns a matrix with the euclidean distance between each pair of solutions in the population . Distances are measured in the objective space | 162 | 27 |
31,638 | public static < S > boolean solutionListsAreEquals ( List < S > solutionList , List < S > newSolutionList ) { boolean found ; for ( int i = 0 ; i < solutionList . size ( ) ; i ++ ) { int j = 0 ; found = false ; while ( j < newSolutionList . size ( ) ) { if ( solutionList . get ( i ) . equals ( newSolutionList . get ( j ) ) ) { found = true ; } j ++ ; } if ( ! found ) { return false ; } } return true ; } | Compares two solution lists to determine if both are equals | 121 | 11 |
31,639 | public static < S > void restart ( List < S > solutionList , Problem < S > problem , int percentageOfSolutionsToRemove ) { if ( solutionList == null ) { throw new NullSolutionListException ( ) ; } else if ( problem == null ) { throw new JMetalException ( "The problem is null" ) ; } else if ( ( percentageOfSolutionsToRemove < 0 ) || ( percentageOfSolutionsToRemove > 100 ) ) { throw new JMetalException ( "The percentage of solutions to remove is invalid: " + percentageOfSolutionsToRemove ) ; } int solutionListOriginalSize = solutionList . size ( ) ; int numberOfSolutionsToRemove = ( int ) ( solutionListOriginalSize * percentageOfSolutionsToRemove / 100.0 ) ; removeSolutionsFromList ( solutionList , numberOfSolutionsToRemove ) ; fillPopulationWithNewSolutions ( solutionList , problem , solutionListOriginalSize ) ; } | This methods takes a list of solutions removes a percentage of its solutions and it is filled with new random generated solutions | 202 | 22 |
31,640 | public static < S > void removeSolutionsFromList ( List < S > solutionList , int numberOfSolutionsToRemove ) { if ( solutionList . size ( ) < numberOfSolutionsToRemove ) { throw new JMetalException ( "The list size (" + solutionList . size ( ) + ") is lower than " + "the number of solutions to remove (" + numberOfSolutionsToRemove + ")" ) ; } for ( int i = 0 ; i < numberOfSolutionsToRemove ; i ++ ) { solutionList . remove ( 0 ) ; } } | Removes a number of solutions from a list | 122 | 9 |
31,641 | public static < S > void fillPopulationWithNewSolutions ( List < S > solutionList , Problem < S > problem , int maxListSize ) { while ( solutionList . size ( ) < maxListSize ) { solutionList . add ( problem . createSolution ( ) ) ; } } | Fills a population with new solutions until its size is maxListSize | 61 | 14 |
31,642 | public double repairSolutionVariableValue ( double value , double lowerBound , double upperBound ) { if ( lowerBound > upperBound ) { throw new JMetalException ( "The lower bound (" + lowerBound + ") is greater than the " + "upper bound (" + upperBound + ")" ) ; } double result = value ; if ( value < lowerBound ) { result = randomGenerator . getRandomValue ( lowerBound , upperBound ) ; } if ( value > upperBound ) { result = randomGenerator . getRandomValue ( lowerBound , upperBound ) ; } return result ; } | Checks if the value is between its bounds ; if not a random value between the limits is returned | 125 | 20 |
31,643 | public static < S extends Solution < ? > > S getBestSolution ( S solution1 , S solution2 , Comparator < S > comparator , BinaryOperator < S > equalityPolicy ) { S result ; int flag = comparator . compare ( solution1 , solution2 ) ; if ( flag == - 1 ) { result = solution1 ; } else if ( flag == 1 ) { result = solution2 ; } else { result = equalityPolicy . apply ( solution1 , solution2 ) ; } return result ; } | Return the best solution between those passed as arguments . If they are equal or incomparable one of them is chosen based on the given policy . | 108 | 28 |
31,644 | public static < S extends Solution < ? > > double distanceBetweenObjectives ( S firstSolution , S secondSolution ) { double diff ; double distance = 0.0 ; //euclidean distance for ( int nObj = 0 ; nObj < firstSolution . getNumberOfObjectives ( ) ; nObj ++ ) { diff = firstSolution . getObjective ( nObj ) - secondSolution . getObjective ( nObj ) ; distance += Math . pow ( diff , 2.0 ) ; } return Math . sqrt ( distance ) ; } | Returns the euclidean distance between a pair of solutions in the objective space | 116 | 16 |
31,645 | public static double distanceBetweenSolutionsInObjectiveSpace ( DoubleSolution solutionI , DoubleSolution solutionJ ) { double distance = 0.0 ; double diff ; for ( int i = 0 ; i < solutionI . getNumberOfVariables ( ) ; i ++ ) { diff = solutionI . getVariableValue ( i ) - solutionJ . getVariableValue ( i ) ; distance += Math . pow ( diff , 2.0 ) ; } return Math . sqrt ( distance ) ; } | Returns the distance between two solutions in the search space . | 103 | 11 |
31,646 | public static < S extends Solution < ? > > double averageDistanceToSolutionList ( S solution , List < S > solutionList ) { double sumOfDistances = 0.0 ; for ( S sol : solutionList ) { sumOfDistances += distanceBetweenObjectives ( solution , sol ) ; } return sumOfDistances / solutionList . size ( ) ; } | Returns the average euclidean distance of a solution to the solutions of a list . | 77 | 18 |
31,647 | public static Solution < ? > normalize ( Solution < ? > solution , double [ ] minValues , double [ ] maxValues ) { if ( solution == null ) { throw new JMetalException ( "The solution should not be null" ) ; } if ( minValues == null || maxValues == null ) { throw new JMetalException ( "The minValues and maxValues should not be null" ) ; } if ( minValues . length == 0 || maxValues . length == 0 ) { throw new JMetalException ( "The minValues and maxValues should not be empty" ) ; } if ( minValues . length != maxValues . length ) { throw new JMetalException ( "The minValues and maxValues should have the same length" ) ; } if ( solution . getNumberOfObjectives ( ) != minValues . length ) { throw new JMetalException ( "The number of objectives should be the same to min and max length" ) ; } Solution < ? > copy = ( Solution < ? > ) solution . copy ( ) ; for ( int i = 0 ; i < copy . getNumberOfObjectives ( ) ; i ++ ) { copy . setObjective ( i , NormalizeUtils . normalize ( solution . getObjective ( i ) , minValues [ i ] , maxValues [ i ] ) ) ; } return copy ; } | It returns the normalized solution given the minimum and maximum values for each objective | 286 | 14 |
31,648 | public static void tred2 ( int n , double v [ ] [ ] , double d [ ] , double e [ ] ) { // This is derived from the Algol procedures tred2 by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. System . arraycopy ( v [ n - 1 ] , 0 , d , 0 , n ) ; // Householder reduction to tridiagonal form. for ( int i = n - 1 ; i > 0 ; i -- ) { // Scale to avoid under/overflow. double scale = 0.0 ; double h = 0.0 ; for ( int k = 0 ; k < i ; k ++ ) { scale = scale + Math . abs ( d [ k ] ) ; } if ( scale == 0.0 ) { e [ i ] = d [ i - 1 ] ; for ( int j = 0 ; j < i ; j ++ ) { d [ j ] = v [ i - 1 ] [ j ] ; v [ i ] [ j ] = 0.0 ; v [ j ] [ i ] = 0.0 ; } } else { h = householderIteration ( i , scale , v , d , e ) ; } d [ i ] = h ; } // Accumulate transformations. accumulateTransformations ( n , v , d ) ; e [ 0 ] = 0.0 ; } | Symmetric Householder reduction to tridiagonal form taken from JAMA package . | 321 | 17 |
31,649 | public static void tql2 ( int n , double d [ ] , double e [ ] , double v [ ] [ ] ) { // This is derived from the Algol procedures tql2, by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. System . arraycopy ( e , 1 , e , 0 , n - 1 ) ; e [ n - 1 ] = 0.0 ; double f = 0.0 ; double tst1 = 0.0 ; double eps = Math . pow ( 2.0 , - 52.0 ) ; for ( int l = 0 ; l < n ; l ++ ) { // Find small subdiagonal element tst1 = Math . max ( tst1 , Math . abs ( d [ l ] ) + Math . abs ( e [ l ] ) ) ; int m = l ; while ( m < n ) { if ( Math . abs ( e [ m ] ) <= eps * tst1 ) { break ; } m ++ ; } // If m == l, d[l] is an eigenvalue, // otherwise, iterate. if ( m > l ) { int iter = 0 ; do { iter = iter + 1 ; // (Could check iteration count here.) // Compute implicit shift f += specificShift ( l , n , d , e ) ; // Implicit QL transformation. implicitQLTransformation ( l , m , n , v , d , e ) ; // Check for convergence. } while ( Math . abs ( e [ l ] ) > eps * tst1 ) ; } d [ l ] = d [ l ] + f ; e [ l ] = 0.0 ; } // Sort eigenvalues and corresponding vectors. sortEigenValues ( n , d , v ) ; } | Symmetric tridiagonal QL algorithm taken from JAMA package . | 410 | 15 |
31,650 | public float [ ] t1 ( float [ ] z , int k ) { float [ ] result = new float [ z . length ] ; for ( int i = 0 ; i < z . length ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . sDecept ( z [ i ] , ( float ) 0.35 , ( float ) 0.001 , ( float ) 0.05 ) ; } return result ; } | WFG5 t1 transformation | 95 | 6 |
31,651 | double calculateHypervolumeIndicator ( Solution < ? > solutionA , Solution < ? > solutionB , int d , double maximumValues [ ] , double minimumValues [ ] ) { double a , b , r , max ; double volume ; double rho = 2.0 ; r = rho * ( maximumValues [ d - 1 ] - minimumValues [ d - 1 ] ) ; max = minimumValues [ d - 1 ] + r ; a = solutionA . getObjective ( d - 1 ) ; if ( solutionB == null ) { b = max ; } else { b = solutionB . getObjective ( d - 1 ) ; } if ( d == 1 ) { if ( a < b ) { volume = ( b - a ) / r ; } else { volume = 0 ; } } else { if ( a < b ) { volume = calculateHypervolumeIndicator ( solutionA , null , d - 1 , maximumValues , minimumValues ) * ( b - a ) / r ; volume += calculateHypervolumeIndicator ( solutionA , solutionB , d - 1 , maximumValues , minimumValues ) * ( max - b ) / r ; } else { volume = calculateHypervolumeIndicator ( solutionA , solutionB , d - 1 , maximumValues , minimumValues ) * ( max - a ) / r ; } } return ( volume ) ; } | Calculates the hypervolume of that portion of the objective space that is dominated by individual a but not by individual b | 287 | 24 |
31,652 | public void computeIndicatorValuesHD ( List < S > solutionSet , double [ ] maximumValues , double [ ] minimumValues ) { List < S > A , B ; // Initialize the structures indicatorValues = new ArrayList < List < Double > > ( ) ; maxIndicatorValue = - Double . MAX_VALUE ; for ( int j = 0 ; j < solutionSet . size ( ) ; j ++ ) { A = new ArrayList <> ( 1 ) ; A . add ( solutionSet . get ( j ) ) ; List < Double > aux = new ArrayList < Double > ( ) ; for ( S solution : solutionSet ) { B = new ArrayList <> ( 1 ) ; B . add ( solution ) ; int flag = ( new DominanceComparator < S > ( ) ) . compare ( A . get ( 0 ) , B . get ( 0 ) ) ; double value ; if ( flag == - 1 ) { value = - calculateHypervolumeIndicator ( A . get ( 0 ) , B . get ( 0 ) , problem . getNumberOfObjectives ( ) , maximumValues , minimumValues ) ; } else { value = calculateHypervolumeIndicator ( B . get ( 0 ) , A . get ( 0 ) , problem . getNumberOfObjectives ( ) , maximumValues , minimumValues ) ; } //Update the max value of the indicator if ( Math . abs ( value ) > maxIndicatorValue ) { maxIndicatorValue = Math . abs ( value ) ; } aux . add ( value ) ; } indicatorValues . add ( aux ) ; } } | This structure stores the indicator values of each pair of elements | 335 | 11 |
31,653 | public void fitness ( List < S > solutionSet , int pos ) { double fitness = 0.0 ; double kappa = 0.05 ; for ( int i = 0 ; i < solutionSet . size ( ) ; i ++ ) { if ( i != pos ) { fitness += Math . exp ( ( - 1 * indicatorValues . get ( i ) . get ( pos ) / maxIndicatorValue ) / kappa ) ; } } solutionFitness . setAttribute ( solutionSet . get ( pos ) , fitness ) ; } | Calculate the fitness for the individual at position pos | 111 | 11 |
31,654 | public void calculateFitness ( List < S > solutionSet ) { // Obtains the lower and upper bounds of the population double [ ] maximumValues = new double [ problem . getNumberOfObjectives ( ) ] ; double [ ] minimumValues = new double [ problem . getNumberOfObjectives ( ) ] ; for ( int i = 0 ; i < problem . getNumberOfObjectives ( ) ; i ++ ) { maximumValues [ i ] = - Double . MAX_VALUE ; minimumValues [ i ] = Double . MAX_VALUE ; } for ( S solution : solutionSet ) { for ( int obj = 0 ; obj < problem . getNumberOfObjectives ( ) ; obj ++ ) { double value = solution . getObjective ( obj ) ; if ( value > maximumValues [ obj ] ) { maximumValues [ obj ] = value ; } if ( value < minimumValues [ obj ] ) { minimumValues [ obj ] = value ; } } } computeIndicatorValuesHD ( solutionSet , maximumValues , minimumValues ) ; for ( int pos = 0 ; pos < solutionSet . size ( ) ; pos ++ ) { fitness ( solutionSet , pos ) ; } } | Calculate the fitness for the entire population . | 246 | 10 |
31,655 | public void removeWorst ( List < S > solutionSet ) { // Find the worst; double worst = ( double ) solutionFitness . getAttribute ( solutionSet . get ( 0 ) ) ; int worstIndex = 0 ; double kappa = 0.05 ; for ( int i = 1 ; i < solutionSet . size ( ) ; i ++ ) { if ( ( double ) solutionFitness . getAttribute ( solutionSet . get ( i ) ) > worst ) { worst = ( double ) solutionFitness . getAttribute ( solutionSet . get ( i ) ) ; worstIndex = i ; } } // Update the population for ( int i = 0 ; i < solutionSet . size ( ) ; i ++ ) { if ( i != worstIndex ) { double fitness = ( double ) solutionFitness . getAttribute ( solutionSet . get ( i ) ) ; fitness -= Math . exp ( ( - indicatorValues . get ( worstIndex ) . get ( i ) / maxIndicatorValue ) / kappa ) ; solutionFitness . setAttribute ( solutionSet . get ( i ) , fitness ) ; } } // remove worst from the indicatorValues list indicatorValues . remove ( worstIndex ) ; for ( List < Double > anIndicatorValues_ : indicatorValues ) { anIndicatorValues_ . remove ( worstIndex ) ; } solutionSet . remove ( worstIndex ) ; } | Update the fitness before removing an individual | 289 | 7 |
31,656 | public double evaluate ( List < ? extends Solution < ? > > set1 , List < ? extends Solution < ? > > set2 ) { double result ; int sum = 0 ; if ( set2 . size ( ) == 0 ) { if ( set1 . size ( ) == 0 ) { result = 0.0 ; } else { result = 1.0 ; } } else { for ( Solution < ? > solution : set2 ) { if ( SolutionListUtils . isSolutionDominatedBySolutionList ( solution , set1 ) ) { sum ++ ; } } result = ( double ) sum / set2 . size ( ) ; } return result ; } | Calculates the set coverage of set1 over set2 | 138 | 12 |
31,657 | protected void checkNumberOfParents ( List < S > population , int numberOfParentsForCrossover ) { if ( ( population . size ( ) % numberOfParentsForCrossover ) != 0 ) { throw new JMetalException ( "Wrong number of parents: the remainder if the " + "population size (" + population . size ( ) + ") is not divisible by " + numberOfParentsForCrossover ) ; } } | A crossover operator is applied to a number of parents and it assumed that the population contains a valid number of solutions . This method checks that . | 91 | 28 |
31,658 | public int location ( S solution ) { //Create a int [] to store the range of each objective int [ ] position = new int [ numberOfObjectives ] ; //Calculate the position for each objective for ( int obj = 0 ; obj < numberOfObjectives ; obj ++ ) { if ( ( solution . getObjective ( obj ) > gridUpperLimits [ obj ] ) || ( solution . getObjective ( obj ) < gridLowerLimits [ obj ] ) ) { return - 1 ; } else if ( solution . getObjective ( obj ) == gridLowerLimits [ obj ] ) { position [ obj ] = 0 ; } else if ( solution . getObjective ( obj ) == gridUpperLimits [ obj ] ) { position [ obj ] = ( ( int ) Math . pow ( 2.0 , bisections ) ) - 1 ; } else { double tmpSize = divisionSize [ obj ] ; double value = solution . getObjective ( obj ) ; double account = gridLowerLimits [ obj ] ; int ranges = ( int ) Math . pow ( 2.0 , bisections ) ; for ( int b = 0 ; b < bisections ; b ++ ) { tmpSize /= 2.0 ; ranges /= 2 ; if ( value > ( account + tmpSize ) ) { position [ obj ] += ranges ; account += tmpSize ; } } } } //Calculate the location into the hypercubes int location = 0 ; for ( int obj = 0 ; obj < numberOfObjectives ; obj ++ ) { location += position [ obj ] * Math . pow ( 2.0 , obj * bisections ) ; } return location ; } | Calculates the hypercube of a solution | 358 | 9 |
31,659 | public void removeSolution ( int location ) { //Decrease the solutions in the location specified. hypercubes [ location ] -- ; //Update the most populated hypercube if ( location == mostPopulatedHypercube ) { for ( int i = 0 ; i < hypercubes . length ; i ++ ) { if ( hypercubes [ i ] > hypercubes [ mostPopulatedHypercube ] ) { mostPopulatedHypercube = i ; } } } //If hypercubes[location] now becomes to zero, then update ocuppied hypercubes if ( hypercubes [ location ] == 0 ) { this . calculateOccupied ( ) ; } } | Decreases the number of solutions into a specific hypercube . | 140 | 12 |
31,660 | public void addSolution ( int location ) { //Increase the solutions in the location specified. hypercubes [ location ] ++ ; //Update the most populated hypercube if ( hypercubes [ location ] > hypercubes [ mostPopulatedHypercube ] ) { mostPopulatedHypercube = location ; } //if hypercubes[location] becomes to one, then recalculate //the occupied hypercubes if ( hypercubes [ location ] == 1 ) { this . calculateOccupied ( ) ; } } | Increases the number of solutions into a specific hypercube . | 107 | 11 |
31,661 | public int rouletteWheel ( BoundedRandomGenerator < Double > randomGenerator ) { //Calculate the inverse sum double inverseSum = 0.0 ; for ( int hypercube : hypercubes ) { if ( hypercube > 0 ) { inverseSum += 1.0 / ( double ) hypercube ; } } //Calculate a random value between 0 and sumaInversa double random = randomGenerator . getRandomValue ( 0.0 , inverseSum ) ; int hypercube = 0 ; double accumulatedSum = 0.0 ; while ( hypercube < hypercubes . length ) { if ( hypercubes [ hypercube ] > 0 ) { accumulatedSum += 1.0 / ( double ) hypercubes [ hypercube ] ; } if ( accumulatedSum > random ) { return hypercube ; } hypercube ++ ; } return hypercube ; } | Returns a random hypercube using a rouleteWheel method . | 183 | 12 |
31,662 | public void calculateOccupied ( ) { int total = 0 ; for ( int hypercube : hypercubes ) { if ( hypercube > 0 ) { total ++ ; } } occupied = new int [ total ] ; int base = 0 ; for ( int i = 0 ; i < hypercubes . length ; i ++ ) { if ( hypercubes [ i ] > 0 ) { occupied [ base ] = i ; base ++ ; } } } | Calculates the number of hypercubes having one or more solutions . return the number of hypercubes with more than zero solutions . | 94 | 28 |
31,663 | public int randomOccupiedHypercube ( BoundedRandomGenerator < Integer > randomGenerator ) { int rand = randomGenerator . getRandomValue ( 0 , occupied . length - 1 ) ; return occupied [ rand ] ; } | Returns a random hypercube that has more than zero solutions . | 48 | 12 |
31,664 | public double getAverageOccupation ( ) { calculateOccupied ( ) ; double result ; if ( occupiedHypercubes ( ) == 0 ) { result = 0.0 ; } else { double sum = 0.0 ; for ( int value : occupied ) { sum += hypercubes [ value ] ; } result = sum / occupiedHypercubes ( ) ; } return result ; } | Return the average number of solutions in the occupied hypercubes | 80 | 12 |
31,665 | public static double [ ] getMaximumValues ( Front front ) { if ( front == null ) { throw new NullFrontException ( ) ; } else if ( front . getNumberOfPoints ( ) == 0 ) { throw new EmptyFrontException ( ) ; } int numberOfObjectives = front . getPoint ( 0 ) . getDimension ( ) ; double [ ] maximumValue = new double [ numberOfObjectives ] ; for ( int i = 0 ; i < numberOfObjectives ; i ++ ) { maximumValue [ i ] = Double . NEGATIVE_INFINITY ; } for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { for ( int j = 0 ; j < numberOfObjectives ; j ++ ) { if ( front . getPoint ( i ) . getValue ( j ) > maximumValue [ j ] ) { maximumValue [ j ] = front . getPoint ( i ) . getValue ( j ) ; } } } return maximumValue ; } | Gets the maximum values for each objectives in a front | 214 | 11 |
31,666 | public static double [ ] getMinimumValues ( Front front ) { if ( front == null ) { throw new NullFrontException ( ) ; } else if ( front . getNumberOfPoints ( ) == 0 ) { throw new EmptyFrontException ( ) ; } int numberOfObjectives = front . getPoint ( 0 ) . getDimension ( ) ; double [ ] minimumValue = new double [ numberOfObjectives ] ; for ( int i = 0 ; i < numberOfObjectives ; i ++ ) { minimumValue [ i ] = Double . MAX_VALUE ; } for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { for ( int j = 0 ; j < numberOfObjectives ; j ++ ) { if ( front . getPoint ( i ) . getValue ( j ) < minimumValue [ j ] ) { minimumValue [ j ] = front . getPoint ( i ) . getValue ( j ) ; } } } return minimumValue ; } | Gets the minimum values for each objectives in a given front | 210 | 12 |
31,667 | public static double distanceToNearestPoint ( Point point , Front front , PointDistance distance ) { if ( front == null ) { throw new NullFrontException ( ) ; } else if ( front . getNumberOfPoints ( ) == 0 ) { throw new EmptyFrontException ( ) ; } else if ( point == null ) { throw new JMetalException ( "The point is null" ) ; } double minDistance = Double . MAX_VALUE ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { double aux = distance . compute ( point , front . getPoint ( i ) ) ; if ( ( aux < minDistance ) && ( aux > 0.0 ) ) { minDistance = aux ; } } return minDistance ; } | Gets the distance between a point and the nearest one in a front . If a distance equals to 0 is found that means that the point is in the front so it is excluded | 163 | 36 |
31,668 | public static Front getInvertedFront ( Front front ) { if ( front == null ) { throw new NullFrontException ( ) ; } else if ( front . getNumberOfPoints ( ) == 0 ) { throw new EmptyFrontException ( ) ; } int numberOfDimensions = front . getPoint ( 0 ) . getDimension ( ) ; Front invertedFront = new ArrayFront ( front . getNumberOfPoints ( ) , numberOfDimensions ) ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { for ( int j = 0 ; j < numberOfDimensions ; j ++ ) { if ( front . getPoint ( i ) . getValue ( j ) <= 1.0 && front . getPoint ( i ) . getValue ( j ) >= 0.0 ) { invertedFront . getPoint ( i ) . setValue ( j , 1.0 - front . getPoint ( i ) . getValue ( j ) ) ; } else if ( front . getPoint ( i ) . getValue ( j ) > 1.0 ) { invertedFront . getPoint ( i ) . setValue ( j , 0.0 ) ; } else if ( front . getPoint ( i ) . getValue ( j ) < 0.0 ) { invertedFront . getPoint ( i ) . setValue ( j , 1.0 ) ; } } } return invertedFront ; } | This method receives a normalized pareto front and return the inverted one . This method is for minimization problems | 299 | 22 |
31,669 | public static double [ ] [ ] convertFrontToArray ( Front front ) { if ( front == null ) { throw new NullFrontException ( ) ; } double [ ] [ ] arrayFront = new double [ front . getNumberOfPoints ( ) ] [ ] ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { arrayFront [ i ] = new double [ front . getPoint ( i ) . getDimension ( ) ] ; for ( int j = 0 ; j < front . getPoint ( i ) . getDimension ( ) ; j ++ ) { arrayFront [ i ] [ j ] = front . getPoint ( i ) . getValue ( j ) ; } } return arrayFront ; } | Given a front converts it to an array of double values | 158 | 11 |
31,670 | public static List < PointSolution > convertFrontToSolutionList ( Front front ) { if ( front == null ) { throw new NullFrontException ( ) ; } int numberOfObjectives ; int solutionSetSize = front . getNumberOfPoints ( ) ; if ( front . getNumberOfPoints ( ) == 0 ) { numberOfObjectives = 0 ; } else { numberOfObjectives = front . getPoint ( 0 ) . getDimension ( ) ; } List < PointSolution > solutionSet = new ArrayList <> ( solutionSetSize ) ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { PointSolution solution = new PointSolution ( numberOfObjectives ) ; for ( int j = 0 ; j < numberOfObjectives ; j ++ ) { solution . setObjective ( j , front . getPoint ( i ) . getValue ( j ) ) ; } solutionSet . add ( solution ) ; } return solutionSet ; } | Given a front converts it to a Solution set of PointSolutions | 208 | 13 |
31,671 | public List < PermutationSolution < Integer > > execute ( List < PermutationSolution < Integer > > parents ) { if ( null == parents ) { throw new JMetalException ( "Null parameter" ) ; } else if ( parents . size ( ) != 2 ) { throw new JMetalException ( "There must be two parents instead of " + parents . size ( ) ) ; } return doCrossover ( crossoverProbability , parents ) ; } | Executes the operation | 96 | 4 |
31,672 | @ Override public int compare ( Point pointOne , Point pointTwo ) { if ( pointOne == null ) { throw new JMetalException ( "PointOne is null" ) ; } else if ( pointTwo == null ) { throw new JMetalException ( "PointTwo is null" ) ; } else if ( pointOne . getDimension ( ) != pointTwo . getDimension ( ) ) { throw new JMetalException ( "Points have different size: " + pointOne . getDimension ( ) + " and " + pointTwo . getDimension ( ) ) ; } for ( int i = pointOne . getDimension ( ) - 1 ; i >= 0 ; i -- ) { if ( isBetter ( pointOne . getValue ( i ) , pointTwo . getValue ( i ) ) ) { return - 1 ; } else if ( isBetter ( pointTwo . getValue ( i ) , pointOne . getValue ( i ) ) ) { return 1 ; } } return 0 ; } | Compares two Point objects | 212 | 5 |
31,673 | public double spread ( Front front , Front referenceFront ) { PointDistance distance = new EuclideanDistance ( ) ; // STEP 1. Sort normalizedFront and normalizedParetoFront; front . sort ( new LexicographicalPointComparator ( ) ) ; referenceFront . sort ( new LexicographicalPointComparator ( ) ) ; // STEP 2. Compute df and dl (See specifications in Deb's description of the metric) double df = distance . compute ( front . getPoint ( 0 ) , referenceFront . getPoint ( 0 ) ) ; double dl = distance . compute ( front . getPoint ( front . getNumberOfPoints ( ) - 1 ) , referenceFront . getPoint ( referenceFront . getNumberOfPoints ( ) - 1 ) ) ; double mean = 0.0 ; double diversitySum = df + dl ; int numberOfPoints = front . getNumberOfPoints ( ) ; // STEP 3. Calculate the mean of distances between points i and (i - 1). // (the points are in lexicografical order) for ( int i = 0 ; i < ( numberOfPoints - 1 ) ; i ++ ) { mean += distance . compute ( front . getPoint ( i ) , front . getPoint ( i + 1 ) ) ; } mean = mean / ( double ) ( numberOfPoints - 1 ) ; // STEP 4. If there are more than a single point, continue computing the // metric. In other case, return the worse value (1.0, see metric's description). if ( numberOfPoints > 1 ) { for ( int i = 0 ; i < ( numberOfPoints - 1 ) ; i ++ ) { diversitySum += Math . abs ( distance . compute ( front . getPoint ( i ) , front . getPoint ( i + 1 ) ) - mean ) ; } return diversitySum / ( df + dl + ( numberOfPoints - 1 ) * mean ) ; } else { return 1.0 ; } } | Calculates the Spread metric . | 416 | 7 |
31,674 | private double hypervolume ( Front front , Front referenceFront ) { Front invertedFront ; invertedFront = FrontUtils . getInvertedFront ( front ) ; int numberOfObjectives = referenceFront . getPoint ( 0 ) . getDimension ( ) ; // STEP4. The hypervolume (control is passed to the Java version of Zitzler code) return this . calculateHypervolume ( FrontUtils . convertFrontToArray ( invertedFront ) , invertedFront . getNumberOfPoints ( ) , numberOfObjectives ) ; } | Returns the hypervolume value of a front of points | 111 | 10 |
31,675 | private double [ ] hvContributions ( double [ ] [ ] front ) { int numberOfObjectives = front [ 0 ] . length ; double [ ] contributions = new double [ front . length ] ; double [ ] [ ] frontSubset = new double [ front . length - 1 ] [ front [ 0 ] . length ] ; LinkedList < double [ ] > frontCopy = new LinkedList < double [ ] > ( ) ; Collections . addAll ( frontCopy , front ) ; double [ ] [ ] totalFront = frontCopy . toArray ( frontSubset ) ; double totalVolume = this . calculateHypervolume ( totalFront , totalFront . length , numberOfObjectives ) ; for ( int i = 0 ; i < front . length ; i ++ ) { double [ ] evaluatedPoint = frontCopy . remove ( i ) ; frontSubset = frontCopy . toArray ( frontSubset ) ; // STEP4. The hypervolume (control is passed to java version of Zitzler code) double hv = this . calculateHypervolume ( frontSubset , frontSubset . length , numberOfObjectives ) ; double contribution = totalVolume - hv ; contributions [ i ] = contribution ; // put point back frontCopy . add ( i , evaluatedPoint ) ; } return contributions ; } | Calculates how much hypervolume each point dominates exclusively . The points have to be transformed beforehand to accommodate the assumptions of Zitzler s hypervolume code . | 275 | 32 |
31,676 | public double invertedGenerationalDistancePlus ( Front front , Front referenceFront ) { double sum = 0.0 ; for ( int i = 0 ; i < referenceFront . getNumberOfPoints ( ) ; i ++ ) { sum += FrontUtils . distanceToClosestPoint ( referenceFront . getPoint ( i ) , front , new DominanceDistance ( ) ) ; } // STEP 4. Divide the sum by the maximum number of points of the reference Pareto front return sum / referenceFront . getNumberOfPoints ( ) ; } | Returns the inverted generational distance plus value for a given front | 113 | 11 |
31,677 | private Map < String , Double > computeStatistics ( List < Double > values ) { Map < String , Double > results = new HashMap <> ( ) ; DescriptiveStatistics stats = new DescriptiveStatistics ( ) ; for ( Double value : values ) { stats . addValue ( value ) ; } results . put ( "mean" , stats . getMean ( ) ) ; results . put ( "median" , stats . getPercentile ( 50.0 ) ) ; results . put ( "stdDeviation" , stats . getStandardDeviation ( ) ) ; results . put ( "iqr" , stats . getPercentile ( 75 ) - stats . getPercentile ( 25 ) ) ; results . put ( "max" , stats . getMax ( ) ) ; results . put ( "min" , stats . getMean ( ) ) ; results . put ( "numberOfElements" , ( double ) values . size ( ) ) ; return results ; } | Computes the statistical values | 208 | 5 |
31,678 | private double delta ( double y , double bMutationParameter ) { double rand = randomGenenerator . getRandomValue ( ) ; int it , maxIt ; it = currentIteration ; maxIt = maxIterations ; return ( y * ( 1.0 - Math . pow ( rand , Math . pow ( ( 1.0 - it / ( double ) maxIt ) , bMutationParameter ) ) ) ) ; } | Calculates the delta value used in NonUniform mutation operator | 90 | 13 |
31,679 | private void scaleToPositive ( ) { // Obtain min value double minScalarization = Double . MAX_VALUE ; for ( S solution : getSolutionList ( ) ) { if ( scalarization . getAttribute ( solution ) < minScalarization ) { minScalarization = scalarization . getAttribute ( solution ) ; } } if ( minScalarization < 0 ) { // Avoid scalarization values of 0 double eps = 10e-6 ; for ( S solution : getSolutionList ( ) ) { scalarization . setAttribute ( solution , eps + scalarization . getAttribute ( solution ) + minScalarization ) ; } } } | The niching mechanism of ESPEA only works if the scalarization values are positive . Otherwise scalarization values cannot be interpreted as charges of a physical system that signal desirability . | 148 | 39 |
31,680 | private double [ ] energyVector ( double [ ] [ ] distanceMatrix ) { // Ignore the set (maxSize + 1)'th archive member since it's the new // solution that is tested for eligibility of replacement. double [ ] energyVector = new double [ distanceMatrix . length - 1 ] ; for ( int i = 0 ; i < energyVector . length - 1 ; i ++ ) { for ( int j = i + 1 ; j < energyVector . length ; j ++ ) { energyVector [ i ] += scalarization . getAttribute ( archive . get ( j ) ) / distanceMatrix [ i ] [ j ] ; energyVector [ j ] += scalarization . getAttribute ( archive . get ( i ) ) / distanceMatrix [ i ] [ j ] ; } energyVector [ i ] *= scalarization . getAttribute ( archive . get ( i ) ) ; } return energyVector ; } | Computes the energy contribution of each archive member . Note that the archive member at position maxSize + 1 is the new solution that is tested for eligibility of replacement . | 190 | 33 |
31,681 | private double [ ] replacementVector ( double [ ] [ ] distanceMatrix ) { double [ ] replacementVector = new double [ distanceMatrix . length - 1 ] ; // Energy between archive member k and new solution double [ ] individualEnergy = new double [ distanceMatrix . length - 1 ] ; // Sum of all individual energies double totalEnergy = 0.0 ; for ( int i = 0 ; i < replacementVector . length ; i ++ ) { individualEnergy [ i ] = scalarization . getAttribute ( archive . get ( i ) ) / distanceMatrix [ i ] [ maxSize ] ; totalEnergy += individualEnergy [ i ] ; } for ( int i = 0 ; i < individualEnergy . length ; i ++ ) { replacementVector [ i ] = totalEnergy - individualEnergy [ i ] ; replacementVector [ i ] *= scalarization . getAttribute ( archive . get ( maxSize ) ) ; } return replacementVector ; } | Computes the replacement energy vector . Each component k of the replacement vector states how much energy the new solution would introduce into the archive instead of the archive member at position k . | 194 | 35 |
31,682 | public static void printFinalSolutionSet ( List < ? extends Solution < ? > > population ) { new SolutionListOutput ( population ) . setSeparator ( "\t" ) . setVarFileOutputContext ( new DefaultFileOutputContext ( "VAR.tsv" ) ) . setFunFileOutputContext ( new DefaultFileOutputContext ( "FUN.tsv" ) ) . print ( ) ; JMetalLogger . logger . info ( "Random seed: " + JMetalRandom . getInstance ( ) . getSeed ( ) ) ; JMetalLogger . logger . info ( "Objectives values have been written to file FUN.tsv" ) ; JMetalLogger . logger . info ( "Variables values have been written to file VAR.tsv" ) ; } | Write the population into two files and prints some data on screen | 168 | 12 |
31,683 | public static < S extends Solution < ? > > void printQualityIndicators ( List < S > population , String paretoFrontFile ) throws FileNotFoundException { Front referenceFront = new ArrayFront ( paretoFrontFile ) ; FrontNormalizer frontNormalizer = new FrontNormalizer ( referenceFront ) ; Front normalizedReferenceFront = frontNormalizer . normalize ( referenceFront ) ; Front normalizedFront = frontNormalizer . normalize ( new ArrayFront ( population ) ) ; List < PointSolution > normalizedPopulation = FrontUtils . convertFrontToSolutionList ( normalizedFront ) ; String outputString = "\n" ; outputString += "Hypervolume (N) : " + new PISAHypervolume < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "Hypervolume : " + new PISAHypervolume < S > ( referenceFront ) . evaluate ( population ) + "\n" ; outputString += "Epsilon (N) : " + new Epsilon < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "Epsilon : " + new Epsilon < S > ( referenceFront ) . evaluate ( population ) + "\n" ; outputString += "GD (N) : " + new GenerationalDistance < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "GD : " + new GenerationalDistance < S > ( referenceFront ) . evaluate ( population ) + "\n" ; outputString += "IGD (N) : " + new InvertedGenerationalDistance < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "IGD : " + new InvertedGenerationalDistance < S > ( referenceFront ) . evaluate ( population ) + "\n" ; outputString += "IGD+ (N) : " + new InvertedGenerationalDistancePlus < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "IGD+ : " + new InvertedGenerationalDistancePlus < S > ( referenceFront ) . evaluate ( population ) + "\n" ; outputString += "Spread (N) : " + new Spread < PointSolution > ( normalizedReferenceFront ) . evaluate ( normalizedPopulation ) + "\n" ; outputString += "Spread : " + new Spread < S > ( referenceFront ) . evaluate ( population ) + "\n" ; // outputString += "R2 (N) : " + // new R2<List<DoubleSolution>>(normalizedReferenceFront).runAlgorithm(normalizedPopulation) + "\n"; // outputString += "R2 : " + // new R2<List<? extends Solution<?>>>(referenceFront).runAlgorithm(population) + "\n"; outputString += "Error ratio : " + new ErrorRatio < List < ? extends Solution < ? > > > ( referenceFront ) . evaluate ( population ) + "\n" ; JMetalLogger . logger . info ( outputString ) ; } | Print all the available quality indicators | 665 | 6 |
31,684 | public void doMutation ( PermutationSolution < T > solution ) { int permutationLength ; permutationLength = solution . getNumberOfVariables ( ) ; if ( ( permutationLength != 0 ) && ( permutationLength != 1 ) ) { if ( mutationRandomGenerator . getRandomValue ( ) < mutationProbability ) { int pos1 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 1 ) ; int pos2 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 1 ) ; while ( pos1 == pos2 ) { if ( pos1 == ( permutationLength - 1 ) ) pos2 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 2 ) ; else pos2 = positionRandomGenerator . getRandomValue ( pos1 , permutationLength - 1 ) ; } T temp = solution . getVariableValue ( pos1 ) ; solution . setVariableValue ( pos1 , solution . getVariableValue ( pos2 ) ) ; solution . setVariableValue ( pos2 , temp ) ; } } } | Performs the operation | 232 | 4 |
31,685 | private void doMutation ( double probability , DoubleSolution solution ) { for ( int i = 0 ; i < solution . getNumberOfVariables ( ) ; i ++ ) { if ( randomGenerator . getRandomValue ( ) <= probability ) { Double value = solution . getLowerBound ( i ) + ( ( solution . getUpperBound ( i ) - solution . getLowerBound ( i ) ) * randomGenerator . getRandomValue ( ) ) ; solution . setVariableValue ( i , value ) ; } } } | Implements the mutation operation | 111 | 6 |
31,686 | @ SuppressWarnings ( "unchecked" ) public static < S > Problem < S > loadProblem ( String problemName ) { Problem < S > problem ; try { problem = ( Problem < S > ) Class . forName ( problemName ) . getConstructor ( ) . newInstance ( ) ; } catch ( InstantiationException e ) { throw new JMetalException ( "newInstance() cannot instantiate (abstract class)" , e ) ; } catch ( IllegalAccessException e ) { throw new JMetalException ( "newInstance() is not usable (uses restriction)" , e ) ; } catch ( InvocationTargetException e ) { throw new JMetalException ( "an exception was thrown during the call of newInstance()" , e ) ; } catch ( NoSuchMethodException e ) { throw new JMetalException ( "getConstructor() was not able to find the constructor without arguments" , e ) ; } catch ( ClassNotFoundException e ) { throw new JMetalException ( "Class.forName() did not recognized the name of the class" , e ) ; } return problem ; } | Create an instance of problem passed as argument | 234 | 8 |
31,687 | public float [ ] t1 ( float [ ] z , int k ) { float [ ] result = new float [ z . length ] ; for ( int i = 0 ; i < z . length ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . sMulti ( z [ i ] , 30 , 10 , ( float ) 0.35 ) ; } return result ; } | WFG4 t1 transformation | 84 | 6 |
31,688 | public double evalG ( BinarySolution solution ) { double res = 0.0 ; for ( int i = 1 ; i < solution . getNumberOfVariables ( ) ; i ++ ) { res += evalV ( u ( solution . getVariableValue ( i ) ) ) ; } return res ; } | Returns the value of the ZDT5 function G . | 63 | 11 |
31,689 | public FieldsFilter withFields ( String fields , boolean includeFields ) { parameters . put ( "fields" , fields ) ; parameters . put ( "include_fields" , includeFields ) ; return this ; } | Only retrieve certain fields from the item . | 46 | 8 |
31,690 | @ JsonFormat ( shape = JsonFormat . Shape . STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) @ JsonProperty ( "created_at" ) public Date getCreatedAt ( ) { return createdAt ; } | Getter for the date this user was created on . | 64 | 11 |
31,691 | @ JsonFormat ( shape = JsonFormat . Shape . STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) @ JsonProperty ( "updated_at" ) public Date getUpdatedAt ( ) { return updatedAt ; } | Getter for the date this user was last updated on . | 64 | 12 |
31,692 | @ JsonFormat ( shape = JsonFormat . Shape . STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) @ JsonProperty ( "last_login" ) public Date getLastLogin ( ) { return lastLogin ; } | Getter for the last login date . | 64 | 8 |
31,693 | @ Deprecated @ JsonProperty ( "from" ) public void setFrom ( String from ) throws IllegalArgumentException { if ( messagingServiceSID != null ) { throw new IllegalArgumentException ( "You must specify either `from` or `messagingServiceSID`, but not both" ) ; } this . from = from ; } | Setter for the Twilio From number . | 73 | 10 |
31,694 | @ Deprecated @ JsonProperty ( "messaging_service_sid" ) public void setMessagingServiceSID ( String messagingServiceSID ) throws IllegalArgumentException { if ( from != null ) { throw new IllegalArgumentException ( "You must specify either `from` or `messagingServiceSID`, but not both" ) ; } this . messagingServiceSID = messagingServiceSID ; } | Setter for the Twilio Messaging Service SID . | 88 | 13 |
31,695 | public QueryFilter withQuery ( String query ) { try { String encodedQuery = urlEncode ( query ) ; parameters . put ( KEY_QUERY , encodedQuery ) ; return this ; } catch ( UnsupportedEncodingException ex ) { //"Every implementation of the Java platform is required to support the following standard charsets [...]: UTF-8" //cf. https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html throw new IllegalStateException ( "UTF-8 encoding not supported by current Java platform implementation." , ex ) ; } } | Filter by a query | 135 | 4 |
31,696 | public String build ( ) { for ( Map . Entry < String , String > p : parameters . entrySet ( ) ) { builder . addQueryParameter ( p . getKey ( ) , p . getValue ( ) ) ; } return builder . build ( ) . toString ( ) ; } | Creates a string representation of the URL with the configured parameters . | 61 | 13 |
31,697 | @ JsonFormat ( shape = JsonFormat . Shape . STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) @ JsonProperty ( "enrolled_at" ) public Date getEnrolledAt ( ) { return enrolledAt ; } | Getter for the enrolled at . | 66 | 7 |
31,698 | @ JsonFormat ( shape = JsonFormat . Shape . STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ) @ JsonProperty ( "last_auth" ) public Date getLastAuth ( ) { return lastAuth ; } | Getter for the last authentication . | 64 | 7 |
31,699 | public AuthorizeUrlBuilder withParameter ( String name , String value ) { assertNotNull ( name , "name" ) ; assertNotNull ( value , "value" ) ; parameters . put ( name , value ) ; return this ; } | Sets an additional parameter . | 50 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.