(Greek) Θεωρία Βελτιστοποίησης – quiz

Sorry, this entry is only available in Greek.

Posted in Εκπαίδευση | Tagged | Leave a comment

Optimization Algorithms for GenOpt

GenOpt® is an optimization program for the minimization of a cost function that is evaluated by an external simulation program, such as EnergyPlus, TRNSYS, Dymola, IDA-ICE or DOE-2. You may find more information in:

http://simulationresearch.lbl.gov/GO/

This page will include information and source code implementation of optimization algorithms that I’ve built for use in research projects. Two packages of evolutionary algorithms are coupled with GenOpt, the ECJ and JGAP. You may find more information about ECJ and JGAP in:

http://cs.gmu.edu/~eclab/projects/ecj/

http://jgap.sourceforge.net/

The pattern search of Hooke and Jeeves is modified to work in a synchronously parallel version as well. I intend to post details on their operation and tutorial examples in a different post.

1) The first and probably the most useful implementation is the simple genetic algorithm. The Java Genetic Algorithms Package (JGAP) is coupled with GenOpt to provide the functionality of the typical genetic algorithm operation (best chromosomes selector-mutation-crossover). This version has been used in many of my research studies and it’s robust and mature. I’ve even modified some of JGAP’s functionality to work more efficiently utilizing multiple threads. It can include one suggested solution in the initial population too. The major disadvantage of this algorithm implementation is the lack of ability to handle negative values of the objective function. I’ve modified the JGAP version to handle such operation, but the risk of breakage some other functionality of JGAP and backward compatibility issues couldn’t let the implementation in the base package. You have to work with the current version of JGAP (3.6.2.), so you should ensure that the objective function doesn’t result in negative values. You may download the compiled files of the simple genetic algorithm implementation here:

GeneticAlgorithmJGAP.class

jgapBulkFunction.class

JGAPConfiguration.class

2) The second algorithm is the modified version of Hooke and Jeeves. This is a pattern search algorithm which doesn’t utilize the multithreaded capability. An asynchronous parallel operation of such an algorithm would improve the efficiency, but the current version of GenOpt couldn’t let implementing such an architecture. So I built a synchronously parallel version. This version searches all directions in a multithreaded way before it updates its current position. I’ve used it for problems where the number of the design variables is twice as bigger than the number of the computer threads and it worked faster especially when the start point were near optimal. It is expected to have an even better operation for problems where the number of threads is bigger than the number of design variables. This version replaces the current implemented version in GenOpt and you choose the desired operation via a keyword in the command file. You can use this version with the hybrid Particle Swarm algorithm or the genetic algorithm. You may download the compiled file of the synchronously parallel version of Hooke-Jeeves here:

GPSCoordinateSearch.class

3) The next algorithm is the obvious connection of the genetic algorithm with the modified Hooke-Jeeves. This hybrid operation is equivalent to the current PSO+Hooke-Jeeves implementation. The genetic algorithm global searches for a near optimal point and the result is used as a starting point for Hooke-Jeeves for refinement. Discrete variables are set to a constant value as Hooke-Jeeves works only on continuous variables. You may download the compiled file of the hybrid genetic algorithm with Hooke-Jeeves here:

GeneticAlgorithmJGAPGPSHJ.class

4) The ECJ coupling implementation has provided 2 more algorithms. The first is another simple genetic algorithm. This still is in beta version (my coupling code is in beta, not ECJ) and it probably will stay that way, as the JGAP implementation is good enough. The second is an interesting implementation of the NSGA-II which is a multiobjective genetic algorithm. So GenOpt is able to work for multiobjective (or multi-criteria) problems as well! This is a beta version as well, but a public version will be available soon and it will stay that way because I indent to start from scratch implementing NSGA-II to a new optimization package. Let me know if you need any help utilizing multiobjective algorithms to a research project.

Java programmers will find their way easy (build a project from genopt’s source code, adding the source files in the algorithms folder and add a reference to the jgap file). A very abstract description on how you make them work is: a) get GenOpt’s jar file and add the .class files in the algorithms folder (jar is a compressed file like zip). Then add a lib folder outside genopt.jar with the “jgap3.6.2.jar”. You should add a line in the MANIFEST.MF file to include the JGAP path as “Class-Path: lib/jgap3.6.2.jar”.

