Runtime dynamics with serial Borg

written by Riddhi Singh

Purpose:

The purpose of this write up is to provide step-by-step instructions for generating a runtime dynamics file using the serial version of Borg.

Pre-requisites:

Familiarity with running the serial version of Borg is NOT needed. We will give a brief overview of setting up a Borg problem. The user should preferably have a pre-defined problem to test this method. Otherwise, the dtlz2 test function that is provided with the serial release of Borg (dtlz2.py) can be used.   Serial Borg can be requested here: http://borgmoea.org/

Step-by-step instructions for obtaining a runtime dynamics file when calling Borg from the command line

1.    Create a Borg executable – use the make file that comes with the Borg-1.6 version.

Use the following commands in a makefile and then run the ‘make’ command- 

CC  = gcc

build:

            ${CC}  -o borgExec frontend.c borg.c mt19937ar.c -lm

Alternatively run the following on command line:

gcc -o borgExec frontend.c borg.c mt19937ar.c -lm

2.    Create a problem executable – This step can be skipped while using the dtlz2.py executable that comes with the Borg package. If compiling your own problem, you need essentially create a bridge between Borg and your problem. For each function evaluation, Borg needs a way to pass variables to your problem, and after evaluation your problem needs to return the associated objective function values back to Borg. You can use the template in dtlz2.py to parse Borg’s input stream. Sample code in C++ is provided below. Note that you cannot use this code directly, this is just the interface with your test function that should be defined above.

void test_function(double * vars, double *objs)

{

/*your test function here

test function takes inputs in vars and returns objective function values in objs*/

/*Once the objectives are evaluated, pass them to Borg using output stream functions*/

      for (int cols=0;cols<nobjs;cols++)

            {

              printf(“%lg “, objs[cols]);

            }

      printf(“\n”);

      fflush(stdout);

}

void main( int argc, char * argv[])

{

//Initialize number of variables and objective functions

  int nvars = 10;

  int nobjs = 1;

/*Declare the pointers to the arrays that will store the incoming Borg variables and outgoing objective function values*/

  double * vars = new double [nvars];

  double * objs = new double [nobjs];

//Read the input stream and output the objective function values

  int maxSize = 10000;

  char buffer [maxSize];

/*Read the input stream from Borg until the end of stream is reached and

assign the numbers to a testbuffer*/

Borg terminates each stream with a endline character*/

while ( *fgets(buffer, maxSize, stdin)!=’\n’)

    {

      int UseSize = strlen(buffer);

      char *pEnd;

      char *testbuffer = new char [UseSize];

      for (int i=0; i <UseSize; i++)

            {

              testbuffer[i] = buffer[i];

            }

/*Now, parse through the testbuffer and assign variables.

Borg only passes variables followed by objective functions but since we are reading these as strings, they need to be converted to double before sending out for evaluation*/

      for (int cols =0;cols<nvars;cols++)

            {

              vars[cols] = strtod(buffer, &pEnd);

              testbuffer  = pEnd;

            }

      //Evaluate the test problem with this vector

     test_problem(vars, objs);

//This test problem is declared as:

void test_problem(double vars, double* objs)

//The function returns the objective function values in objs

}

Now compile this executable. Use the following commands in a makefile and then run the ‘make’ command-

CC2 = g++

build:

            ${CC2} -o TestExec TestFunction.cpp

Alternatively run the following on command line:

g++ -o TestExec TestFunction.cpp

3.    Get the runtime dynamics file – Once both Borg and problem executables are ready, obtaining runtime dynamics from the command line is straightforward. Use the following command to generate a runtime dynamics file –

./BorgExec –v 10 –o 1 –n 1000 –e 0.01 –R RuntimeDynamicsFile.txt –F 10 ./TestExec > BorgOutput.txt

The options are elaborated in the README file that is provided with the Borg-1.6 package. The ‘RuntimeDynamicsFile.txt’ contains the runtime dynamics and the ‘BorgOutput.txt’ file contains the final result.

Alternatively, if using the dtlz2.py function, execute the following command –

./BorgExec –v 11 –o 2 –n 1000 –e 0.01,0.01 –R RuntimeDynamicsFile.txt –F 10 python dtlz2.py > BorgOutput.txt

Advertisements