irace and C++

161 views
Skip to first unread message

Amira Zarglayoun

unread,
Apr 22, 2019, 1:02:08 AM4/22/19
to irace-...@googlegroups.com
Hey,
I want to use the irace package to tune parameters for several metaheuristics algorithms (SA,TS) on the graph partitioning problem. I 've implemented the algorithms in C++. 
I've checked the user guide and tried to follow the example but the ACOTSP does not compile in windows. Do you have any examples to use iRace with C++?
I am a beginner in "structuring programs" so each of the methods is implemented as follows: for the SA I define several functions (reading graph, neighborhood, cost, SA, etc) and then in the main function I call what I need. Same for TS. So let's say that I want to tune the initial temperature in SA, how to do that since I already need to fix a value for it in the C++ code in order to compile. 
I would be glad if you could guide me a little bit. 
Thanks.
Best Regards

Leslie Perez Caceres

unread,
Apr 22, 2019, 1:09:57 AM4/22/19
to The irace package: Iterated Racing for Automatic Configuration
hello Amira,

If you want to run the ACOTSP example without compiling the C++ code, one alternative would be to used the Java version, the link is in the same website as the C++ code (http://www.aco-metaheuristic.org/aco-code/public-software.html). 

There is no difference for irace if your algorithm was programmed in C++, Java, or any other language. The target runner script is the script that acts as an intermediary between irace and your algorithm. The script must only take into account the input format in which irace will provide you the instance, seed and parameter values you have to execute your algorithm with, and the output format in which irace expects you to return the result of the execution. Please check section 5.2 of the user to get more information on how to define a proper target runner. The package comes with templates for windows and linux, so you can take the one for windows and modify it to execute your algorithm. 

If you want to automatically tune your algorithm you will need to define a way to pass the parameter values to your algorithm when you make the execution call in the target runner. This can be done in different ways, but the most common would be to pass the parameter values as arguments. For example, if your algorithm executable is called my_sa.exe you can execute it like this:

my_sa.exe --instance instance/instance1.txt --evaluations 10000 --t_initial 100

you will need to parse these arguments in your main to set the parameter values that these arguments indicate. Then, in the target runner, you will have to build this execution line (like in the examples that are in the package). The --flag argument will be automatically passed by irace if you configure them correctly in the parameter file. For example, the parameter.txt file should be:

# param_name param_flag param_type param_domain
temp_initial
"--t_initial " r (1, 100)


Check section 5.1 of the user guide for more details on defining the parameters.

I hope this can help you, and let us know if you have any doubts or problems.

Bests,
Reply all
Reply to author
Forward
0 new messages