Use the above information at your own risk! I’m not responsible for any losses because of the use of the algorithms. These algorithms cannot ensure finding the optimal solution to a problem and the optimality is depended on the problem setup as well.

I’m interested participating to research projects utilizing optimization algorithms to improve building design and control efficiency.

Posted in Engineering Research | Tagged , , | Leave a comment

Tutorial on GenOpt with Radiance

In this tutorial, I will set up an optimization problem of a building construction. The solution to this optimization problem will be provided by GenOpt. My intention is to show how to couple a new simulation engine (Radiance) to GenOpt, but it can be used as a reference to any optimization problem solved by GenOpt. I assume that you have a basic understanding on how to describe an optimization problem and some familiarity with GIGO (garbage in – garbage out) text simulation engines. Don’t expect tutorial photos because all work is done in text files.

GenOpt® is an optimization program for the minimization of a cost function that is evaluated by an external simulation program, such as EnergyPlus, TRNSYS, Dymola, IDA-ICE or DOE-2.

You can find more information to

http://simulationresearch.lbl.gov/GO/

Radiance is a suite of programs for the analysis and visualization of lighting in design. The primary advantage of Radiance over simpler lighting calculation and rendering tools is that there are no limitations on the geometry or the materials that may be simulated. Radiance is used by architects and engineers to predict illumination, visual quality and appearance of innovative design spaces, and by researchers to evaluate new lighting and daylighting technologies.

You can find more information to

http://radsite.lbl.gov/radiance/HOME.html

Step 1 – Describing the optimization problem

I assume that I have an office room with dimensions of 5m X 7m with 3m height. The 5m wall is facing south and it has a window of 4.6m X 1.5m at 1m height from the floor. There are venetian blinds of 0.1m width outside of this window. I want to find the reflectance/angle of the blinds and the reflectance of the ceiling to get as close to 500lux as I can, at 2 points (2m and 3m distance from the window).

I don’t go on more details of the model because it is insignificant with the optimization problem itself. The problem isn’t very realistic (I should include glare dependence in my fitness function and a more accurate simulation model to get useful daylight optimization results) but I wanted to build a simple sample problem with 2 or more optimization variables and an objective function depending on 2 or more variables.

Building the objective function (or cost or fitness function):

I want as close to 500lux I can get at 2 points. If Poi1 is illuminance at point1 and Poi2 is illuminance at point2 then the simplest fitness function I can build is

f(x) = abs(Poi1-500)+abs(Poi2-500)

which we want to be as close to zero we can get (minimization problem). A real optimization problem might include a more sophisticated objective function which would be depended by glare and might increase exponential the objective function’s value outside desirable illuminance/glare values (implementation of constraints).

Design parameters:

The design parameters are independent continuous variables with box constraints.

1) Reflectance of the ceiling refl_ceil with 0 < refl_ceil < 1 with 0.2 step

2) Reflectance of the blinds refl_blinds with 0 < refl_blinds < 1 with 0.2 step

3) Angle of the blinds angle_blinds with -90 < angle_blinds < 90 (0 means horizontal slats) with 5 degrees step

Step 2 – Optimization simulation requirements

GenOpt is able to couple to any simulation engine that gets it’s input from text files and writes it’s output to text files as well. The basic GenOpt simulation steps are:

a) The selected optimization algorithm calculates the values of the design parameters (except for the initial start point which some algorithms make use of suggested values).

b) GenOpt creates the input text files (required by the coupled program) by changing keywords in some template text files to the values of the design parameters.

c) Then it starts the coupled simulation program (in a new file folder) using these newly created input files and waits for it to finish.

d) When the coupled program finishes, GenOpt retrieves result values from the output text files, calculates the objective function value and sends the result to the optimization algorithm to decide for the next values of the design parameters.

I’ll explain later how to setup GenOpt to do all that. My concern about coupling Radiance is how GenOpt will retrieve the result values from the output text files. Most simulation programs write output text files with delimiter keywords before the value. Energyplus, for example, creates a comma delimited file which uses a number before the result value and has an explanation line like this:

241,7,SOUTHZONEZONEHVAC:IDEALLOADSAIRSYSTEM,Ideal Loads Air Heating Energy[J] !RunPeriod

which means that there is line later like this:

241,5731670.34231873

which means that “241” which is Ideal Loads Air Heating Energy has the value of 5731670.34231873 [J]

