Basic Borg MOEA use for the truly newbies (Part 2/2)

This post will walk you though a simple example using Borg MOEA to solve the DTLZ2, 3 objective instance.  I suggest reading first Part 1 of this post.  Once you have compiled the Borg MOEA, you are ready to follow this example.

The DTLZ2 problem, named after its creators :Deb, Thiele, Laumanns and Zitzler, is a very popular function to test MOEAs’ performance since  its  Pareto-optimal solutions are analytically known, and it is easily scalable to any number of objectives.

Step 1. Set the DTLZ2, 3 objective instance

In your borg folder,  open the dtlz2.py function. You should see the following script:

```
from sys import *
from math import *

nvars = 11
nobjs = 2
k = nvars - nobjs + 1

while True:
# Read the next line from standard input
line = raw_input()

# Stop if the Borg MOEA is finished
if line == "":
break

# Parse the decision variables from the input
vars = map(float, line.split())

# Evaluate the DTLZ2 problem
g = 0

for i in range(nvars-k, nvars):
g = g + (vars[i] - 0.5)**2

objs = [1.0 + g]*nobjs

for i in range(nobjs):
for j in range(nobjs-i-1):
objs[i] = objs[i] * cos(0.5 * pi * vars[j])
if i != 0:
objs[i] = objs[i] * sin(0.5 * pi * vars[nobjs-i-1])

# Print objectives to standard output, flush to write immediately
print " ".join(["%0.17f" % obj for obj in objs])
stdout.flush()
```

You can easily scale the number of objectives in the DTLZ2 function by modifying lines 4 and 5 in the code.  Since we want to solve the 3 objective configuration of the problem, we will change the nobjs  and set it equal to 3.  In general :  number of variables= number of objectives + 9;  in this case nvars= 12. Alternatively, if we want to work with the 5 objective instance, then we would have nobjs= 5 and nvars= 14.

```
from sys import *
from math import *

nvars = 12
nobjs = 3
k = nvars - nobjs + 1

```

Once you have updated the file, save it and go back to your terminal.

Step 2. Run the DTLZ2 3 objective instance from your terminal

From your terminal  make sure you are in the borg folder and type the following command:

```./borg.exe -v 12 -o 3 -e 0.01,0.01,0.01 -l 0,0,0,0,0,0,0,0,0,0,0,0 -u 1,1,1,1,1,1,1,1,1,1,1,1 -n 10000 python dtlz2.py > dtlz2.set
```

The -v and the -o flags, as you probably guessed are the number of decision variables and objectives, respectively. The -e flag stands for the epsilon precision values, here the same epsilon values are specified for the three objectives for simplicity, just remember that they don’t necessarily need to be the same across objectives.  The -l and -u flag are the decision variables’ lower and upper bounds.  These bounds can vary according to the problem.  The -n flag stands for the number of iterations, here we specify 1000,  you can certainly increase the number of iterations.  In the last part of the command you call the dtlz2.py function, finally, the optimization results are saved  in a separate file using the > “greater than”  symbol.  Once you typed the previous script, you should see a new file in your borg folder called dtlz2.set.  Before we go on, type the following command in your terminal and see what happens:

```./borg.exe -h
```

The -h flag provides information about the different options available.

Step 3. Select the objectives

Now, open your newly generated dtlz2.set file. you will see something like this:

