genopt.io
Class SimOutputFileHandler

java.lang.Object
  extended by genopt.io.SimOutputFileHandler

public class SimOutputFileHandler
extends java.lang.Object

Object that extends FileHandler and offers additional methods to get the value of the objective function out of the file.

This project was carried out at:

and supported by

GenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.

Version:
GenOpt(R) 3.1.0 (December 8, 2011)

Author:
Michael Wetter

Field Summary
protected  java.lang.String delimiter
          objective function delimiter
protected  int delLen
          length of function delimiter
(package private)  java.lang.String filNam
          The file name
(package private)  int firstCharAt
          One-based index for the position where the first character of the delimiter starts, or 0 if unspecified
private static java.lang.String LS
          System dependent line separator
private static java.lang.String separator
          separator after the objective function value (will be initialized below)
 
Constructor Summary
SimOutputFileHandler(java.lang.String fileName, java.lang.String Separator)
          Constructor.
 
Method Summary
protected static java.lang.String cutBeginSpaceAndTab(java.lang.String s)
          cuts all space and tab characters at the beginning of the String
protected static java.lang.String cutEndSpaceAndTab(java.lang.String s)
          cuts all space and tab characters at the end of the String
private  double getDoubleAfterLastSpace(java.lang.String s)
          gets the double that occurs after the last blank character
private  double getFirstDouble(java.lang.String s)
          gets the first double that occurs in the String (which is separated from the next entries by either a space character, a tab, a comma, or a semicolon, or a double dot)
protected static int getIndexOfSeparator(java.lang.String s)
          gets the first index of the space character, tab character, semi-colon, colon, or comma
 double getObjectiveFunctionValue(java.lang.String ObjectiveFunctiondelimiter, int firstCharacterAt)
          gets the last number of the file content
private  double getObjectiveFunctionValueEmpty()
          gets the last number of the file content.
private  double getObjectiveFunctionValueNonEmpty()
          gets the last number of the file content.
static void main(java.lang.String[] args)
          The main method.
private  double parseToDouble(java.lang.String s)
          parses a String to a double value
protected  void throwObjectiveFunctionValueNotFound()
          Throws an OptimizerException with the error message that the objective function value could not be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS

private static final java.lang.String LS
System dependent line separator


separator

private static java.lang.String separator
separator after the objective function value (will be initialized below)


delimiter

protected java.lang.String delimiter
objective function delimiter


delLen

protected int delLen
length of function delimiter


filNam

java.lang.String filNam
The file name


firstCharAt

int firstCharAt
One-based index for the position where the first character of the delimiter starts, or 0 if unspecified

Constructor Detail

SimOutputFileHandler

public SimOutputFileHandler(java.lang.String fileName,
                            java.lang.String Separator)
                     throws java.io.IOException,
                            java.io.FileNotFoundException,
                            java.lang.SecurityException
Constructor.

Parameters:
fileName - the file name
Separator - separator after the objective function value
Throws:
java.io.IOException
java.io.FileNotFoundException
java.lang.SecurityException
Method Detail

getObjectiveFunctionValue

public double getObjectiveFunctionValue(java.lang.String ObjectiveFunctiondelimiter,
                                        int firstCharacterAt)
                                 throws OptimizerException
gets the last number of the file content

Parameters:
ObjectiveFunctiondelimiter - String that indicates delimiter (additional to the blank space) of the objective function value
firstCharacterAt - one-based index for the position where the first character of the delimiter starts, or 0 if unspecified
Returns:
value of the objective function
Throws:
OptimizerException - if objective function value has not been found
java.io.IOException - if an IOException occurred while reading the file

cutBeginSpaceAndTab

protected static final java.lang.String cutBeginSpaceAndTab(java.lang.String s)
cuts all space and tab characters at the beginning of the String

Parameters:
s - the String to be cutted
Returns:
the String with all space and tab characters at the beginning cutted away

cutEndSpaceAndTab

protected static final java.lang.String cutEndSpaceAndTab(java.lang.String s)
cuts all space and tab characters at the end of the String

Parameters:
s - the String to be cutted
Returns:
the String with all space and tab characters at the end cutted away

getIndexOfSeparator

protected static int getIndexOfSeparator(java.lang.String s)
gets the first index of the space character, tab character, semi-colon, colon, or comma

Parameters:
s - the String to be tested
Returns:
the first index of the space or tab character, or -1 if non of them is found

getDoubleAfterLastSpace

private double getDoubleAfterLastSpace(java.lang.String s)
                                throws OptimizerException
gets the double that occurs after the last blank character

Parameters:
s - the String containing the double
Returns:
the double
Throws:
OptimizerException

getFirstDouble

private double getFirstDouble(java.lang.String s)
                       throws OptimizerException
gets the first double that occurs in the String (which is separated from the next entries by either a space character, a tab, a comma, or a semicolon, or a double dot)

Parameters:
s - the String containing the double
Returns:
the double
Throws:
OptimizerException

getObjectiveFunctionValueEmpty

private double getObjectiveFunctionValueEmpty()
                                       throws OptimizerException,
                                              java.io.IOException
gets the last number of the file content.
This method is used if the delimiter is either a white space or an empty character

Returns:
value of the objective function
Throws:
OptimizerException
java.io.IOException

getObjectiveFunctionValueNonEmpty

private double getObjectiveFunctionValueNonEmpty()
                                          throws OptimizerException,
                                                 java.io.IOException
gets the last number of the file content.
This method is used if the delimiter is neither a white space nor an empty character

Returns:
value of the objective function
Throws:
OptimizerException
java.io.IOException

throwObjectiveFunctionValueNotFound

protected void throwObjectiveFunctionValueNotFound()
                                            throws OptimizerException
Throws an OptimizerException with the error message that the objective function value could not be found.

Throws:
OptimizerException

parseToDouble

private double parseToDouble(java.lang.String s)
                      throws OptimizerException
parses a String to a double value

Parameters:
s - the String to be parsed
Returns:
value of the objective function
Throws:
OptimizerException - if the String is not a number or if it is infinite

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        OptimizerException
The main method. This method is used for testing only

Throws:
java.io.IOException
OptimizerException