genopt.algorithm
Class Optimizer

java.lang.Object
  extended by genopt.algorithm.Optimizer
Direct Known Subclasses:
DiscreteArmijoGradient, Mesh, ModelFiniteIntervalSearcher, ModelGPS, ModelPSO, NelderMeadONeill, Parametric

public abstract class Optimizer
extends java.lang.Object

Abstract Class that represents the structure of an optimization algorithm class and offers generic methods to run the optimization.
All optimization algorithms must extend this class. Note that many data fields are static. This is needed for the hybrid algorithms.

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
private static java.io.StreamTokenizer algorithm
          The section Algorithm of the command file
private  int conMode
          flag for indicating how constraints are treated
private static GenOpt data
          The reference to the GenOpt kernel
private static int dimCon
          The number of independent, continuous variables
private static int dimDis
          The number of independent, discrete variables
private static int dimF
          The number of cost function values
private static int dimInpFun
          The number of input functions
private static int dimX
          The number of independent variables (sum of continuous and discrete)
static java.util.concurrent.CountDownLatch done
          Count down latch for parallel function evaluations
private static java.util.Map<Point,java.lang.Double[]> evaPoi
          The list with evaluated points and its function values.
static int EXCLUDING
          constant to indicate strict inequality
private  boolean firstSimulations
          Flag that indicates whether the set of points that are currently evaluated are the first simulations.
protected static java.lang.String FS
          System dependent file separator
private static java.util.concurrent.atomic.AtomicBoolean functionValuesParsed
          Flag that indicates whether function values have been parsed at least once
private  java.util.concurrent.CountDownLatch funValParLat
          Count down latch, if 0, the function value pointer funValPoi has been set
private static int[] funValPoi
          pointer that assign to each objective function value the number of the output file in which it is stored
static int INCLUDING
          constant to indicate weak inequality
protected static java.lang.String LS
          System dependent line separator
static boolean MAINITERATION
          constant to indicate that it is a main iteration
private static int maxThrPoo
          The maximum number of threads in the pool
private static java.lang.String[] nameF
          The name of the function values
private static int nSimInpFil
          The number of the simulation input files
private static int nSimLogFil
          The number of the simulation log files
private static int nSimOutFil
          The number of the simulation output files
private static ObjectiveFunctionLocation[] objFunObj
          The objective function objects
private static java.lang.String optComFilNam
          The name of the optimization command file
static int ORIGINAL
          constant for indicating that the optimization is in the original space
private static java.lang.String separator
          Separator that separate the objective function value from the values behind it.
private static FileHandler[] simInpTemFilHan
          The simulation input template file handler