```# BORG version: 1.8
# Current time: Thu Jun 25 17:12:00 2015
# Problem: python dtlz2.py
# Number of variables: 12
# Number of objectives: 3
# Number of constraints: 0
# Lower bounds: 0 0 0 0 0 0 0 0 0 0 0 0
# Upper bounds: 1 1 1 1 1 1 1 1 1 1 1 1
# Epsilons: 0.01 0.01 0.01
# Directions: 0 0 0
# Constraint mode: E
# Seed: (time)
1 0.814090298840556947 0.409932057219915436 0.453114658489247812 0.602037485943714312 0.612211413314472264 0.63507815287255176 0.284561154879054812 0.319971228064652446 0.510268965514402262 0.565795181158015859 0.352339424454035932 2.00000000000000014e-17 7.00000000000000035e-17 1.1566219845629353
0.200664515777928404 0.658663937901916241 0.459011341616803015 0.456423615588035791 0.72948415840455394 0.502347551242693147 0.55253340411468177 0.523000325718170678 0.424118159653203652 0.418071947834685986 0.307354991375789255 0.667924369576233357 0.55237113861310283 0.929550654944727661 0.352579197090774399
0.600637603847835599 0.635510585462702893 0.537202278296969316 0.480501397259140872 0.538845435998899225 0.565887992485444302 0.540269661215032948 0.32823362137901485 0.548470138166351484 0.485323707827721162 0.661267336189765076 0.603296309515394924 0.342802362666870974 0.531842633344500104 0.872739730448630957
0.200664515777928404 0.962019489314716703 0.478360997918643505 0.456423615588035791 0.72948415840455394 0.508917943579420218 0.434628101329525951 0.523000325718170678 0.416896640814134301 0.418071947834685986 0.307354991375789255 0.667924369576233357 0.0645572417675578242 1.08080813229192496 0.353051662882838901
0.580252259871913978 0.626070509625966998 0.537503391458319713 0.47945571905554607 0.540634044436276051 0.565466312655102277 0.5375236610793378 0.336204078423532282 0.541224805744518811 0.481480141441438469 0.645345342922852394 0.597006852306095737 0.362763876068478097 0.544895812217087494 0.844603875086156197
```

This is only a snippet of what you should see, here only five solutions are shown (one solution per row); for an epsilon of 0.01 you should see at least 100 solutions.  The first 12 columns in the file represent the 12 decision variables and the last 3 columns are the objectives.  In order to visualize the Pareto front, we want to select only the objectives.  To do so, type the following command:

```awk 'Begin {FS=" "}; /^#/ {print \$0}; /^[-]?[0-9]/ {printf("%s %s %s\n", \$13,\$14,\$15)}' dtlz2.set > dtlz2.obj
```

The previous command is fully described in Joe’s post.  Once you run it you should see a new file called dtlz2.obj, with three columns, one for each of the objectives.

Step 4. Visualize the Pareto front

The Pareto front of the DTLZ2 problem is the first quadrant of a unit sphere centered at the origin and all the decision variables are equal to 0.5.  For the 3-objective case that we solved in this example, the Pareto approximate front generated by Borg MOEA is depicted in the figure below:

With your results, attempt to generate a similar plot in the language of your choice.  Once you have visualized the Pareto Front, you will have completed this exercise!

11 thoughts on “Basic Borg MOEA use for the truly newbies (Part 2/2)”

1. Simon Plate |

Hello Jazmin,

thanks for the beginner’s guide!

At first, I got stuck executing Borg for the first time according to your example. I have now figured out that -e option does not accept spaces after the commas separating the operator values, otherwise the program gives the error: “Failed parsing argument, invalid format or invalid number of elements”.

So, I guess your command line should look like this:
./borg.exe -v 12 -o 3 -e 0.01,0.01,0.01 -l 0,0,0,0,0,0,0,0,0,0,0,0 -u 1,1,1,1,1,1,1,1,1,1,1,1 -n 1000 python dtlz2.py > dtlz2.set

Best,
Simon

• Hi Simon,

Thank you for giving the tutorial a try. I fixed the space issue, thanks for pointing that out.

Best,
Jazmin

2. Svetlana |

Hello Jazmin,

Is there a similar tutorial for problems written in Java?

Thanks,
Svetlana.

3. Jose |

Hi Jazmin,
I was trying to follow your post, but I am getting the following error. Could you help me…

File “dtlz2.py”, line 42
print ” “.join([“%0.17f” % obj for obj in objs])
^
SyntaxError: invalid syntax

Thanks,
j.

4. Yosune Miquelajauregui |

Hello!
I was able to run the code in the terminal. However, it is taking a long time to process. Is that normal. Besides, I got the following message:
./borg.exe -v 11 -o 2 -e 0.01,0.01 -l 0,0,0,0,0,0,0,0,0,0,0 -u 1,1,1,1,1,1,1,1,1,1,1 -n 100 python dtlz2.py > dtlz2.set
execv: No such file or directory

is that normal as well?
Thanks for the post!