[Scilab-users] Genetic Algorithm (GA) in Scilab: Retrieve the final solution
tanthiamhuat
tanthiamhuat at yahoo.com
Thu Jun 12 03:26:21 CEST 2014
Hi Scilab experts in GA,
I would like to find out how can I retrieve the final GA solutions in Scilab
variables.
Firstly, I am trying to solve a Simple Card Problem, as define here:
http://www.codeproject.com/Articles/16286/AI-Simple-Genetic-Algorithm-GA-to-solve-a-card-pro
My Scilab code is as below: But I could not retrieve its final solution for
Cards_Stack1 and Cards_Stack2.
How should I change my code, such that those variables (Cards_Stack1,
Cards_Stack2) are available?
clear;clc;clf
function out = objectivefunction(AllCards)
AllCards = 1:1:10;
Cards_Stack1 = samwr(5,1,AllCards)'
Cards_Stack2 = setdiff(AllCards,Cards_Stack1)
err1 = sum(Cards_Stack1) - 36;
err2 = prod(Cards_Stack2) - 360;
out = err1^2 + err2^2;
endfunction
PopSize = 100;
Proba_cross = 0.7;
Proba_mut = 0.1;
NbGen = 10;
NbCouples = 110;
Log = %T;
ga_params = init_param();
// Parameters to control the initial population.
//ga_params = add_param(ga_params,"dimension",1);
[pop_opt, fobj_pop_opt] = ..
optim_ga(objectivefunction, PopSize, NbGen, Proba_mut, Proba_cross, Log,
ga_params);
// Display basic statistics
// min, mean and max function values of the population.
disp([min(fobj_pop_opt) mean(fobj_pop_opt) max(fobj_pop_opt)])
// Get the best x (i.e. the one which achieves the minimum function value)
[fmin ,k] = min(fobj_pop_opt);
xmin = pop_opt(k);
// Get the worst x
[fmax ,k] = max(fobj_pop_opt);
xmax = pop_opt(k);
--
View this message in context: http://mailinglists.scilab.org/Genetic-Algorithm-GA-in-Scilab-Retrieve-the-final-solution-tp4030721.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
More information about the users
mailing list