public static double [ ] [ ] readFromFile ( String filePath ) { double [ ] [ ] weights ; Vector < double [ ] > listOfWeights = new Vector <> ( ) ; try { // Open the file 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