private static int stepNumber
          The step number (for implementing variation of the weighting factors for penalty function and barrier function
static boolean SUBITERATION
          constant to indicate that it is a sub iteration
static int TRANSFORMED
          constant for indicating that the optimization is in the transformed space
private static boolean useSteNum
          A flag to indicate whether the step number is used by the optimization algorithm.
private static boolean wriSteNum
          A flag to indicate whether the step number has to be written in the simulation input file (and hence a simulation done)
 
Constructor Summary
  Optimizer()
          Constructor
protected Optimizer(GenOpt genOptData, int constraintMode)
          Constructor
 
Method Summary
private  void _copyRunFiles(java.lang.String[] savePath, java.lang.String[] path, java.lang.String[] name, int simNum)
          Copies the files from path to savePath and adds the run number in front of the file name.
private  void _deleteRunFiles(java.lang.String[] path, java.lang.String[] name)
          Deletes the run files specified by path and name.
private  Point _evaluateSimulation(Point x)
          Evaluates the simulation writes a new input file launches the simulation checks for simulation errors returns an array with the values of the objective function
private static double[] _processResultFunction(java.lang.String[] formula, double[] objFunVal)
          Process the function objects for post processing of the objective function.
private static boolean _replaceInInputFile(java.lang.String text, java.lang.String value, FileHandler[] simulationInput)
          Replaces text with value in simulationInput.
private  Point _retryEvaluateSimulation(Point x, java.lang.Throwable t)
          Tries to evaluate the simulation a second time if an exception has been thrown
private static double _setToFeasibleCoordinate(double x, double l, double u)
          Computes x := 2 * l - x if x < l, or x := 2 * u - x if x < u.
private static int _setToFeasibleCoordinate(int x, int l, int u)
          Computes x := 2 * l - x if x < l, or x := 2 * u - x if x < u.
private static void _variableNotFound(java.lang.String variableName)
          Throws a SimulationInputException that says that the variable could not be found.
protected  void algorithmRequiresUsageOfStepNumber()
          A call to this method sets useSteNum = true.
 void appendToOutputListing(java.lang.String s)
          appends a String to the output listing files
protected  boolean checkMaxIteration()
          Checks if the maximum number of iteration is exceeded
 void checkObjectiveFunctionValue(Point x)
          Checks whether the last objective function value has already been obtained previously.
protected  void ensureOnlyContinuousParameters()
          Checks whether all independent parameters are continuous.
protected  void ensureOnlyDiscreteParameters()
          Checks whether all independent parameters are discrete.
protected  double getAbsAccuracyFunction()
          Gets the absolute accuracy of the last two main iterations
 int getDimensionContinuous()
          Gets the number of independent, continuous variables
 int getDimensionDiscrete()
          Gets the number of independent, continuous variables
 int getDimensionF()
          Gets the number of function values
 int getDimensionX()
          Gets the number of independent variables (sum of continuous and discrete)
 double getDiscreteValueDouble0(int variableNumber)
          Gets the double representation of the variableNumber-th discrete parameter as specified in the command file
If the variable represents discrete numerical values, then the double value of the currently selected value is returned.
 double getDx(int i, double x)
          Gets the step size dx[i] of the i-th continuous variable
Note: dx[i] might be in the transformed space depending on the value of conMode.
 double getDx0(int i)
          Gets the step size dx[i] of the i-th continuous variable as specified in the command file.
 Point getF(Point x)
          Evaluates the simulation for the point x
The value conMode determines in which mode the constraints are treated.
 Point[] getF(Point[] x, boolean stopAtError)
          Evaluates the simulation for the point x
The value conMode determines in which mode the constraints are treated.
 int[] getIndex0()
          Gets the indices of the discrete variable x
 int getIndex0(int i)
          Gets the value (i.e., the index) of x[i]
protected  boolean getInputValueBoolean(java.lang.String keyWord)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  double getInputValueDouble(java.lang.String keyWord)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  double getInputValueDouble(java.lang.String keyWord, double min, double minEqu, double max, double maxEqu)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  int getInputValueInteger(java.lang.String keyWord)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  int getInputValueInteger(java.lang.String keyWord, int min, int minEqu, int max, int maxEqu)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  java.lang.String getInputValueString(java.lang.String keyWord)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
protected  java.lang.String getInputValueString(java.lang.String keyWord, java.lang.String[] admVal)
          Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown
 int getKindOfConstraint(int i)
          Gets the kind of constraint that is imposed on the i-th continuous variable
 double getL(int i)
          Gets the lower bound l[i] of the continuous variable x[i]
 int getLengthDiscrete(int i)
          Gets the number of elements of the i-th discrete variable
protected  int getMainIterationNumber()
          Gets the main iteration number
static int getMaximumThreadPoolSize()
          Returns the maximum size of the thread pool
protected  int getMaxIterationNumber()
          Gets the maximum number of allowed main iterations
 Point getMinimumPoint()
          Gets the minimum point.
 int getMode()
          Gets the mode of the optimization
 java.lang.String getObjectiveFunctionName(int i)
          Gets the name of the i-th objective function value.
protected  java.lang.String getOutputPath()
          Gets the output path.
static int[] getPointerToEqualPoints(Point[] x)
          Gets an integer array that shows what points are equals.
protected  double getRelAccuracyFunction()
          Gets the relative accuracy of the last two main iterations
protected static int getSimulationNumber()
          Gets the number of simulation.
protected  int getStepNumber()
          Gets the current step number
 double getU(int i)
          Gets the upper bound u[i] of the continuous variable x[i]
 java.lang.String getVariableNameContinuous(int i)
          Gets the name of the continuous variable x[i]
 java.lang.String getVariableNameDiscrete(int i)
          Gets the name of the discrete variable x[i]
 double[] getX0()
          Gets the values of the continuous variable x
Note: x might be in the transformed space depending on the value of conMode
 double getX0(int i)
          Gets the value of x[i]
Note: x[i] might be in the transformed space depending on the value of conMode
 void goToEndOfCommandFile()
          Checks whether the current section is closed and then moves to the end of the file.
protected  void increaseStepNumber()
          Increases the step number without a function evaluation.
protected  Point increaseStepNumber(Point x)
          Increases the step number.
protected  boolean isFeasible(Point x)
          Checks whether a point is feasible.
 boolean isNextToken(java.lang.String keyWord)
          Checks whether the next Token is equal to the passed String.
protected  boolean maxIterationReached()
          Checks if the maximum number of iteration is reached.
 boolean mustStopOptimization()
          Returns a flag that indicates whether GenOpt must be stopped after the current simulation (due to a user request).
 void print(java.lang.String text)
          Prints a message to the output device without finishing the line
Note: Use this method instead of System.out.printl(String), otherwise it won't be reported in the GUI
 void println(java.lang.String text)
          Prints a message to the output device, and then finishs the line
Note: Use this method instead of System.out.println(String), otherwise it won't be reported in the GUI
protected static boolean replace(java.lang.String[] strArr, java.lang.String text, java.lang.String value)
          Replaces text with value in input functions.
 void report(Point x, boolean MainIteration)
          Reports an iterate to the output files and to the internal data structure reports the new trial reports the objective function value increases the number of the iteration Note: If a sub iteration is also a main iteration, then you have to call this function twice, first with MainIteration = false and then with MainIteration = true
protected  void reportCurrentLowestPoint()
          Reports the current lowest point for the case that GenOpt has to terminate.
protected  void reportMinimum()
          Reports the minimum point.
protected static void resetStepNumber(int sN)
          Sets the step number.
protected static Point roundCoordinates(Point x)
          Rounds the coordinates of the continuous parameters to float format.
 int run()
          Method for running the optimization algorithm until a termination criteria is satisfied.
abstract  int run(Point x0)
          Abstract method for running the optimization algorithm until a termination criteria is satisfied
protected  void setInfo(java.lang.String s, int simNum)
          Sets a message in the InformationManager The message will be displayed in the output stream (GUI in WinGenOpt, command shell otherwise) and in the log file
private  boolean[] setKnownFunctionValues(Point[] x)
          Sets the function values in these points that are already known.
 void setMode(int constraintMode)
          Sets the mode of the optimization
protected  void setNumberOfMatchingResults(int maxNumberOfMatchingResults)
          Sets the maximal allowed number of matching results
static double setToFeasibleCoordinate(double x, double l, double u)
          Restricts the value of x such that l <= x <= u.
static int setToFeasibleCoordinate(int x, int l, int u)
          Restricts the value of x such that l <= x <= u.
protected  void setWarning(java.lang.String s, int simNum)
          Sets a message in the WarningManager.
 void simulate(Point x)
          Evaluates the simulation based on the parameter set x
protected  void throwInputError(java.lang.String expectedValue)
          Throws an input error.
 boolean useStepNumber()
          Returns the flag that indicates whether the step number is used by the optimization algorithm.
 boolean writeStepNumber()
          Returns the flag that indicates whether the step number has to written to the simulation input file or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS

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


FS

protected static final java.lang.String FS
System dependent file separator


MAINITERATION

public static final boolean MAINITERATION
constant to indicate that it is a main iteration

See Also:
Constant Field Values

SUBITERATION

public static final boolean SUBITERATION
constant to indicate that it is a sub iteration

See Also:
Constant Field Values

ORIGINAL

public static final int ORIGINAL
constant for indicating that the optimization is in the original space

See Also:
Constant Field Values

TRANSFORMED

public static final int TRANSFORMED
constant for indicating that the optimization is in the transformed space

See Also:
Constant Field Values

EXCLUDING

public static final int EXCLUDING
constant to indicate strict inequality

See Also:
Constant Field Values

INCLUDING

public static final int INCLUDING
constant to indicate weak inequality

See Also:
Constant Field Values

conMode

private int conMode
flag for indicating how constraints are treated


dimCon

private static int dimCon
The number of independent, continuous variables


dimDis

private static int dimDis
The number of independent, discrete variables


dimX

private static int dimX
The number of independent variables (sum of continuous and discrete)


dimInpFun

private static int dimInpFun
The number of input functions


dimF

private static int dimF
The number of cost function values


nameF

private static java.lang.String[] nameF
The name of the function values


done

public static java.util.concurrent.CountDownLatch done
Count down latch for parallel function evaluations


data

private static GenOpt data
The reference to the GenOpt kernel


algorithm

private static java.io.StreamTokenizer algorithm
The section Algorithm of the command file


optComFilNam

private static java.lang.String optComFilNam
The name of the optimization command file


separator

private static java.lang.String separator
Separator that separate the objective function value from the values behind it. Separators additional to whitespace characters are specified in the properties.txt file


stepNumber

private static int stepNumber
The step number (for implementing variation of the weighting factors for penalty function and barrier function


wriSteNum

private static boolean wriSteNum
A flag to indicate whether the step number has to be written in the simulation input file (and hence a simulation done)


useSteNum

private static boolean useSteNum
A flag to indicate whether the step number is used by the optimization algorithm. It is used if either wriSteNum = true or if the algorithm requires explicitly the step number to be used. This is typically the case for algorithm that construct at some point a surrogate function and then only seek to optimize the surrogate.


simInpTemFilHan

private static FileHandler[] simInpTemFilHan
The simulation input template file handler


objFunObj

private static ObjectiveFunctionLocation[] objFunObj
The objective function objects


nSimInpFil

private static int nSimInpFil
The number of the simulation input files


nSimLogFil

private static int nSimLogFil
The number of the simulation log files


nSimOutFil

private static int nSimOutFil
The number of the simulation output files


funValPoi

private static int[] funValPoi
pointer that assign to each objective function value the number of the output file in which it is stored


evaPoi

private static java.util.Map<Point,java.lang.Double[]> evaPoi
The list with evaluated points and its function values. Prior to evaluating the cost function, this list is checked whether it contains the same point, where equality is defined by the implementation of genopt.algorithm.util.math.Point.compareTo(java.lang.Object o)


maxThrPoo

private static int maxThrPoo
The maximum number of threads in the pool


functionValuesParsed

private static java.util.concurrent.atomic.AtomicBoolean functionValuesParsed
Flag that indicates whether function values have been parsed at least once


funValParLat

private java.util.concurrent.CountDownLatch funValParLat
Count down latch, if 0, the function value pointer funValPoi has been set


firstSimulations

private boolean firstSimulations
Flag that indicates whether the set of points that are currently evaluated are the first simulations. If the flag is true, then no second simulation is done in case of an error.

Constructor Detail

Optimizer

protected Optimizer(GenOpt genOptData,
                    int constraintMode)
             throws InputFormatException,
                    OptimizerException,
                    java.io.IOException,
                    java.lang.Exception
Constructor

Parameters:
genOptData - a reference to the GenOpt object.
Note: The object is used as a reference. Hence, the data of GenOpt are modified by this Class.
constraintMode - a flag indicating how constraints are treated
 0: optimization is in original space (constraints are not taken into account)
 1: optimization is in transformed space
Throws:
InputFormatException - if an error occurs while searching for Main in the Algorithm section
java.io.IOException - if an I/O exception occurs
java.lang.Exception - in an exception occurs
OptimizerException

Optimizer

public Optimizer()
Constructor

Method Detail

resetStepNumber

protected static void resetStepNumber(int sN)
Sets the step number. This method is used by multi-start algorithms. This method must not be used to decrease the step number

Parameters:
sN -

getOutputPath

protected java.lang.String getOutputPath()
Gets the output path.

Algorithms that write their own output files should write them to the directory returned by this function.

Returns:
the output path

ensureOnlyContinuousParameters

protected void ensureOnlyContinuousParameters()
                                       throws OptimizerException
Checks whether all independent parameters are continuous. If any independent parameter is not continuous, then an OptimizerException is thrown (with an descriptive information)

Throws:
OptimizerException - if some independent parameters are not continuous

ensureOnlyDiscreteParameters

protected void ensureOnlyDiscreteParameters()
                                     throws OptimizerException
Checks whether all independent parameters are discrete. If any independent parameter is not discrete, then an OptimizerException is thrown (with an descriptive information)

Throws:
OptimizerException - if some independent parameters are not discrete

_deleteRunFiles

private void _deleteRunFiles(java.lang.String[] path,
                             java.lang.String[] name)
                      throws java.lang.Exception
Deletes the run files specified by path and name. Deletes the directory if it is empty

Parameters:
path - path of the files
name - name of the files
Throws:
java.lang.Exception - if a SecurityException occured

_copyRunFiles

private void _copyRunFiles(java.lang.String[] savePath,
                           java.lang.String[] path,
                           java.lang.String[] name,
                           int simNum)
                    throws java.lang.SecurityException,
                           java.lang.Exception
Copies the files from path to savePath and adds the run number in front of the file name.

Parameters:
savePath - path where the files have to be copied to. If it does not exist, it will be created.
path - source path of the files
name - name of the files
simNum - The number of the simulation
Throws:
java.lang.SecurityException - if a SecurityException occured
java.lang.Exception - if the directory could not be made

algorithmRequiresUsageOfStepNumber

protected final void algorithmRequiresUsageOfStepNumber()
A call to this method sets useSteNum = true. This method is typically called by multiple layer algorithm that optimize different functions during the whole optimization. An example for such an algorithm is one that -- after some iterations -- constructs a surrogate function and then only attempts to optimize the surrogate, neglecting all previous results.


increaseStepNumber

protected final void increaseStepNumber()
Increases the step number without a function evaluation.
If WriteStepNumber is set to false, then the step number is not increased

See Also:
increaseStepNumber(Point)

increaseStepNumber

protected final Point increaseStepNumber(Point x)
                                  throws SimulationInputException,
                                         OptimizerException,
                                         java.lang.Exception
Increases the step number.
If the variable WriteStepNumber in the optimization command file is set to true, the function getF(Point x) is called and the new point is returned.
If WriteStepNumber is set to false, then the step number is not increased, and no simulation is done. The passed argument x is returned.
Note: You must call this function everytime when the optimization constructed a convergent sequence. This method increases a counter that can be used to implement penalty function and barrier function in the cost function.

Parameters:
x - the new point for the simulation
Returns:
the new point
Throws:
OptimizerException - if an OptimizerException occurs
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.Exception - if an Exception occurs
See Also:
getF(Point)

writeStepNumber

public final boolean writeStepNumber()
Returns the flag that indicates whether the step number has to written to the simulation input file or not.
Note: If this method returns true, then after each iteration step, the method increaseStepNumber(...) has to be called in order to allow the implementation of penalty function, barrier function and slackness variables.

Returns:
true if the step number has to written, false otherwise

useStepNumber

public final boolean useStepNumber()
Returns the flag that indicates whether the step number is used by the optimization algorithm. It is used if either wriSteNum = true or if the algorithm requires explicitly the step number to be used. Note that useStepNumber() always returns true if writeStepNumber() returns true, but writeStepNumber() may return false if useStepNumber() returns true.


getStepNumber

protected int getStepNumber()
Gets the current step number

Returns:
the current step number

goToEndOfCommandFile

public void goToEndOfCommandFile()
                          throws InputFormatException,
                                 java.io.IOException
Checks whether the current section is closed and then moves to the end of the file. If either of the operation fails, an InputFormatException is thrown.
Note: This method is called from the GenOpt kernel to ensure that all the information in the command file is parsed properly

Throws:
InputFormatException - if either of the checks fails
java.io.IOException - if the optimization command file cannot be accessed

isNextToken

public final boolean isNextToken(java.lang.String keyWord)
                          throws java.io.IOException
Checks whether the next Token is equal to the passed String.

Parameters:
keyWord - the keyword that has to be searched for
Returns:
true if the next Token equals the value of keyWord, false otherwise
Throws:
java.io.IOException - if the optimization command file cannot be accessed

getInputValueString

protected final java.lang.String getInputValueString(java.lang.String keyWord)
                                              throws InputFormatException,
                                                     java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueString

protected final java.lang.String getInputValueString(java.lang.String keyWord,
                                                     java.lang.String[] admVal)
                                              throws InputFormatException,
                                                     java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
admVal - the admissible values
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueBoolean

protected final boolean getInputValueBoolean(java.lang.String keyWord)
                                      throws InputFormatException,
                                             java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueInteger

protected final int getInputValueInteger(java.lang.String keyWord)
                                  throws InputFormatException,
                                         java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueInteger

protected final int getInputValueInteger(java.lang.String keyWord,
                                         int min,
                                         int minEqu,
                                         int max,
                                         int maxEqu)
                                  throws InputFormatException,
                                         java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
min - the minimum allowed value
minEqu - flag whether the minimum equality is strict or weak, as defined by Optimizer.EXCLUDING and Optimizer.INCLUDING
max - the maximum allowed value
maxEqu - flag whether the maximum equality is strict or weak, as defined by Optimizer.EXCLUDING and Optimizer.INCLUDING
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueDouble

protected final double getInputValueDouble(java.lang.String keyWord)
                                    throws InputFormatException,
                                           java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getInputValueDouble

protected final double getInputValueDouble(java.lang.String keyWord,
                                           double min,
                                           double minEqu,
                                           double max,
                                           double maxEqu)
                                    throws InputFormatException,
                                           java.io.IOException
Gets the value of keyWord from the algorithmEntry If another String than keyWord is at the current position of the algorithmEntry, an InputFormatException is thrown

Parameters:
keyWord - the expected keyWord
min - the minimum allowed value
minEqu - flag whether the minimum equality is strict or weak, as defined by Optimizer.EXCLUDING and Optimizer.INCLUDING
max - the maximum allowed value
maxEqu - flag whether the maximum equality is strict or weak, as defined by Optimizer.EXCLUDING and Optimizer.INCLUDING
Returns:
the value of keyWord
Throws:
InputFormatException - if another String than keyWord is read or if it is a invalid type
java.io.IOException - if the optimization command file cannot be accessed

getMaximumThreadPoolSize

public static int getMaximumThreadPoolSize()
Returns the maximum size of the thread pool

Returns:
the maximum size of the thread pool

throwInputError

protected final void throwInputError(java.lang.String expectedValue)
                              throws InputFormatException
Throws an input error. Use this method if the value that you got with one of the getInputValue... method is not valid.
Note: You have to call this method immediately after getting the value so that the error message points to the right line number

Parameters:
expectedValue - a String that specifies the value you expected
Throws:
InputFormatException - the thrown exception with the error message

getDimensionX

public final int getDimensionX()
Gets the number of independent variables (sum of continuous and discrete)

Returns:
the number of independent variables (sum of continuous and discrete)

getDimensionContinuous

public final int getDimensionContinuous()
Gets the number of independent, continuous variables

Returns:
the number of independent, continuous variables

getDimensionDiscrete

public final int getDimensionDiscrete()
Gets the number of independent, continuous variables

Returns:
the number of independent, continuous variables

getDimensionF

public final int getDimensionF()
Gets the number of function values

Returns:
the number of function values

setMode

public final void setMode(int constraintMode)
Sets the mode of the optimization

Parameters:
constraintMode - a flag indicating how constraints are treated
 0: optimization is in original space (constraints are not taken into account)
 1: optimization is in transformed space

getMode

public final int getMode()
Gets the mode of the optimization

Returns:
the constraints flag indicating how constraints are treated
 0: optimization is in original space (constraints are not taken into account)
 1: optimization is in transformed space

run

public abstract int run(Point x0)
                 throws OptimizerException,
                        SimulationInputException,
                        java.lang.NoSuchMethodException,
                        java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException,
                        java.lang.Exception
Abstract method for running the optimization algorithm until a termination criteria is satisfied

Parameters:
x0 - Initial iterate
Returns:
-1 if the maximum number of iteration is exceeded
+1 if any required accuracy is reached
+2 if the absolute accuracy is reached
+3 if the relative accuracy is reached
+4 if run is finished without checking a convergence criteria (e.g., parametric runs)
Throws:
OptimizerException - if an OptimizerException occurs
InputFormatException - if an InputFormatException occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an Exception occurs
SimulationInputException

run

public final int run()
              throws OptimizerException,
                     SimulationInputException,
                     java.lang.NoSuchMethodException,
                     java.lang.IllegalAccessException,
                     java.lang.reflect.InvocationTargetException,
                     java.lang.Exception
Method for running the optimization algorithm until a termination criteria is satisfied. This method is called by the GenOpt kernel.

Returns:
-1 if the maximum number of iteration is exceeded
+1 if any required accuracy is reached
+2 if the absolute accuracy is reached
+3 if the relative accuracy is reached
+4 if run is finished without checking a convergence criteria (e.g., parametric runs)
Throws:
OptimizerException - if an OptimizerException occurs
InputFormatException - if an InputFormatException occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an Exception occurs
SimulationInputException

getF

public Point[] getF(Point[] x,
                    boolean stopAtError)
             throws SimulationInputException,
                    OptimizerException,
                    java.lang.NoSuchMethodException,
                    java.lang.IllegalAccessException,
                    java.lang.Exception
Evaluates the simulation for the point x
The value conMode determines in which mode the constraints are treated. The return value contains the same point but with its function value as determined by the simulation.

Parameters:
x - the points to be evaluated
stopAtError - set to false to continue with function evaluations even if there was an error
Returns:
a clone of the points with the new function values stored
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an I/O error in the simulation input file occurs

getF

public Point getF(Point x)
           throws SimulationInputException,
                  OptimizerException,
                  java.lang.NoSuchMethodException,
                  java.lang.IllegalAccessException,
                  java.lang.Exception
Evaluates the simulation for the point x
The value conMode determines in which mode the constraints are treated. The return value contains the same point but with its function value as determined by the simulation.

Parameters:
x - the point being evaluated
Returns:
a clone of the point with the new function values stored
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an I/O error in the simulation input file occurs

setKnownFunctionValues

private boolean[] setKnownFunctionValues(Point[] x)
                                  throws OptimizerException
Sets the function values in these points that are already known.

Parameters:
x - the points for which the function values are needed
Returns:
a vectors with elements set to true if a simulation is needed for a particular point
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt

getPointerToEqualPoints

public static int[] getPointerToEqualPoints(Point[] x)
Gets an integer array that shows what points are equals. If an element is equal to -1, then no point with lower index is equal. If a element is non-negative, then its value is the index of the point that has is equal. For such a point, no simulation is required.

Parameters:
x - the points for which the function values are needed
Returns:
a vectors with elements set to true if a simulation is needed for a particular point
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt

simulate

public void simulate(Point x)
              throws SimulationInputException,
                     OptimizerException,
                     java.lang.NoSuchMethodException,
                     java.lang.IllegalAccessException,
                     java.lang.Exception
Evaluates the simulation based on the parameter set x

Parameters:
x - the point being evaluated
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an I/O error in the simulation input file occurs

_retryEvaluateSimulation

private Point _retryEvaluateSimulation(Point x,
                                       java.lang.Throwable t)
                                throws SimulationInputException,
                                       OptimizerException,
                                       java.lang.NoSuchMethodException,
                                       java.lang.IllegalAccessException,
                                       java.lang.reflect.InvocationTargetException,
                                       java.lang.Exception
Tries to evaluate the simulation a second time if an exception has been thrown

Parameters:
x - the point being evaluated
t - the caught Throwable
Returns:
a clone of the point with the new function values stored
Throws:
OptimizerException - if an OptimizerException occurs or if the user required to stop GenOpt
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an exception occurs

appendToOutputListing

public final void appendToOutputListing(java.lang.String s)
                                 throws java.io.IOException
appends a String to the output listing files

Parameters:
s - String to be appended to output listing files
Throws:
java.io.IOException

reportCurrentLowestPoint

protected void reportCurrentLowestPoint()
                                 throws java.io.IOException
Reports the current lowest point for the case that GenOpt has to terminate.
This method calls the function report with a corresponding comment and reports the minimum point to the output device

Throws:
java.io.IOException - if an I/O error in the optimization output files occurs

_evaluateSimulation

private Point _evaluateSimulation(Point x)
                           throws OptimizerException,
                                  SimulationInputException,
                                  java.lang.NoSuchMethodException,
                                  java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException,
                                  java.lang.Exception
Evaluates the simulation

Parameters:
x - the point being evaluated
Returns:
a clone of the points object with the new function values stored
Throws:
OptimizerException - if an OptimizerException occurs
SimulationInputException - if an error in writing the simulation input file occurs
java.lang.NoSuchMethodException - if a method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.lang.Exception - if an exception occurs

_replaceInInputFile

private static boolean _replaceInInputFile(java.lang.String text,
                                           java.lang.String value,
                                           FileHandler[] simulationInput)
Replaces text with value in simulationInput.

Parameters:
text - text to be searched for
value - value that will replace text
simulationInput - file handler in which search will take place
Returns:
true if text was found, false otherwise

replace

protected static boolean replace(java.lang.String[] strArr,
                                 java.lang.String text,
                                 java.lang.String value)
Replaces text with value in input functions.

Parameters:
strArr - array of strings that will be searched
text - text to be searched for
value - value that will replace text
Returns:
true if text was found, false otherwise

_variableNotFound

private static void _variableNotFound(java.lang.String variableName)
                               throws SimulationInputException
Throws a SimulationInputException that says that the variable could not be found.

Parameters:
variableName - name of the variable that was not found.
Throws:
SimulationInputException

_processResultFunction

private static double[] _processResultFunction(java.lang.String[] formula,
                                               double[] objFunVal)
                                        throws OptimizerException,
                                               java.lang.NoSuchMethodException,
                                               java.lang.IllegalAccessException,
                                               java.lang.reflect.InvocationTargetException,
                                               java.io.IOException
Process the function objects for post processing of the objective function.

Parameters:
formula - all formulas or null, if no function object has been specified for an objective function
objFunVal - the objective function values for which no function object has been specified
Returns:
an array with all objective function values
Throws:
OptimizerException - if not all arguments in a function could be replaced
java.lang.NoSuchMethodException - if the method that should be invoked could not be found
java.lang.IllegalAccessException - if an invoked method enforces Java language access control and the underlying method is inaccessible
java.lang.reflect.InvocationTargetException - if an invoked method throws an exception
java.io.IOException - if an error occurs

checkObjectiveFunctionValue

public void checkObjectiveFunctionValue(Point x)
                                 throws OptimizerException
Checks whether the last objective function value has already been obtained previously.
If it has been obtained previously, an information message is reported.
If the maximum number of matching function value is obtained, an exception is thrown.

Parameters:
x - the point to be checked
Throws:
OptimizerException - thrown if the maximum number of matching function value is obtained

setInfo

protected void setInfo(java.lang.String s,
                       int simNum)
Sets a message in the InformationManager The message will be displayed in the output stream (GUI in WinGenOpt, command shell otherwise) and in the log file

Parameters:
s - the message
simNum - The number of the simulation
See Also:
setWarning(java.lang.String, int)

setWarning

protected void setWarning(java.lang.String s,
                          int simNum)
Sets a message in the WarningManager. The message will be displayed in the output stream (GUI in WinGenOpt, command shell otherwise) and in the log file

Parameters:
s - the message
simNum - The number of the simulation
See Also:
setInfo(java.lang.String, int)

setNumberOfMatchingResults

protected void setNumberOfMatchingResults(int maxNumberOfMatchingResults)
Sets the maximal allowed number of matching results

Parameters:
maxNumberOfMatchingResults - the number how many results can be equal before an OptimizerException is thrown

getX0

public double getX0(int i)
Gets the value of x[i]
Note: x[i] might be in the transformed space depending on the value of conMode

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the value of the variable

getIndex0

public int getIndex0(int i)
Gets the value (i.e., the index) of x[i]

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the index of the variable

getDiscreteValueDouble0

public double getDiscreteValueDouble0(int variableNumber)
Gets the double representation of the variableNumber-th discrete parameter as specified in the command file
If the variable represents discrete numerical values, then the double value of the currently selected value is returned.
If the variable represents different string values, then the currently selected index is returned.

Parameters:
variableNumber - the number of the variable (zero-based counter)
Returns:
the double representation of the currently selected value

getX0

public double[] getX0()
Gets the values of the continuous variable x
Note: x might be in the transformed space depending on the value of conMode

Returns:
the vector of the independent variables

getIndex0

public int[] getIndex0()
Gets the indices of the discrete variable x

Returns:
the vector of indices of the independent variables

getLengthDiscrete

public final int getLengthDiscrete(int i)
Gets the number of elements of the i-th discrete variable

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the number of elements of the i-th discrete variable

getVariableNameContinuous

public final java.lang.String getVariableNameContinuous(int i)
Gets the name of the continuous variable x[i]

Parameters:
i - number of the variable (zero-based counter)
Returns:
the name of x[i]

getVariableNameDiscrete

public final java.lang.String getVariableNameDiscrete(int i)
Gets the name of the discrete variable x[i]

Parameters:
i - number of the variable (zero-based counter)
Returns:
the name of x[i]

getObjectiveFunctionName

public final java.lang.String getObjectiveFunctionName(int i)
Gets the name of the i-th objective function value. The name of the objective function value is specified by the key word Namei (i = 1, 2, ... getDimensionF()) in the section ObjectiveFunctionLocation.
Note: i is zero-based in the Java code, but one-based in the input file. Thus, to get the name of the first objective function value, you need to call this function with argument 0.

Parameters:
i - number of the objective function value (zero-based counter)
Returns:
the name of the [i]-th objective function value

getL

public double getL(int i)
Gets the lower bound l[i] of the continuous variable x[i]

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the lower bound of the variable

getU

public double getU(int i)
Gets the upper bound u[i] of the continuous variable x[i]

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the upper bound of the variable

getKindOfConstraint

public int getKindOfConstraint(int i)
Gets the kind of constraint that is imposed on the i-th continuous variable

Parameters:
i - the number of the variable (zero-based counter)
Returns:
the kind of constraint that is imposed on the parameter.
Possible constraints:
 1: no under boundary, no upper boundary
 2: under boundary,    no upper boundary
 3: under boundary,    upper boundary
 4: no under boundary, upper boundary 

getDx

public double getDx(int i,
                    double x)
Gets the step size dx[i] of the i-th continuous variable
Note: dx[i] might be in the transformed space depending on the value of conMode.

Parameters:
i - the number of the variable (zero-based counter)
x - the current value of the variable. If the optimization algorithm works in the transformed space, then x need to be in the transformed space as well.
Returns:
the value of the variable

getDx0

public double getDx0(int i)
Gets the step size dx[i] of the i-th continuous variable as specified in the command file.

Parameters:
i - the index of the variable (zero-based counter)
Returns:
the value of the variable

print

public void print(java.lang.String text)
Prints a message to the output device without finishing the line
Note: Use this method instead of System.out.printl(String), otherwise it won't be reported in the GUI

Parameters:
text - the text to be printed

println

public void println(java.lang.String text)
Prints a message to the output device, and then finishs the line
Note: Use this method instead of System.out.println(String), otherwise it won't be reported in the GUI

Parameters:
text - the text to be printed

reportMinimum

protected void reportMinimum()
                      throws java.io.IOException
Reports the minimum point.
This method gets the minimum point from the data base, calls the function report with an corresponding comment and reports the minimum point to the output device.

Throws:
java.io.IOException - if an I/O error in the optimization output files occurs

getMinimumPoint

public Point getMinimumPoint()
Gets the minimum point.
This method gets the minimum point from the data base.

Returns:
the point with the lowest function value
Throws:
java.io.IOException - if an I/O error in the optimization output files occurs

report

public void report(Point x,
                   boolean MainIteration)
            throws java.io.IOException
Reports an iterate to the output files and to the internal data structure Note: If a sub iteration is also a main iteration, then you have to call this function twice, first with MainIteration = false and then with MainIteration = true

Parameters:
x - the point to be reported
MainIteration - true if step was a main iteration or false if it was a sub iteration
Throws:
java.io.IOException - if an I/O error in the optimization output files occurs

maxIterationReached

protected final boolean maxIterationReached()
Checks if the maximum number of iteration is reached.

Returns:
true if the number of simulation is equal or bigger than the maximum number of iteration, false otherwise

getAbsAccuracyFunction

protected final double getAbsAccuracyFunction()
Gets the absolute accuracy of the last two main iterations

Returns:
the absolute accuracy of the last two main iterations

getRelAccuracyFunction

protected final double getRelAccuracyFunction()
Gets the relative accuracy of the last two main iterations

Returns:
the relative accuracy of the last two main iterations

getMainIterationNumber

protected final int getMainIterationNumber()
Gets the main iteration number

Returns:
the main iteration number

getSimulationNumber

protected static final int getSimulationNumber()
Gets the number of simulation. Note: This counter counts only the number of function evaluations that required a call to the simulation program. If the same point is evaluated twice -- which does not require a function evaluation -- then the counter returned by this method is not increased.

Returns:
the number of simulation

getMaxIterationNumber

protected final int getMaxIterationNumber()
Gets the maximum number of allowed main iterations

Returns:
the maximum number of allowed main iterations

checkMaxIteration

protected boolean checkMaxIteration()
Checks if the maximum number of iteration is exceeded

Returns:
true if the main iteration number is equal or bigger than the maximum number of iteration, false otherwise

mustStopOptimization

public final boolean mustStopOptimization()
Returns a flag that indicates whether GenOpt must be stopped after the current simulation (due to a user request).

Returns:
true if GenOpt has to be stopped, false otherwise

roundCoordinates

protected static Point roundCoordinates(Point x)
Rounds the coordinates of the continuous parameters to float format.

Parameters:
x - the point to be rounded.
Returns:
the point with rounded values for the independent parameters

isFeasible

protected boolean isFeasible(Point x)
Checks whether a point is feasible.

Parameters:
x - the point to be checked
Returns:
true if point is feasible, false otherwise

setToFeasibleCoordinate

public static double setToFeasibleCoordinate(double x,
                                             double l,
                                             double u)
Restricts the value of x such that l <= x <= u. This method recursively reassigning x := 2 * l - x if x < l, or x := 2 * u - x if x < u. If x is feasible, then it returns x unmodified.

Parameters:
x - the independent paramter
l - the lower bound
u - the upper bound
Returns:
a feasible value of x, such that l <= x <= u

_setToFeasibleCoordinate

private static double _setToFeasibleCoordinate(double x,
                                               double l,
                                               double u)
Computes x := 2 * l - x if x < l, or x := 2 * u - x if x < u. If x is feasible, then it returns x unmodified.

Parameters:
x - the independent paramter
l - the lower bound
u - the upper bound
Returns:
a feasible value of x, such that l <= x <= u

setToFeasibleCoordinate

public static int setToFeasibleCoordinate(int x,
                                          int l,
                                          int u)
Restricts the value of x such that l <= x <= u. This method recursively reassigning x := 2 * l - x if x < l, or x := 2 * u - x if x < u. If x is feasible, then it returns x unmodified.

Parameters:
x - the independent paramter
l - the lower bound
u - the upper bound
Returns:
a feasible value of x, such that l <= x <= u

_setToFeasibleCoordinate

private static int _setToFeasibleCoordinate(int x,
                                            int l,
                                            int u)
Computes x := 2 * l - x if x < l, or x := 2 * u - x if x < u. If x is feasible, then it returns x unmodified.

Parameters:
x - the independent paramter
l - the lower bound
u - the upper bound
Returns:
a feasible value of x, such that l <= x <= u