Nonlinear programming test function suite


[ MATLAB | C/C++ | C# | Java ]


The NLP test function library


The complete set of functions may be found in the following C source code: fcnsuite.c and should be compiled as follows:

for linux:
  
  gcc -c fcnsuite.c
  ld -o fcnsuite.so -shared fcnsuite.o

for windows:

  gcc -c fcnsuite.c -DWINDOWS
  dllwrap -o fcnsuite.dll fcnsuite.o

We recommend the GCC compiler native in Linux and available for Windows from here www.mingw.org.

Binary versions are also directly available from here: fcnsuite.dll (Windows) or as fcnsuite.so (Linux Intel binary).




MATLAB: wrapper

All of the function can be accessed directly from MATLAB using the following wrapper MEX file: mlbsuite.c, which is compiled as follows from within MATLAB:

for linux:
  
  mex mlbsuite.c

for windows:

  mex mlbsuite.c -DWINDOWS

For windows we recommended using the LCC compiler that comes default with MATLAB.

Example usage from MATLAB:

>> x = [707.3356954913084;68.6;102.89999999999999;282.0252391859284;84.1988];
>> [f, g, h] = mlbsuite(x, 38, 0, 'g16');
% that is 38 inequality constraints g(x) <= 0 and 0 equality constraints h(x) = 0
% output is the objective function value f and constraint functions g and h
% x is the input variables which can also be in MATRIX form, i.e. n x NoPoints
% for example:
>> x = rand(5,100);
>> [f, g, h] = mlbsuite(x, 38, 0, 'g16');
>> size(f)
ans =

     1   100
>> size(g)
ans =
    38   100
>> size(h)
ans =
     0   100

Here is a MATLAB function that tests each of the functions one at a time with the best known solution: bestknown_new.m.

กก

*For users' convenience  gn  & hn for 24 problems are list here:

gn=[9,2,0,6,2,2,8,2,4,6,0,1,0,0,0,38,0,13,5,6,1,1,2,2]; hn=[0,0,1,0,3,0,0,0,0,0,1,0,3,3,2,0,4,0,0,14,5,19,4,0];

NEW:

Example study using the MATLAB Optimization Toolbox




C/C++: loading the DLL library or shared object

An example of this is actually given in the MATLAB wrapper above.

In general you must modify your code as follows:

Add the following to your header: For windows:

#include <windows.h>
#include <process.h>
typedef void (WINAPI * PPROC) (double *, double *, double *, double *, int, int, int, int);
#define LIBHANDLE HANDLE
#define GetProcedure GetProcAddress
#define CloseDynalink FreeLibrary

and for Linux

#include <dlfcn.h>
#include <pthread.h>
typedef void (*PPROC) (double *, double *, double *, double *, int, int, int, int);
#define LIBHANDLE void *
#define GetProcedure dlsym
#define CloseDynalink dlclose

Define the variables:

  PPROC pfcn;
  LIBHANDLE hLibrary;

Now to call the function you must load the library fcnsuite and get a pointer to the procedure, for Windows:

  hLibrary = LoadLibrary ("fcnsuite.dll");
  pfcn = (PPROC) GetProcedure (hLibrary, "g01"); /* g01 to g24 is valid */

and Linux:

  hLibrary = dlopen ("./fcnsuite.so", RTLD_NOW);
  pfcn = (PPROC) GetProcedure (hLibrary, "g01"); /* g01 to g24 is valid */

now the test function may be called as follows:

  pfcn (&x, &f, &g, &h, n, 1, ng, nh);

where types are:

  double x[n], f, g[ng], h[nh];

and n is the number of variables, ng is the number of inequality constraints of type g(x)<=0, nh is the number of equality constraints of type h(x)=0 and f is the objective function value. The function will return the objective function f, the ng constraint values in g, and the nh constraint values in h.

Finally close the library like this:

  CloseDynalink (hLibrary);


Compiling your code:

Windows: nothing special.

Linux: used the flag -ldl




C#: loading the DLL library from C#

class C
   {
   [ DllImport("fcnsuite.dll") ]
      public static extern void g01 ( double [], double [], double [], double [], int, int, int, int);
   public static int Main()
      {...




Java:

[benchmarkConstr.java]

usage:

// Declaration
....
int nx=**;
int ng=**;
int nh=0;
int nf=1+ng+nh;
....
double[] fitness = new double[nf];
double[] x = new double[nx];
....
// Call
fitness = benchmarkConstr.g01(x,nf,ng,nh);

*The very first line in the code (package ...) will have to be modified by each user.




Test Data:  New

Please check your code with the following data set:

[test_data]

กก