public abstract class Optimizer
extends java.lang.Object
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2021, 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.
Modifier and Type | Field and Description |
---|---|
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)
|
Modifier | Constructor and Description |
---|---|
|
Optimizer()
Constructor
|
protected |
Optimizer(GenOpt genOptData,
int constraintMode)
Constructor
|
Modifier and Type | Method and Description |
---|---|
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 fileIf 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 variableNote: 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.
|
protected static final java.lang.String LS
protected static final java.lang.String FS
public static final boolean MAINITERATION
public static final boolean SUBITERATION
public static final int ORIGINAL
public static final int TRANSFORMED
public static final int EXCLUDING
public static final int INCLUDING
private int conMode
private static int dimCon
private static int dimDis
private static int dimX
private static int dimInpFun
private static int dimF
private static java.lang.String[] nameF
public static java.util.concurrent.CountDownLatch done
private static GenOpt data
private static java.io.StreamTokenizer algorithm
Algorithm
of the command fileprivate static java.lang.String optComFilNam
private static java.lang.String separator
private static int stepNumber
private static boolean wriSteNum
private static boolean useSteNum
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.private static FileHandler[] simInpTemFilHan
private static ObjectiveFunctionLocation[] objFunObj
private static int nSimInpFil
private static int nSimLogFil
private static int nSimOutFil
private static int[] funValPoi
private static java.util.Map<Point,java.lang.Double[]> evaPoi
genopt.algorithm.util.math.Point.compareTo(java.lang.Object o)
private static int maxThrPoo
private static java.util.concurrent.atomic.AtomicBoolean functionValuesParsed
private java.util.concurrent.CountDownLatch funValParLat
private boolean firstSimulations
true
, then no second simulation is done in case of an error.protected Optimizer(GenOpt genOptData, int constraintMode) throws InputFormatException, OptimizerException, java.io.IOException, java.lang.Exception
genOptData
- a reference to the GenOpt object.constraintMode
- a flag indicating how constraints are treated0: optimization is in original space (constraints are not taken into account) 1: optimization is in transformed space
InputFormatException
- if an error occurs while searching for Main
in the Algorithm
sectionjava.io.IOException
- if an I/O exception occursjava.lang.Exception
- in an exception occursOptimizerException
public Optimizer()
protected static void resetStepNumber(int sN)
sN
- protected java.lang.String getOutputPath()
Algorithms that write their own output files should write them
to the directory returned by this function.
protected void ensureOnlyContinuousParameters() throws OptimizerException
OptimizerException
is thrown (with an
descriptive information)OptimizerException
- if some independent parameters are not continuousprotected void ensureOnlyDiscreteParameters() throws OptimizerException
OptimizerException
is thrown (with an
descriptive information)OptimizerException
- if some independent parameters are not discreteprivate void _deleteRunFiles(java.lang.String[] path, java.lang.String[] name) throws java.lang.Exception
path
- path of the filesname
- name of the filesjava.lang.Exception
- if a SecurityException occuredprivate void _copyRunFiles(java.lang.String[] savePath, java.lang.String[] path, java.lang.String[] name, int simNum) throws java.lang.SecurityException, java.lang.Exception
path
to savePath
and
adds the run number in front of the file name.savePath
- path where the files have to be copied to.
If it does not exist, it will be created.path
- source path of the filesname
- name of the filessimNum
- The number of the simulationjava.lang.SecurityException
- if a SecurityException occuredjava.lang.Exception
- if the directory could not be madeprotected final void algorithmRequiresUsageOfStepNumber()
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.protected final void increaseStepNumber()
WriteStepNumber
is set to false
, then the step number
is not increasedincreaseStepNumber(Point)
protected final Point increaseStepNumber(Point x) throws SimulationInputException, OptimizerException, java.lang.Exception
WriteStepNumber
in the optimization
command file is set to true
, the function
getF(Point x)
is called and the new point is returned.WriteStepNumber
is set to false
,
then the step number is not increased, and no simulation is done.
The passed argument x
is returned.x
- the new point for the simulationOptimizerException
- if an OptimizerException occursSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.Exception
- if an Exception occursgetF(Point)
public final boolean writeStepNumber()
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.true
if the step number has to written,
false
otherwisepublic final boolean useStepNumber()
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
.protected int getStepNumber()
public void goToEndOfCommandFile() throws InputFormatException, java.io.IOException
InputFormatException
- if either of the checks failsjava.io.IOException
- if the optimization command file cannot be accessedpublic final boolean isNextToken(java.lang.String keyWord) throws java.io.IOException
keyWord
- the keyword that has to be searched fortrue
if the next Token equals the value of keyWord
,
false
otherwisejava.io.IOException
- if the optimization command file cannot be accessedprotected final java.lang.String getInputValueString(java.lang.String keyWord) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final java.lang.String getInputValueString(java.lang.String keyWord, java.lang.String[] admVal) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
admVal
- the admissible valueskeyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final boolean getInputValueBoolean(java.lang.String keyWord) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final int getInputValueInteger(java.lang.String keyWord) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final int getInputValueInteger(java.lang.String keyWord, int min, int minEqu, int max, int maxEqu) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
min
- the minimum allowed valueminEqu
- flag whether the minimum equality is strict or weak,
as defined by Optimizer.EXCLUDING
and
Optimizer.INCLUDING
max
- the maximum allowed valuemaxEqu
- flag whether the maximum equality is strict or weak,
as defined by Optimizer.EXCLUDING
and
Optimizer.INCLUDING
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final double getInputValueDouble(java.lang.String keyWord) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedprotected final double getInputValueDouble(java.lang.String keyWord, double min, double minEqu, double max, double maxEqu) throws InputFormatException, java.io.IOException
keyWord
from the algorithmEntry
If another String than keyWord
is at the current position
of the algorithmEntry
, an InputFormatException is thrownkeyWord
- the expected keyWord
min
- the minimum allowed valueminEqu
- flag whether the minimum equality is strict or weak,
as defined by Optimizer.EXCLUDING
and
Optimizer.INCLUDING
max
- the maximum allowed valuemaxEqu
- flag whether the maximum equality is strict or weak,
as defined by Optimizer.EXCLUDING
and
Optimizer.INCLUDING
keyWord
InputFormatException
- if another String than keyWord
is read or if it is a invalid typejava.io.IOException
- if the optimization command file cannot be accessedpublic static int getMaximumThreadPoolSize()
protected final void throwInputError(java.lang.String expectedValue) throws InputFormatException
getInputValue...
method is not valid.expectedValue
- a String that specifies the value you expectedInputFormatException
- the thrown exception with the error messagepublic final int getDimensionX()
public final int getDimensionContinuous()
public final int getDimensionDiscrete()
public final int getDimensionF()
public final void setMode(int constraintMode)
constraintMode
- a flag indicating how constraints are treated0: optimization is in original space (constraints are not taken into account) 1: optimization is in transformed space
public final int getMode()
0: optimization is in original space (constraints are not taken into account) 1: optimization is in transformed space
public abstract int run(Point x0) throws OptimizerException, SimulationInputException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.Exception
x0
- Initial iterate-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)OptimizerException
- if an OptimizerException occursInputFormatException
- if an InputFormatException occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an Exception occursSimulationInputException
public final int run() throws OptimizerException, SimulationInputException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.Exception
-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)OptimizerException
- if an OptimizerException occursInputFormatException
- if an InputFormatException occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an Exception occursSimulationInputException
public Point[] getF(Point[] x, boolean stopAtError) throws SimulationInputException, OptimizerException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.Exception
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.x
- the points to be evaluatedstopAtError
- set to false to continue with function evaluations even if there was an errorOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an I/O error in the simulation input file occurspublic Point getF(Point x) throws SimulationInputException, OptimizerException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.Exception
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.x
- the point being evaluatedOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an I/O error in the simulation input file occursprivate boolean[] setKnownFunctionValues(Point[] x) throws OptimizerException
x
- the points for which the function values are neededtrue
if a simulation is needed
for a particular pointOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptpublic static int[] getPointerToEqualPoints(Point[] x)
x
- the points for which the function values are neededtrue
if a simulation is needed
for a particular pointOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptpublic void simulate(Point x) throws SimulationInputException, OptimizerException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.Exception
x
- the point being evaluatedOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an I/O error in the simulation input file occursprivate Point _retryEvaluateSimulation(Point x, java.lang.Throwable t) throws SimulationInputException, OptimizerException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.Exception
x
- the point being evaluatedt
- the caught ThrowableOptimizerException
- if an OptimizerException occurs or
if the user required to stop GenOptSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an exception occurspublic final void appendToOutputListing(java.lang.String s) throws java.io.IOException
s
- String to be appended to output listing filesjava.io.IOException
protected void reportCurrentLowestPoint() throws java.io.IOException
java.io.IOException
- if an I/O error in the optimization output files
occursprivate Point _evaluateSimulation(Point x) throws OptimizerException, SimulationInputException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.Exception
x
- the point being evaluatedOptimizerException
- if an OptimizerException occursSimulationInputException
- if an error in writing the
simulation input file occursjava.lang.NoSuchMethodException
- if a method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.lang.Exception
- if an exception occursprivate static boolean _replaceInInputFile(java.lang.String text, java.lang.String value, FileHandler[] simulationInput)
text
with value
in simulationInput
.text
- text to be searched forvalue
- value that will replace text
simulationInput
- file handler in which search will take placetrue
if text
was found, false
otherwiseprotected static boolean replace(java.lang.String[] strArr, java.lang.String text, java.lang.String value)
text
with value
in input functions.strArr
- array of strings that will be searchedtext
- text to be searched forvalue
- value that will replace text
true
if text
was found, false
otherwiseprivate static void _variableNotFound(java.lang.String variableName) throws SimulationInputException
SimulationInputException
that says that the variable
could not be found.variableName
- name of the variable that was not found.SimulationInputException
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
formula
- all formulas or null
, if no function object has been specified
for an objective functionobjFunVal
- the objective function values for which no
function object has been specifiedOptimizerException
- if not all arguments in a function could be replacedjava.lang.NoSuchMethodException
- if the method that should be invoked could not be foundjava.lang.IllegalAccessException
- if an invoked method enforces Java language access
control and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException
- if an invoked method throws an exceptionjava.io.IOException
- if an error occurspublic void checkObjectiveFunctionValue(Point x) throws OptimizerException
x
- the point to be checkedOptimizerException
- thrown if the maximum number of matching
function value is obtainedprotected void setInfo(java.lang.String s, int simNum)
s
- the messagesimNum
- The number of the simulationsetWarning(java.lang.String, int)
protected void setWarning(java.lang.String s, int simNum)
s
- the messagesimNum
- The number of the simulationsetInfo(java.lang.String, int)
protected void setNumberOfMatchingResults(int maxNumberOfMatchingResults)
maxNumberOfMatchingResults
- the number how many results can be
equal before an OptimizerException is thrownpublic double getX0(int i)
x[i]
x[i]
might be in the transformed space
depending on the value of conMode
i
- the number of the variable (zero-based counter)public int getIndex0(int i)
x[i]
i
- the number of the variable (zero-based counter)public double getDiscreteValueDouble0(int variableNumber)
variableNumber
-th
discrete parameter as specified in the command filevariableNumber
- the number of the variable (zero-based counter)public double[] getX0()
x
x
might be in the transformed space
depending on the value of conMode
public int[] getIndex0()
x
public final int getLengthDiscrete(int i)
i
- the number of the variable (zero-based counter)public final java.lang.String getVariableNameContinuous(int i)
x[i]
i
- number of the variable (zero-based counter)x[i]
public final java.lang.String getVariableNameDiscrete(int i)
x[i]
i
- number of the variable (zero-based counter)x[i]
public final java.lang.String getObjectiveFunctionName(int i)
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
.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
.i
- number of the objective function value (zero-based counter)[i]
-th objective function valuepublic double getL(int i)
l[i]
of the continuous
variable x[i]
i
- the number of the variable (zero-based counter)public double getU(int i)
u[i]
of the continuous
variable x[i]
i
- the number of the variable (zero-based counter)public int getKindOfConstraint(int i)
i
- the number of the variable (zero-based counter)1: no under boundary, no upper boundary 2: under boundary, no upper boundary 3: under boundary, upper boundary 4: no under boundary, upper boundary
public double getDx(int i, double x)
dx[i]
of the i-th continuous variabledx[i]
might be in the transformed space
depending on the value of conMode
.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.public double getDx0(int i)
dx[i]
of the i-th continuous variable as specified
in the command file.i
- the index of the variable (zero-based counter)public void print(java.lang.String text)
System.out.printl(String)
,
otherwise it won't be reported in the GUItext
- the text to be printedpublic void println(java.lang.String text)
System.out.println(String)
,
otherwise it won't be reported in the GUItext
- the text to be printedprotected void reportMinimum() throws java.io.IOException
java.io.IOException
- if an I/O error in the optimization output files
occurspublic Point getMinimumPoint()
java.io.IOException
- if an I/O error in the optimization output files
occurspublic void report(Point x, boolean MainIteration) throws java.io.IOException
MainIteration = false
and then with
MainIteration = true
x
- the point to be reportedMainIteration
- true
if step was a main iteration or
false
if it was a sub iterationjava.io.IOException
- if an I/O error in the optimization output files
occursprotected final boolean maxIterationReached()
true
if the number of simulation is
equal or bigger than the maximum number of iteration,
false
otherwiseprotected final double getAbsAccuracyFunction()
protected final double getRelAccuracyFunction()
protected final int getMainIterationNumber()
protected static final int getSimulationNumber()
protected final int getMaxIterationNumber()
protected boolean checkMaxIteration()
true
if the main iteration number is
equal or bigger than the maximum number of iteration,
false
otherwisepublic final boolean mustStopOptimization()
true
if GenOpt has to be stopped, false
otherwiseprotected static Point roundCoordinates(Point x)
x
- the point to be rounded.protected boolean isFeasible(Point x)
x
- the point to be checkedtrue
if point is feasible,
false
otherwisepublic static double setToFeasibleCoordinate(double x, double l, double u)
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.x
- the independent paramterl
- the lower boundu
- the upper boundx
, such that l ≤ x ≤ u
private static double _setToFeasibleCoordinate(double x, double l, double u)
x := 2 * l - x
if x < l
,
or x := 2 * u - x
if x < u
.
If x
is feasible, then it returns x
unmodified.x
- the independent paramterl
- the lower boundu
- the upper boundx
, such that l ≤ x ≤ u
public static int setToFeasibleCoordinate(int x, int l, int u)
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.x
- the independent paramterl
- the lower boundu
- the upper boundx
, such that l ≤ x ≤ u
private static int _setToFeasibleCoordinate(int x, int l, int u)
x := 2 * l - x
if x < l
,
or x := 2 * u - x
if x < u
.
If x
is feasible, then it returns x
unmodified.x
- the independent paramterl
- the lower boundu
- the upper boundx
, such that l ≤ x ≤ u