# Optimization using genetic algorithm in matlab

Tags:
1. May 8, 2014

### amos.ngwoke

For my B.Eng project, I'm optimizing the thermal efficiency of a boiler using genetic algorithm in MATLAB. i'm finding it very tough to write my fitness function, constraint equations and upload my initial population which is a set of data from my case study plant.
for boiler thermal efficiency,
η = Q(hf - hg)/ (q * GCV)

here's my fitness function

function E = thermal_eff(x)
% thermal_efficiency(x) calculates thermal efficiency of a steam boiler
%
% E = thermal_efficiency(x) calculates the thermal efficiency of the steam boiler
%
% x(1) = Q = Quantity of steam generated per hour in kg/hr
% x(2) = hg = Enthalpy of saturated steam in kCal/kg of steam
% x(3) = hf = Enthalpy of feed water in kCal/kg of water
% x(4) = q = Quantity of fuel used per hour (q) in kg/hr
% x(5) = GCV = Gross calorific value of the fuel (GCV) in kCal/kg of fuel
%
% thermal efficiency of a steam boiler
E = (x(1)*(x(2)- x(3))) / (x(4) * x(5));

I don't know how accurate I am, and i'm finding it difficult to write the constraint equations and upload my initial population

Please assist me in any way you can
Thanks

2. May 8, 2014

### Staff: Mentor

Lets start from the beginning. You need to optimize the effciency in what sense? What are the things you can actually change (type of fuel?, size of the boiler?, temperature of the boiler?)?

3. May 8, 2014

### amos.ngwoke

pressure and temperature of boiler and feed water, mass flow rate of fuel and steam. all these can be altered. but the pressure and temperature are used to calculate the enthalpy which appears in the equation i wrote above

4. May 8, 2014

### Staff: Mentor

So you need to make your fitness function take as input these parameters use them to calculate the terms in the equation, from which you will get thermal efficiency.

Do you plan to use a pre-written package for the evolution engine, or do you intend to write your own?

5. May 9, 2014

### amos.ngwoke

Yes.
i haven't seen any detailed work close to it, from which i can pull some "pre-written package", so i'm making efforts to writing my own.

6. May 12, 2014

### Staff: Mentor

If you're going to do it yourself, I recommend getting a good book, such as books.google.com/books?isbn=3540606769

You will find there discussions about initial populations and handling constraints. If you have particular questions, you can post them in this thread.

7. Nov 19, 2015

### Janos Szena

To create the initial population you need first of all make a function like this:

function Chrom = createRealPopulation(Nind, Bounds);
Range = rep((Bounds(2,:)-Bounds(1,,[Nind 1]);
Lower = rep(Bounds(1,:), [Nind 1]);
Chrom = rand(Nind,Nvar) .* Range + Lower;

The Bounds array is defined by you corresponding to the number of variables. Each variable gets an upper and a lower bound. During the optimization the algorithm will search between these bounds. It is essential to choose appropriate values for lower and upper bound, because the optimum search depends on it.
E.g. see an example of it.
NVAR = 5;
NIND= 20;
SUBPOP = 4;
% lower and upper bound, identical for all n variables
Bounds = [-5.12; 5.12];
Bounds = Bounds(1:2,ones(NVAR, 1));

Chrom = createRealPopulation(SUBPOP*NIND, Bounds);

Hopefully I moved your work a bit forward.

8. Nov 19, 2015

### kroni

The cost function is continuous, and i think convex. Use FMINNUNC, LSQNONLIN ! instead of slowwwwwwww genetic algorithm.

9. Nov 19, 2015

### Janos Szena

The Genetic Algorithm isn't slow if you don't run it under MATLAB. I developped the algorithm in Visual C++. The running time is very quick. Otherwise my version (the MATLAB open source version only) is rather old, gets from 1994. Since I have an own new version in which I corrected the faults and extended with new features.