[Scilab-users] Using Scilab Genetic Algorithm to solve Simple Card Problem

tanthiamhuat tanthiamhuat at yahoo.com
Wed Jun 11 07:35:55 CEST 2014


managed to write a objective function for this GA problem. How do I get the
final solution for Card_Stack1 and Card_Stack2? which variables are they
stored in?

clear;clc;clf
//function y=f(x)
//  y = sum(x.^2)
//endfunction
function out = objectivefunction(AllCards)
    AllCards = 1:1:10;
    Random_10 = grand(1, "prm", (1:10)')'  // random unique number 1 to 10
    Cards_Stack1 = AllCards(Random_10(1:5))   
    Cards_Stack2 = AllCards(Random_10(6:10))    
    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/Using-Scilab-Genetic-Algorithm-to-solve-Simple-Card-Problem-tp4030679p4030713.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list