User function (v2)

Syntax:

[popu,ple] = userfun(mode,popuin,figh,axsh,plein,cheix,xdata,ydata);

nrow: number of subplot-rows

nind: number of individuals, size of population

The Easy-IEC toolbox calls this function in every loop to evaluate the population. Because the evaluation depends on the user's problem, hence it is the user's duty to write this function.

The Easy-IEC toolbox calls this function in two cases:

1. At the beginning of the evolution-loop (mode = 0). The task: to evaluate the actual population (all individuals) and to display plots and texts for the operator.

2. During the evolution-loop after editing a line-object (mode = 1). The task: to calculate the new chromosome from the new (edited) line-object and to evaluate the modified individual.

Because the operator can modify a line-object, the chromosome which belongs to this line-object should be also changed. The mode = 1 stands for that a line-object has been modified. In this case, the cheix argument variable gives which individual belongs to the edited line-object (i.e. cheix = 1 means the first individual); the xdata and ydata gives the points of new (edited) line-object. The user function must extract the new chromosome from xdata and ydata (the user determines the structure of chromosomes).

If mode = 0, the user function must evaluate all individuals of the population and draw plots for the operator. The popuin.chrom contains the chromosomes for every individuals (population variable).

The function must return the resulted population variable in popu variable.

The popuin is the actual population variable.

The function must return the handles of editable line-objects in ple variable (mode=0/1). Only one editable line-object can belong to one individual, hence the ple variable is a nind length vector which contains these handles. The handle of a line-object is returned by plot command (see the example program below).

The figh is the handle of the interactive figure which includes the subplots.

The axsh matrix contains the handles of the subplots (axes). The user must draw plots and write texts on these subplots.

The user function gets the handles of editable-line objects in plein argument variable (mode=1).

Example:

function popu = userfun2(mode,popuin,figh,axsh,plein,cheix,xdata,ydata);

%User function:

global param tout yout1 %global variables -> simulation

figure(figh); %actual figure

nind = size(popu.chrom,1); %number of individuals (= columns on the figure)

nvar = 3+3; %one chromosome contains 3+3 real values

%-------------------- MODE = 0 --------------------

if mode == 0,

popu = popin; %resulted population

ple = zeros(1,nind); %handles of editable line-object (->in the loop!)

%Loop:

for i = 1:nind,

%Evaulation (-> tout, yout1):

param = popu.chrom(i,:);

sim('usersimu',[0 10]);

%First subplot (represents the chromosome):

subplot(axsh(1,i));

h = plot(popu.chrom(i,1:3),popu.chrom(i,4:6),'b-');

ple(i) = h; %this plot is editable, h is the handle of it

%Second subplot (represents the simulation output):

subplot(axsh(2,i));

plot(tout,yout1,'r-');

%Refresh the figure:

drawnow

end

end

%-------------------- MODE = 1 --------------------

if mode == 1,

popu = popuin;

ple = plein;

%Extract the chromosome from edited line-object:

popu.chrom(cheix,1:3) = xdata(:)';

popu.chrom(cheix,4:6) = ydata(:)';

%Evaulate of modified individual:

param = popu.chrom(cheix,:);

sim('usersimu',[0 10]);

%Refresh subplots of the modified individual:

subplot(axsh(1,cheix));

h = plot(popu.chrom(i,1:3),popu.chrom(i,4:6),'b-');

ple(cheix) = h;

subplot(axsh(2,cheix));

plot(tout,yout1,'r-');

drawnow;

end