⇄ Menu

Using the prebuilt package

This section describes the outline of the configuration files, and walks through the steps of an example running under Windows and Linux. The method shown here is only suitable for global optimization. If you want to run local optimization build up your optimizer config from java code or implement a wrapper global optimizer for local optimization.

Optimizer Config XML

The optimizer config XML defines the connections between the Java classes and parameterizes them.

Creating configured optimizer

XML Structure

<base class="base.optimizer.Baseclass">Create optimizer Baseclass algorithm from JAR.
<par1 type="long">2</par1>Set par1 to '2' in Baseclass.
<par2 type="double">0.04</par2>Set par2 to '0.04' in Baseclass.
<par3 type="string">UNIT_CUBE</par3>Set par3 to 'UNIT_CUBE' in Baseclass.
...
Create optimizer subclass algorithm from JAR and set it as par_subclass1 in Baseclass
<par_subclass1 type="abstract.optimizer.AbstractSubclass1" class="exact.optimizer.Subclass1Type">
<par1 ...> ... </par1>Set subclass parameters.
...
</par_subclass1>
...
</base>

BND File

The BND file contains the identifier of the objective function, the dimension count of the running and a min-max inclusive interval constraint for every dimension. It can also contain the known local optimum value for testing the optimizer.

Running the optimizer

BND File Structure

readable nameReadable name of the function.
class nameFirstly interpreted as the full name of a java class implementing the function, secondly look for it in the 'org.uszeged.inf.optimization.functions' package.
dimension countNumber of dimensions of the search space, some functions may be interpreted in different number of dimensions.
dimension_1_lower_bound dimension_1_upper_boundInclusive interval for the first dimension.
dimension_2_lower_bound dimension_2_upper_boundInclusive interval for the second dimension.
...
dimension_N_lower_bound dimension_N_upper_boundInclusive interval for the Nth dimension where N is the dimension count.
known optimum value(Optional parameter for testing purposes, holds the global optimum value for the function.)

Example configuration

This section shows an example of running a built in optimizer algorithm on a custom objective function.

First of all you will need the Java 8 JDK or the compiled somefunc.class file of your objective function. Secondly you will need the Java 8 JRE which comes alone or with the JDK from Oracle's website. Thirdly you will need a consol for running the application.

Config File: GlobalUnirandiCLS.xml

Code

<?xml version="1.0"?>
<Global class="org.uszeged.inf.optimization.algorithm.optimizer.global.Global">
<MaxNumberOfSamples type="long">
400
</MaxNumberOfSamples>
<SampleReducingFactor type="double">
0.04
</SampleReducingFactor>

<LocalOptimizer class="org.uszeged.inf.optimization.algorithm.optimizer.local.parallel.UnirandiCLS">
<MaxFunctionEvaluations type="long">
1000
</MaxFunctionEvaluations>
<RelativeConvergence type="double">
0.00000001
</RelativeConvergence>

<LineSearchFunction class="org.uszeged.inf.optimization.algorithm.optimizer.line.parallel.LineSearchImpl">
</LineSearchFunction>
</LocalOptimizer>

<Clusterizer class="org.uszeged.inf.optimization.algorithm.clustering.GlobalSingleLinkageClusterizer">
<Alpha type="double">
0.1
</Alpha>
</Clusterizer>
</Global>

Explanation

The first node in the document holds information about the global optimizer class. The class attribute of the node points to the Global class in the optimizer package. The first subnode is the MaxNumberOfSamples which type is long and has a value of 400. It means that the optimizer will randomize maximum 400 starting points for local search in the search space. The second argument is the SampleReducingFactor with the type double and a value of 0.04. It means that 4% of the NewSampleSize (which default value is 100) will be choosen from the generated sample points. In this case it is the best 4 samples. The LocalOptimizer node holds a class which have to be instantiated. The algorithm is specified in the class argument which have to implement the interface specified by the setLocalOptimizer(LocalOptimizer) function of Global. MaxFunctionEvaluations is stands for one local search. RelativeConvergence is a stopping criteria, lesser values stand for longer and more accurate running. The LineSearchFunction has no parameters. It is a parameter of the LocalOptimizer The Clusterizer is parameter of the Global class. The Alpha parameter controls the clusterizer thresholds shrinking speed. The bigger the value is (in [0;1] inclusive interval) the harder it is to clusterize a sample. At 1 the clustering is effectively disabled.

BND File: sumofsquares.bnd

Code

sum x^2
SumOfSquares
2
-0.5 2
-2.5 4.5

Explanation

The second line contains the objective functions classname. If there is a class with this name without package it will be used, otherwise the application will try to use org.uszeged.inf.optimization.functions.SumOfSquares. Secondly we specify the dimension count which is now 2. The next two lines contain the dimensional intervals from dimension 1 to dimension 2. The intervals are inclusive.

Objective Function: SumOfSquares

Code

package org.uszeged.inf.optimization.functions;

import org.uszeged.inf.optimization.data.*;

public class SumOfSquares implements Function{

	public double evaluate(Vector x){

		double res = 0;

		for (int i = 0;i < x.getDimension();i++){
			res += x.getCoordinate(i+1)*x.getCoordinate(i+1);
		}

		return res;
	}

	public boolean isParameterAcceptable(Vector lb,Vector ub){
		return isDimensionAcceptable(lb.getDimension());
	}

	public boolean isDimensionAcceptable(int dim){
		return true;
	}
}

Explanation

The objective functions class must implement the org.uszeged.inf.optimization.data.Function interface. The boolean isParameterAcceptable(Vector,Vector) function has to return true if the dimension and the search space is accepted by the function. The boolean isDimensionAcceptable(int) function has to return true if the dimension count is acceptable. The double evaluate(Vector) function receives a vector with dimension count values which are indexed from one. The function have to return the objective function value at the specified location.

Console commands for Windows

Compile the objective function

Type into the console:

javac -cp global.jar externalfunc\org\uszeged\inf\optimization\functions\SumOfSquares.java

Run the optimizer

The main class for running with config XML and bnd file is Calculate. The basic parameterisation is java -cp global.jar Calculate <config.xml> <function.bnd>. The results will be printed to the console. It is a common method to route the outputs into a result file.

Type into the console:

java -cp "global.jar;externalfunc" Calculate -o TestGlobalConfigs/GlobalUnirandiCLS.xml -f TestInputFiles/sumofsquares.bnd >> results/GlobalUnirandiCLSsumofsquares.res

Console commands for Linux

Compile the objective function

Type into the console:

javac -cp global.jar externalfunc/org/uszeged/inf/optimization/functions/SumOfSquares.java

Run the optimizer

The main class for running with config XML and bnd file is Calculate. The basic parameterisation is java -cp global.jar Calculate <config.xml> <function.bnd>. The results will be printed to the console. It is a common method to route the outputs into a result file.

Type into the console:

java -cp "global.jar:externalfunc" Calculate -o TestGlobalConfigs/GlobalUnirandiCLS.xml -f TestInputFiles/sumofsquares.bnd >> results/GlobalUnirandiCLSsumofsquares.res

Results

The results of a running are printed in one line as follows. The number of function evaluations, runtime in milliseconds, the optimum value and a number of parameters which depends on the actual algorithm. Also a logfile is created in the logs directory which describes the algorithm settings and additional information about the optimization process.

This example is from the included result file. This version of the used algorithm adds the number of local searches to the result file.

Number of function evaluations Runtime in milliseconds Optimum value [Algorithm specific values]
411 52 1.1034719987680216E-17 1

You can find the example sources at the Downloads page, in the using_jar_example directory of the zip.