Our (delimiter) keyword in that example (if we want to retrieve Ideal Loads Air Heating Energy for RunPeriod) will be “241,” and GenOpt will be smart enough to look for the last occurrence of “241,” and it will retrieve the value after that keyword. Version 3.1 of GenOpt has introduced a “FirstCharacterAt” setup which will let know the position of the value in the same line (if multiple values are in the same line where the delimiter keyword is).

For our Radiance coupling example, we are not able to retrieve result values by delimiter keywords because Radiance creates an output file with the values itself in each line without delimiter keywords. So I have to build a simple program to wrap Radiance, retrieve the results line by line and write a new output text file with delimiter keywords. GenOpt instead of starting Radiance, it will start my Radiance wrapper program and retrieve output values from my program. This way, my program will be general enough to be used to another situation like this. Most situations which use output files with delimiter keywords won’t need this step.

Edit Oct 4, 2012: As Khaled Nassar showed at 11th Radiance Workshop (2012 Copenhagen) there is a way to get delimited (formatted) results from Radiance by using -o option in rcalc.

Step 3 – Radiance simulation setup

This isn’t a Radiance tutorial but I’ll present most key points on how I set up my simulation. I installed desktop radiance20b (http://radsite.lbl.gov/deskrad/) without the AutoCAD support. Make sure that Radiance installation has added the path of \radiance\bin folder to your environment variables path, so you can have access to the Radiance executives from anywhere in your disk (I think desktop Radiance do that anyway).

I have built 3 text input Radiance files and one executive (.bat) with the start commands and options:

  • room.rad – describes the materials, the geometry and the blinds of the scene.
  • clear_sky.rad – describes the light source.
  • pp1.pts – describes the 2 points where I want the result values.
  • run.bat – executes the command “oconv clear_sky.rad room.rad>all.oct” which builds the file “all.oct” and then executes rtrace with options to calculate illuminance values at the 2 points (from pp1.pts) and print the values to the file results.dat. It can have an option to output results with headers but nothing I could find useful coupling to GenOpt (so I use the option without the headers).

When I execute run.bat I get output the all.oct and results.dat with the result values as text.

Step 4 – GenOpt simulation setup

I’ll try to explain in more details here, but I have to say that I use windows XP/7 and Unix simulations might be slightly different to setup. As far as I know, the only differences would be the configuration file .cfg which describes how to start the coupled program.

GenOpt needs 3 files (and the template files) to run the simulation:

  1. the .ini file – has the current simulation options on how to retrieve/change values from the files and sets up the calculation of the objective function.
  2. the .cfg file – which is the configuration file on how to execute the coupled program. Once configured, it remains the same for all simulations with the same coupled program.
  3. the command file – which describes the design parameters with their initial values and sets up the optimization algorithm’s options.

.ini File:

This text file has a simulation section and an optimization section.

“Template” subsection (of files subsection….of simulation section) describes the input files which GenOpt will search to change some text keywords with the design parameters values. My example has all the design parameters keywords in the room_Template.RAD but the other files are needed for the simulation as well.

In “Files” subsection of the simulation section I put these texts which are explained at the end of each line with comments starting with “//”:

//GenOpt will use these files to create the Radiance simulation input files.

Template {

File1 = room_Template.RAD;         //I’ll explain later for this file

File2 = clear_sky_Template.rad;  //Just a renamed copy

File3 = pp1_Template.pts;             //Just a renamed copy

File4 = run_Template.bat;            //Just a renamed copy

}

//These files will be created for each Radiance simulation.

Input {

File1 = room.RAD;

SavePath1 = Save;     //Optional parameter which means that it will save a copy of the input files in a “Save” folder.

File2 = clear_sky.rad;

SavePath2 = Save;

File3 = pp1.pts;

SavePath3 = Save;

File4 = run.bat;

SavePath4 = Save;

}

Log {

File1 = results.dat;      //GenOpt will search here for error keywords. I don’t know how Radiance prints any errors so I just put the results file. This means that we will not be prompted for any Radiance simulation errors (not very nice, I know).

}

Output {

File1 = delimitedResults.dat; //GenOpt will search for this file to retrieve the result values.

SavePath1 = Save; //Optional parameter to save a copy

}

Configuration {

File1 = “RadianceWinXP.cfg”;   //This file has the coupling information (how GenOpt can start a Radiance simulation)

}

CallParameter { // optional section

//Suffix = ********;

}

I describe here my objective function. It will be constructed from the bottom up, which means that GenOpt will search in the Output file (delimitedResults.dat) for delimiter “result1,” and “result2,” and the values will be set to Poi1 and Poi2. Next, it will substract 500 from each value. Next it will get the absolute value of the substraction, and finally it will add the 2 values to calculate the fitness value.

ObjectiveFunctionLocation

{

Name1 = fitness;

Function1 = “add( %absPoi1% , %absPoi2% )”;

Name2 = absPoi2;

Function2 = “abs( %Poi2-500% )”;

Name3 = absPoi1;

Function3 = “abs( %Poi1-500% )”;

Name4 = Poi2-500;

Function4 = “add( %Poi2% , -500 )”;

Name5 = Poi1-500;

Function5 = “add( %Poi1% , -500 )”;

Name6 = Poi2;

Delimiter6 = “result2,”;

Name7 = Poi1;

Delimiter7 = “result1,”;

}

Optimization {

Files {

Command {

File1 = command.txt; //This file has some more optimization information

}

}

} // end of configuration file

Someone who already knows how to use GenOpt will notice that GenOpt doesn’t have an abs() function. I had to add my own abs() function in GenOpt and recompile it. GenOpt’s manual has the details how to do this.

.cfg file:

This file has the error keywords of the coupling program and the command how to start the coupling program simulation (in command line). For my example I start my Radiance wrapper program to get delimited results. It’s a java program so it needs “java -jar” before it’s name to start.

command file:

This file describes the 3 design parameters and the optimization’s algorithm settings.

For example:

Parameter{

Name = refl_ceil;

Min = 0;

Ini = 0.5;

Max = 1;

Step = 0.2;

}

describes the design parameter of the ceiling reflection as a continuous parameter. GenOpt will look in the template files for a keyword named %refl_ceil% and it will change it to a value. This parameter has a minimum value of 0 and a maximum of 1. The initial algorithm value for this parameter will be set to 0.5, but not all algorithms use this setting. The value step will be set to 0.2. Again not all algorithms use this setting. Some algorithms like HookeJeeves will use this setting to “snap” values to a mesh grid of this value. If you want this kind of operation using the Genetic Algorithm then it will be wiser to describe this design parameter as a discrete parameter. Have in mind that this will not work for a hybrid operation between GA and HookeJeeves because HookeJeeves doesn’t use discrete parameters (it sets them to a fixed value extracted from the optimum solution). The solution is to do a global optimization with GA (or PSO) with the parameters described as discrete. When it finishes, change these to continuous at a finer mesh and do a local optimization with HookeJeeves, using as initial values the best values obtained by global optimization.

At this section:

OptimizationSettings{

MaxIte = 2500;

MaxEqualResults = 1000;

WriteStepNumber = false;

UnitsOfExecution = 0;

}

MaxIte is the maximum iteration number.

MaxEqualResults is self-explanatory.

WriteStepNumber is an advanced topic for optimization problems where you want to use penalty functions.

UnitsOfExecution is the suggested number for parallel simulations. If it’s equal to 0 then GenOpt will set this to the threads number of your workstation.

I don’t describe the algorithm’s settings here because it’s algorithm depended and I’ve used a genetic algorithm which hasn’t been implemented yet in GenOpt. I’ve coupled GenOpt with JGAP which is a genetics algorithm and genetics programming package. This again is an advanced topic which I might describe in another tutorial. You may copy the Algorithm settings from a command.txt file in GenOpt’s examples.

Finally, I have to build my templates files. I have only one file where the design parameters values exist, which is room_Template.RAD.

In this file I changed the values of the ceiling reflectance to the string %refl_ceil% , the blinds material reflectance changed to %refl_blinds% and blinds angle to %angle_blinds%.

I haven’t mentioned how I built my Radiance wrapper program (radWrap.jar) to get delimited results. This is a simple programming concept and you may find more information in programming tutorials. You can download all files I’ve used with the implementation code of radWrap.

To start the optimization simulation I need these Radiance settings files:

and these GenOpt settings files:

Start GenOpt, and open the optWinXP.ini. You will find some self-explanatory text files with the results when it’s finished. Be aware that depending on your machine and the optimization algorithm’s settings, the optimization runtime will vary from minutes to weeks.

Posted in Engineering Research | Tagged | 15 Comments