idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
31,600
public double norm_vector ( double [ ] z ) { double sum = 0 ; for ( int i = 0 ; i < problem . getNumberOfObjectives ( ) ; i ++ ) { sum += z [ i ] * z [ i ] ; } return Math . sqrt ( sum ) ; }
Calculate the norm of the vector
31,601
private double epsilon ( Front front , Front referenceFront ) throws JMetalException { double eps , epsJ = 0.0 , epsK = 0.0 , epsTemp ; int numberOfObjectives = front . getPointDimensions ( ) ; eps = Double . MIN_VALUE ; for ( int i = 0 ; i < referenceFront . getNumberOfPoints ( ) ; i ++ ) { for ( int j = 0 ; j < front . getNumberOfPoints ( ) ; j ++ ) { for ( int k = 0 ; k < numberOfObjectives ; k ++ ) { epsTemp = front . getPoint ( j ) . getValue ( k ) - referenceFront . getPoint ( i ) . getValue ( k ) ; if ( k == 0 ) { epsK = epsTemp ; } else if ( epsK < epsTemp ) { epsK = epsTemp ; } } if ( j == 0 ) { epsJ = epsK ; } else if ( epsJ > epsK ) { epsJ = epsK ; } } if ( i == 0 ) { eps = epsJ ; } else if ( eps < epsJ ) { eps = epsJ ; } } return eps ; }
Returns the value of the epsilon indicator .
31,602
protected double evalH ( double f , double g ) { double h ; h = 1.0 - Math . sqrt ( f / g ) - ( f / g ) * Math . sin ( 10.0 * Math . PI * f ) ; return h ; }
Returns the value of the ZDT3 function H .
31,603
public boolean prefers ( int x , int y , int [ ] womanPref , int size ) { for ( int i = 0 ; i < size ; i ++ ) { int pref = womanPref [ i ] ; if ( pref == x ) { return true ; } if ( pref == y ) { return false ; } } System . out . println ( "Error in womanPref list!" ) ; return false ; }
Returns true in case that a given woman prefers x to y .
31,604
public void referenceSetUpdate ( DoubleSolution solution ) { if ( refSet1Test ( solution ) ) { for ( DoubleSolution solutionInRefSet2 : referenceSet2 ) { double aux = SolutionUtils . distanceBetweenSolutionsInObjectiveSpace ( solution , solutionInRefSet2 ) ; DoubleSolution auxSolution = solutionInRefSet2 ; if ( aux < distanceToSolutionListAttribute . getAttribute ( auxSolution ) ) { distanceToSolutionListAttribute . setAttribute ( auxSolution , aux ) ; } } } else { refSet2Test ( solution ) ; } }
Update the reference set with a new solution
31,605
public void buildNewReferenceSet1 ( ) { DoubleSolution individual ; strengthRawFitness . computeDensityEstimator ( getPopulation ( ) ) ; Collections . sort ( getPopulation ( ) , fitnessComparator ) ; for ( int i = 0 ; i < referenceSet1Size ; i ++ ) { individual = getPopulation ( ) . get ( 0 ) ; getPopulation ( ) . remove ( 0 ) ; marked . setAttribute ( individual , false ) ; referenceSet1 . add ( individual ) ; } }
Build the referenceSet1 by moving the best referenceSet1Size individuals according to a fitness comparator from the population to the referenceSet1
31,606
public void buildNewReferenceSet2 ( ) { for ( int i = 0 ; i < getPopulation ( ) . size ( ) ; i ++ ) { DoubleSolution individual = getPopulation ( ) . get ( i ) ; double distanceAux = SolutionUtils . distanceToSolutionListInSolutionSpace ( individual , referenceSet1 ) ; distanceToSolutionListAttribute . setAttribute ( individual , distanceAux ) ; } int size = referenceSet2Size ; if ( getPopulation ( ) . size ( ) < referenceSet2Size ) { size = getPopulation ( ) . size ( ) ; } for ( int i = 0 ; i < size ; i ++ ) { double maxMinimum = 0.0 ; int index = 0 ; for ( int j = 0 ; j < getPopulation ( ) . size ( ) ; j ++ ) { DoubleSolution auxSolution = getPopulation ( ) . get ( j ) ; if ( distanceToSolutionListAttribute . getAttribute ( auxSolution ) > maxMinimum ) { maxMinimum = distanceToSolutionListAttribute . getAttribute ( auxSolution ) ; index = j ; } } DoubleSolution individual = getPopulation ( ) . get ( index ) ; getPopulation ( ) . remove ( index ) ; for ( int j = 0 ; j < getPopulation ( ) . size ( ) ; j ++ ) { double aux = SolutionUtils . distanceBetweenSolutionsInObjectiveSpace ( getPopulation ( ) . get ( j ) , individual ) ; if ( aux < distanceToSolutionListAttribute . getAttribute ( individual ) ) { DoubleSolution auxSolution = getPopulation ( ) . get ( j ) ; distanceToSolutionListAttribute . setAttribute ( auxSolution , aux ) ; } } marked . setAttribute ( individual , false ) ; referenceSet2 . add ( individual ) ; for ( int j = 0 ; j < referenceSet2 . size ( ) ; j ++ ) { for ( int k = 0 ; k < referenceSet2 . size ( ) ; k ++ ) { if ( i != j ) { double aux = SolutionUtils . distanceBetweenSolutionsInObjectiveSpace ( referenceSet2 . get ( j ) , referenceSet2 . get ( k ) ) ; DoubleSolution auxSolution = referenceSet2 . get ( j ) ; if ( aux < distanceToSolutionListAttribute . getAttribute ( auxSolution ) ) { distanceToSolutionListAttribute . setAttribute ( auxSolution , aux ) ; } } } } } }
Build the referenceSet2 by moving to it the most diverse referenceSet2Size individuals from the population in respect to the referenceSet1 .
31,607
public List < List < DoubleSolution > > subsetGeneration ( ) { List < List < DoubleSolution > > solutionGroupsList ; solutionGroupsList = generatePairsFromSolutionList ( referenceSet1 ) ; solutionGroupsList . addAll ( generatePairsFromSolutionList ( referenceSet2 ) ) ; return solutionGroupsList ; }
Subset generation method
31,608
public List < List < DoubleSolution > > generatePairsFromSolutionList ( List < DoubleSolution > solutionList ) { List < List < DoubleSolution > > subset = new ArrayList < > ( ) ; for ( int i = 0 ; i < solutionList . size ( ) ; i ++ ) { DoubleSolution solution1 = solutionList . get ( i ) ; for ( int j = i + 1 ; j < solutionList . size ( ) ; j ++ ) { DoubleSolution solution2 = solutionList . get ( j ) ; if ( ! marked . getAttribute ( solution1 ) || ! marked . getAttribute ( solution2 ) ) { List < DoubleSolution > pair = new ArrayList < > ( 2 ) ; pair . add ( solution1 ) ; pair . add ( solution2 ) ; subset . add ( pair ) ; marked . setAttribute ( solutionList . get ( i ) , true ) ; marked . setAttribute ( solutionList . get ( j ) , true ) ; } } } return subset ; }
Generate all pair combinations of the referenceSet1
31,609
private void resetIndicatorFiles ( ) { for ( GenericIndicator < S > indicator : experiment . getIndicatorList ( ) ) { for ( ExperimentAlgorithm < ? , Result > algorithm : experiment . getAlgorithmList ( ) ) { for ( ExperimentProblem < ? > problem : experiment . getProblemList ( ) ) { String algorithmDirectory ; algorithmDirectory = experiment . getExperimentBaseDirectory ( ) + "/data/" + algorithm . getAlgorithmTag ( ) ; String problemDirectory = algorithmDirectory + "/" + problem . getTag ( ) ; String qualityIndicatorFile = problemDirectory + "/" + indicator . getName ( ) ; resetFile ( qualityIndicatorFile ) ; } } } }
Deletes the files containing the indicator values if the exist .
31,610
private void resetFile ( String file ) { File f = new File ( file ) ; if ( f . exists ( ) ) { JMetalLogger . logger . info ( "Already existing file " + file ) ; if ( f . isDirectory ( ) ) { JMetalLogger . logger . info ( "Deleting directory " + file ) ; if ( f . delete ( ) ) { JMetalLogger . logger . info ( "Directory successfully deleted." ) ; } else { JMetalLogger . logger . info ( "Error deleting directory." ) ; } } else { JMetalLogger . logger . info ( "Deleting file " + file ) ; if ( f . delete ( ) ) { JMetalLogger . logger . info ( "File successfully deleted." ) ; } else { JMetalLogger . logger . info ( "Error deleting file." ) ; } } } else { JMetalLogger . logger . info ( "File " + file + " does NOT exist." ) ; } }
Deletes a file or directory if it does exist
31,611
public double [ ] [ ] lines_of_polygon ( double [ ] [ ] p ) { double [ ] [ ] c9 = new double [ p . length ] [ 3 ] ; for ( int i = 0 ; i < p . length - 1 ; i ++ ) { c9 [ i ] = line_of_twoP ( p [ i ] , p [ i + 1 ] ) ; } c9 [ p . length - 1 ] = line_of_twoP ( p [ p . length - 1 ] , p [ 0 ] ) ; return c9 ; }
given vertexes evaluate the straight lines of a polygon
31,612
public static double generV ( double lb , double ub ) { double p ; p = JMetalRandom . getInstance ( ) . nextDouble ( ) * ( ub - lb ) + lb ; return p ; }
generate a random variable with boundary lb ub
31,613
public void doMutation ( double probability , DoubleSolution solution ) { for ( int i = 0 ; i < solution . getNumberOfVariables ( ) ; i ++ ) { if ( randomGenenerator . getRandomValue ( ) < probability ) { double rand = randomGenenerator . getRandomValue ( ) ; double tmp = ( rand - 0.5 ) * perturbation ; tmp += solution . getVariableValue ( i ) ; if ( tmp < solution . getLowerBound ( i ) ) { tmp = solution . getLowerBound ( i ) ; } else if ( tmp > solution . getUpperBound ( i ) ) { tmp = solution . getUpperBound ( i ) ; } solution . setVariableValue ( i , tmp ) ; } } }
Perform the operation
31,614
private double evalG ( DoubleSolution solution ) { double g = 0.0 ; for ( int i = 2 ; i < solution . getNumberOfVariables ( ) ; i ++ ) { double t = solution . getVariableValue ( i ) - solution . getVariableValue ( 0 ) * solution . getVariableValue ( 1 ) ; g += - 0.9 * t * t + Math . pow ( Math . abs ( t ) , 0.6 ) ; } g = 2 * Math . sin ( Math . PI * solution . getVariableValue ( 0 ) ) * g ; return g ; }
Returns the value of the MOP6 function G .
31,615
public void add ( List < Double > maxs ) { List < Double > aux = new ArrayList < > ( this . numberOfObjectives ) ; aux . addAll ( maxs ) ; this . history . add ( aux ) ; if ( history . size ( ) > MAX_LENGHT ) history . remove ( 0 ) ; }
Adds a new vector of maxs values to the history . The method ensures that only the newest MAX_LENGTH vectors will be kept in the history
31,616
public List < Double > mean ( ) { List < Double > result = new ArrayList < > ( this . numberOfObjectives ) ; for ( int i = 0 ; i < this . numberOfObjectives ; i ++ ) result . add ( 0.0 ) ; for ( List < Double > historyMember : this . history ) for ( int i = 0 ; i < this . numberOfObjectives ; i ++ ) result . set ( i , result . get ( i ) + historyMember . get ( i ) ) ; for ( int i = 0 ; i < this . numberOfObjectives ; i ++ ) result . set ( i , result . get ( i ) / ( double ) this . history . size ( ) ) ; return result ; }
Returns the mean of the values contained in the history
31,617
private static < S extends Solution < ? > > void setScalarizationValue ( S solution , double scalarizationValue ) { solution . setAttribute ( new ScalarizationValue < S > ( ) . getAttributeIdentifier ( ) , scalarizationValue ) ; }
Sets the scalarization value of a solution . Used for for simplified static access .
31,618
private static double [ ] toArray ( List < Double > list ) { double [ ] values = new double [ list . size ( ) ] ; for ( int i = 0 ; i < values . length ; i ++ ) { values [ i ] = list . get ( i ) ; } return values ; }
Method for turning a list of doubles to an array .
31,619
private static < S extends Solution < ? > > double [ ] getIdealValues ( List < S > solutionsList ) { ArrayFront front = new ArrayFront ( solutionsList ) ; FrontExtremeValues extremeValues = new FrontExtremeValues ( ) ; List < Double > list = extremeValues . findLowestValues ( front ) ; return toArray ( list ) ; }
Computes the ideal point based on a list of solutions
31,620
private static < S extends Solution < ? > > double [ ] getNadirValues ( List < S > solutionsList ) { ArrayFront front = new ArrayFront ( solutionsList ) ; FrontExtremeValues extremeValues = new FrontExtremeValues ( ) ; List < Double > list = extremeValues . findHighestValues ( front ) ; return toArray ( list ) ; }
Computes the nadir point based on a list of solutions
31,621
private static < S extends Solution < ? > > double [ ] [ ] getExtremePoints ( List < S > solutionsList ) { double [ ] [ ] extremePoints = new double [ solutionsList . get ( 0 ) . getNumberOfObjectives ( ) ] [ ] ; for ( int i = 0 ; i < extremePoints . length ; i ++ ) { S extreme = Collections . min ( solutionsList , new AchievementScalarizationComparator < S > ( i ) ) ; extremePoints [ i ] = new double [ extreme . getNumberOfObjectives ( ) ] ; for ( int j = 0 ; j < extremePoints . length ; j ++ ) { extremePoints [ i ] [ j ] = extreme . getObjective ( j ) ; } } return extremePoints ; }
Computes the extreme points on achievement scalarization values
31,622
public static < S extends Solution < ? > > void sumOfObjectives ( List < S > solutionsList ) { for ( S solution : solutionsList ) { double sum = solution . getObjective ( 0 ) ; for ( int i = 1 ; i < solution . getNumberOfObjectives ( ) ; i ++ ) { sum += solution . getObjective ( i ) ; } setScalarizationValue ( solution , sum ) ; } }
Scalarization values is computed by summing objective values .
31,623
public static < S extends Solution < ? > > void weightedSum ( List < S > solutionsList , double [ ] weights ) { for ( S solution : solutionsList ) { double sum = weights [ 0 ] * solution . getObjective ( 0 ) ; for ( int i = 1 ; i < solution . getNumberOfObjectives ( ) ; i ++ ) { sum += weights [ i ] * solution . getObjective ( i ) ; } setScalarizationValue ( solution , sum ) ; } }
Objective values are multiplied by weights and summed . Weights should always be positive .
31,624
public static < S extends Solution < ? > > void productOfObjectives ( List < S > solutionsList ) { for ( S solution : solutionsList ) { double product = solution . getObjective ( 0 ) ; for ( int i = 1 ; i < solution . getNumberOfObjectives ( ) ; i ++ ) { product *= solution . getObjective ( i ) ; } setScalarizationValue ( solution , product ) ; } }
Objective values are multiplied .
31,625
public static < S extends Solution < ? > > void weightedProduct ( List < S > solutionsList , double [ ] weights ) { for ( S solution : solutionsList ) { double product = Math . pow ( solution . getObjective ( 0 ) , weights [ 0 ] ) ; for ( int i = 1 ; i < solution . getNumberOfObjectives ( ) ; i ++ ) { product *= Math . pow ( solution . getObjective ( i ) , weights [ i ] ) ; } setScalarizationValue ( solution , product ) ; } }
Objectives are exponentiated by a positive weight and afterwards multiplied .
31,626
public static < S extends Solution < ? > > void chebyshev ( List < S > solutionsList ) { chebyshev ( solutionsList , getIdealValues ( solutionsList ) ) ; }
Scalarization values based on the Chebyshev function . The ideal point is computed from the list of solutions .
31,627
public static < S extends Solution < ? > > void weightedChebyshev ( List < S > solutionsList , double [ ] weights ) { weightedChebyshev ( solutionsList , getIdealValues ( solutionsList ) , weights ) ; }
Chebyhsev function with weighted objectives .
31,628
public static < S extends Solution < ? > > void chebyshev ( List < S > solutionsList , double [ ] idealValues ) { for ( S solution : solutionsList ) { double max = solution . getObjective ( 0 ) - idealValues [ 0 ] ; for ( int i = 1 ; i < solution . getNumberOfObjectives ( ) ; i ++ ) { max = Math . max ( max , solution . getObjective ( i ) - idealValues [ i ] ) ; } setScalarizationValue ( solution , max ) ; } }
Scalarization values based on the Chebyshev function .
31,629
public static < S extends Solution < ? > > void nash ( List < S > solutionsList ) { nash ( solutionsList , getNadirValues ( solutionsList ) ) ; }
Scalarization values based on the Nash bargaining solution . The disagreement point is computed based on the list of solutions .
31,630
public static < S extends Solution < ? > > void nash ( List < S > solutionsList , double [ ] nadirValues ) { for ( S solution : solutionsList ) { double nash = nadirValues [ 0 ] - solution . getObjective ( 0 ) ; for ( int i = 1 ; i < nadirValues . length ; i ++ ) { nash *= ( nadirValues [ i ] - solution . getObjective ( i ) ) ; } setScalarizationValue ( solution , - nash ) ; } }
Scalarization values based on the Nash bargaining solution .
31,631
public static < S extends Solution < ? > > void uniform ( List < S > solutionsList ) { for ( S solution : solutionsList ) { setScalarizationValue ( solution , 1.0 ) ; } }
Uniform preferences . Each solution is assigned a scalarization value of 1 . 0 .
31,632
public float [ ] t2 ( float [ ] z , int k ) { float [ ] result = new float [ z . length ] ; System . arraycopy ( z , 0 , result , 0 , k ) ; for ( int i = k ; i < z . length ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . bFlat ( z [ i ] , ( float ) 0.8 , ( float ) 0.75 , ( float ) 0.85 ) ; } return result ; }
WFG1 t2 transformation
31,633
public float [ ] t3 ( float [ ] z ) throws JMetalException { float [ ] result = new float [ z . length ] ; for ( int i = 0 ; i < z . length ; i ++ ) { result [ i ] = ( new Transformations ( ) ) . bPoly ( z [ i ] , ( float ) 0.02 ) ; } return result ; }
WFG1 t3 transformation
31,634
public float [ ] t4 ( float [ ] z , int k , int M ) { float [ ] result = new float [ M ] ; float [ ] w = new float [ z . length ] ; for ( int i = 0 ; i < z . length ; i ++ ) { w [ i ] = ( float ) 2.0 * ( i + 1 ) ; } 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 ) ; float [ ] subW = subVector ( w , head - 1 , tail - 1 ) ; result [ i - 1 ] = ( new Transformations ( ) ) . rSum ( subZ , subW ) ; } int head = k + 1 - 1 ; int tail = z . length - 1 ; float [ ] subZ = subVector ( z , head , tail ) ; float [ ] subW = subVector ( w , head , tail ) ; result [ M - 1 ] = ( new Transformations ( ) ) . rSum ( subZ , subW ) ; return result ; }
WFG1 t4 transformation
31,635
public static boolean validate ( double [ ] [ ] weights , int numberOfComponents ) { int i ; boolean correct ; correct = ( weights != null && weights . length > 0 ) ; i = 0 ; while ( correct && i < weights . length ) { correct = ( weights [ i ] . length == numberOfComponents ) ; i ++ ; } return correct ; }
Validate if the number of components of all weight vectors has the expected dimensionality .
31,636
public static double [ ] [ ] initializeUniformlyInTwoDimensions ( double epsilon , int numberOfWeights ) { double [ ] [ ] weights = new double [ numberOfWeights ] [ 2 ] ; int indexOfWeight ; double w , jump ; jump = ( 1 - ( 2 * epsilon ) ) / ( numberOfWeights - 1 ) ; indexOfWeight = 0 ; w = epsilon ; while ( indexOfWeight < numberOfWeights ) { weights [ indexOfWeight ] [ 0 ] = w ; weights [ indexOfWeight ] [ 1 ] = 1 - w ; w = w + jump ; indexOfWeight = indexOfWeight + 1 ; } return weights ; }
Generate uniform weight vectors in two dimension
31,637
public static double [ ] [ ] readFromResourcesInJMetal ( String filePath ) { double [ ] [ ] weights ; Vector < double [ ] > listOfWeights = new Vector < > ( ) ; try { InputStream in = WeightVectors . class . getResourceAsStream ( "/" + filePath ) ; InputStreamReader isr = new InputStreamReader ( in ) ; BufferedReader br = new BufferedReader ( isr ) ; int numberOfObjectives = 0 ; int j ; String aux = br . readLine ( ) ; while ( aux != null ) { StringTokenizer st = new StringTokenizer ( aux ) ; j = 0 ; numberOfObjectives = st . countTokens ( ) ; double [ ] weight = new double [ numberOfObjectives ] ; while ( st . hasMoreTokens ( ) ) { weight [ j ] = new Double ( st . nextToken ( ) ) ; j ++ ; } listOfWeights . add ( weight ) ; aux = br . readLine ( ) ; } br . close ( ) ; weights = new double [ listOfWeights . size ( ) ] [ numberOfObjectives ] ; for ( int indexWeight = 0 ; indexWeight < listOfWeights . size ( ) ; indexWeight ++ ) { System . arraycopy ( listOfWeights . get ( indexWeight ) , 0 , weights [ indexWeight ] , 0 , numberOfObjectives ) ; } } catch ( Exception e ) { throw new JMetalException ( "readFromResourcesInJMetal: failed when reading for file: " + filePath + "" , e ) ; } return weights ; }
Read a set of weight vector from a file in the resources folder in jMetal
31,638
public static double [ ] [ ] readFromFile ( String filePath ) { double [ ] [ ] weights ; Vector < double [ ] > listOfWeights = new Vector < > ( ) ; try { FileInputStream fis = new FileInputStream ( filePath ) ; InputStreamReader isr = new InputStreamReader ( fis ) ; BufferedReader br = new BufferedReader ( isr ) ; int numberOfObjectives = 0 ; int j ; String aux = br . readLine ( ) ; while ( aux != null ) { StringTokenizer st = new StringTokenizer ( aux ) ; j = 0 ; numberOfObjectives = st . countTokens ( ) ; double [ ] weight = new double [ numberOfObjectives ] ; while ( st . hasMoreTokens ( ) ) { weight [ j ] = new Double ( st . nextToken ( ) ) ; j ++ ; } listOfWeights . add ( weight ) ; aux = br . readLine ( ) ; } br . close ( ) ; weights = new double [ listOfWeights . size ( ) ] [ numberOfObjectives ] ; for ( int indexWeight = 0 ; indexWeight < listOfWeights . size ( ) ; indexWeight ++ ) { System . arraycopy ( listOfWeights . get ( indexWeight ) , 0 , weights [ indexWeight ] , 0 , numberOfObjectives ) ; } } catch ( Exception e ) { throw new JMetalException ( "readFromFile: failed when reading for file: " + filePath + "" , e ) ; } return weights ; }
Read a set of weight vector from a file
31,639
public static double [ ] [ ] invert ( double [ ] [ ] weights , boolean normalize ) { double [ ] [ ] result = new double [ weights . length ] [ weights [ 0 ] . length ] ; for ( int indexOfWeight = 0 ; indexOfWeight < weights . length ; indexOfWeight ++ ) { if ( normalize ) { double sum = 0 ; for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) { sum = sum + ( 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ) ; } for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) { result [ indexOfWeight ] [ indexOfComponent ] = ( 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ) / sum ; } } else { for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) result [ indexOfWeight ] [ indexOfComponent ] = 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ; } } return result ; }
Calculate the inverse of a set of weight vectors
31,640
protected double evalG ( DoubleSolution solution ) { double g = 0.0 ; for ( int i = 1 ; i < solution . getNumberOfVariables ( ) ; i ++ ) { g += solution . getVariableValue ( i ) ; } double constant = 9.0 / ( solution . getNumberOfVariables ( ) - 1 ) ; return constant * g + 1.0 ; }
Returns the value of the ZDT1 function G .
31,641
protected double evalH ( double f , double g ) { double h ; h = 1.0 - Math . sqrt ( f / g ) ; return h ; }
Returns the value of the ZDT1 function H .
31,642
public double generationalDistance ( Front front , Front referenceFront ) { double sum = 0.0 ; for ( int i = 0 ; i < front . getNumberOfPoints ( ) ; i ++ ) { sum += Math . pow ( FrontUtils . distanceToClosestPoint ( front . getPoint ( i ) , referenceFront ) , pow ) ; } sum = Math . pow ( sum , 1.0 / pow ) ; return sum / front . getNumberOfPoints ( ) ; }
Returns the generational distance value for a given front
31,643
public float linear ( float [ ] x , int m ) { float result = ( float ) 1.0 ; int M = x . length ; for ( int i = 1 ; i <= M - m ; i ++ ) { result *= x [ i - 1 ] ; } if ( m != 1 ) { result *= ( 1 - x [ M - m ] ) ; } return result ; }
Calculate a linear shape
31,644
public float convex ( float [ ] x , int m ) { float result = ( float ) 1.0 ; int M = x . length ; for ( int i = 1 ; i <= M - m ; i ++ ) { result *= ( 1 - Math . cos ( x [ i - 1 ] * Math . PI * 0.5 ) ) ; } if ( m != 1 ) { result *= ( 1 - Math . sin ( x [ M - m ] * Math . PI * 0.5 ) ) ; } return result ; }
Calculate a convex shape
31,645
public float mixed ( float [ ] x , int A , float alpha ) { float tmp ; tmp = ( float ) Math . cos ( ( float ) 2.0 * A * ( float ) Math . PI * x [ 0 ] + ( float ) Math . PI * ( float ) 0.5 ) ; tmp /= ( 2.0 * ( float ) A * Math . PI ) ; return ( float ) Math . pow ( ( ( float ) 1.0 - x [ 0 ] - tmp ) , alpha ) ; }
Calculate a mixed shape
31,646
public float disc ( float [ ] x , int A , float alpha , float beta ) { float tmp ; tmp = ( float ) Math . cos ( ( float ) A * Math . pow ( x [ 0 ] , beta ) * Math . PI ) ; return ( float ) 1.0 - ( float ) Math . pow ( x [ 0 ] , alpha ) * ( float ) Math . pow ( tmp , 2.0 ) ; }
Calculate a disc shape
31,647
static public double sphere_noise ( double [ ] x ) { double sum = 0.0 ; for ( int i = 0 ; i < x . length ; i ++ ) { sum += x [ i ] * x [ i ] ; } sum *= ( 1.0 + 0.1 * Math . abs ( random . nextGaussian ( ) ) ) ; return ( sum ) ; }
Sphere function with noise
31,648
static public double schwefel_102 ( double [ ] x ) { double prev_sum , curr_sum , outer_sum ; curr_sum = x [ 0 ] ; outer_sum = ( curr_sum * curr_sum ) ; for ( int i = 1 ; i < x . length ; i ++ ) { prev_sum = curr_sum ; curr_sum = prev_sum + x [ i ] ; outer_sum += ( curr_sum * curr_sum ) ; } return ( outer_sum ) ; }
Schwefel s problem 1 . 2
31,649
static public double rosenbrock ( double [ ] x ) { double sum = 0.0 ; for ( int i = 0 ; i < ( x . length - 1 ) ; i ++ ) { double temp1 = ( x [ i ] * x [ i ] ) - x [ i + 1 ] ; double temp2 = x [ i ] - 1.0 ; sum += ( 100.0 * temp1 * temp1 ) + ( temp2 * temp2 ) ; } return ( sum ) ; }
Rosenbrock s function
31,650
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
31,651
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
31,652
static public double myRound ( double x ) { return ( Math . signum ( x ) * Math . round ( Math . abs ( x ) ) ) ; }
0 . Use the Matlab version for rounding numbers
31,653
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
31,654
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
31,655
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
31,656
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
31,657
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
31,658
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
31,659
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
31,660
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 .
31,661
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" ) ; } 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 .
31,662
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
31,663
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 ; } for ( int i = 0 ; i < d ; i ++ ) { x [ i ] = randNormal ( 0 , 1 ) ; length += length + x [ i ] * x [ i ] ; } length = Math . sqrt ( length ) ; 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
31,664
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
31,665
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
31,666
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
31,667
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
31,668
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 .
31,669
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 .
31,670
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
31,671
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 .
31,672
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 ) { int totalNumberOfBits = parent1 . getTotalNumberOfBits ( ) ; int crossoverPoint = pointRandomGenerator . getRandomValue ( 0 , totalNumberOfBits - 1 ) ; int variable = 0 ; int bitsAccount = parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) ; while ( bitsAccount < ( crossoverPoint + 1 ) ) { variable ++ ; bitsAccount += parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) ; } int diff = bitsAccount - crossoverPoint ; int intoVariableCrossoverPoint = parent1 . getVariableValue ( variable ) . getBinarySetLength ( ) - diff ; 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 ) ; 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 .
31,673
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
31,674
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
31,675
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
31,676
double psfunc3 ( double x , double t1 , double t2 , int dim , int type ) { 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
31,677
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 .
31,678
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 ; } else if ( flag == 0 ) { int equalflag = equalSolutions . compare ( solution , listIndividual ) ; if ( equalflag == 0 ) isContained = true ; } } if ( ! isDominated && ! isContained ) { solutionList . add ( solution ) ; solutionInserted = true ; } return solutionInserted ; } return solutionInserted ; }
Inserts a solution in the list
31,679
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
31,680
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
31,681
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
31,682
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 .
31,683
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
31,684
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
31,685
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
31,686
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 .
31,687
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
31,688
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
31,689
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
31,690
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
31,691
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
31,692
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
31,693
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 .
31,694
public static < S extends Solution < ? > > double distanceBetweenObjectives ( S firstSolution , S secondSolution ) { double diff ; double distance = 0.0 ; 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
31,695
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 .
31,696
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 .
31,697
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
31,698
public static void tred2 ( int n , double v [ ] [ ] , double d [ ] , double e [ ] ) { System . arraycopy ( v [ n - 1 ] , 0 , d , 0 , n ) ; for ( int i = n - 1 ; i > 0 ; i -- ) { 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 ; } accumulateTransformations ( n , v , d ) ; e [ 0 ] = 0.0 ; }
Symmetric Householder reduction to tridiagonal form taken from JAMA package .
31,699
public static void tql2 ( int n , double d [ ] , double e [ ] , double v [ ] [ ] ) { 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 ++ ) { 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 ) { int iter = 0 ; do { iter = iter + 1 ; f += specificShift ( l , n , d , e ) ; implicitQLTransformation ( l , m , n , v , d , e ) ; } while ( Math . abs ( e [ l ] ) > eps * tst1 ) ; } d [ l ] = d [ l ] + f ; e [ l ] = 0.0 ; } sortEigenValues ( n , d , v ) ; }
Symmetric tridiagonal QL algorithm taken from JAMA package .