mathematical optimization - Can the genetic-algorithm in Matlab pass a second return value from the fitness-function to the constraints? -


i simulating batch evaporator in matlab. genetic algorithm varies several starting variables x (such size, max. mass of working fluid, overall number of evaporators used ...) , goal maximize efficiency. function evaporator(x) returns negative efficiency minimized algorithm.
besides efficiency, there several other values calculated. 1 duration of simulated cycle (not runtime of calculation itself!). constraint, duration of whole evaporation cycle should, depending on number of evaporators, not short (e.g. if 3 evaporators used, whole cycle should take @ least 3*5s = 15s).
know can use nonlinear constraints option of ga (nonlcon). in case have same calculations evaporator(x) again, return calculated duration time. problem is, have call external dll several thousand times per run , calculations become slow. therefore want avoid running calculations twice.
somehow possible, evaporator(x) returns both negative efficiency , duration @ same time? ga should minimize negative efficiency , evaluate duration regarding constraints. thought nesting evaporator(x) inside anonymous function, think function still has called twice then?

i had experience multiobjective optimization of efficiency , duration @ same time, unfortunately gamultiobj algorithm cannot handle integer variables.

at moment using penalty function on short durations inside evaporator(x), think, constraints handling of ga algorithm better this.

edit: got bit more complicated, in end working:

function [ returnvalue ] = switchhxoutput( requestedcase, inputs ) %switchhxoutput returns fitness value or duration depending on requested %case  persistent fitnessvalue duration oldinputs;  if isempty(oldinputs)     oldinputs = {}; %initialize oldinputs cell end   [isallreadycalculated, ioldinput] =... ismember(cell2mat(inputs), cell2mat([oldinputs{:}]), 'rows');   if isempty(oldinputs) || ~isallreadycalculated     [fitnessvalue(end+1), duration(end+1)] = lengthycalculation(inputs); %add current results persistent array     oldinputs(end+1) = {inputs}; %add current inputs persistent array     returnvalue = [fitnessvalue(end), duration(end)]; else     returnvalue = [fitnessvalue(ioldinput), duration(ioldinput)]; % return old values end  if strcmp(requestedcase, 'fitnessvalue')     returnvalue = returnvalue(1); elseif strcmp(requestedcase, 'duration')     returnvalue = returnvalue(2); else     error('myapp:selectoutput','requested case not supported') end  end %function 

i know growing cell array isn't fast. lengthycalculation takes 2 minutes each call still saving lot of time. furthermore best individuals of each generation used again in next generation. in case saved values can used instead of recalculating them again. code works fine parallel computation. fitness value , duration calculated same worker. following generations results can on worker.

one option include persistent state, records both efficiency , duration computed on last run (this memoization) , decide return based on function inputs.

for example,

function return_value = evaporator(method, value, inputs)    persistent efficiency duration;    if strcmp(method, 'recalculate')       % lengthy calculation goes here       efficiency = inputs + 1;       duration   = inputs + 10;       pause(5);   end    switch value     case 'efficiency'       return_value = efficiency;     case 'duration'       return_value = duration;   end  end 

the result is

>> evaporator('recalculate', 'efficiency', 10) 11 >> evaporator('memoized', 'duration') 20 >> evaporator('recalculate', 'efficiency', 20) 21 >> evaporator('memoized', 'duration') 30 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -