A very simple question for GA
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear all, I have a very simple question as follows, I just want to clarify if I am doing right or not:
I have a function named: function [wRemAlo] = Resource allocation (x)
x: have three possible values which I am entering in command line before running the function e.g. I put "x = [90,20,0,10]" and
After receiving the input values of x, my function allocate resources to 16 variables v (v(1) to v(16)) and return the single variable of "wRemAlo".
I want ga to minimise the output of the function: "wRemAlo"
My function is working correct and return the correct value for "wRemAlo" whenever I run it.
I put constraints as follows to put restrictions on ga decisions and pass the handle for the function to ga solver as follows:
ObjectiveFunction = @ResourceAllocation;
nvars = 16; A=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ; 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ; 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 ; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ; 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ; 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 ; 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0 ; 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
b=[105;90;20;0;10;0;0;45;60]; LB = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
[v,fval] = ga(ObjectiveFunction,nvars,A,b,[],[],LB,[],[])
The fval value returns after running ga dose not make any sense! Should this value be as same as the value for the function output: "wRemAlo"
Please somebody tell me if I am doing correct or not??
regs, Melody
0 comentarios
Respuesta aceptada
Seth DeLand
el 27 de Jun. de 2012
It looks like there is an issue with the way your decision variables are defined. The input to the objective function (which is currently x), should be a vector of the decision variables. If the v's are your decision variables that you want to optimize, then the objective function should look like
[wRemAlo] = ResourceAllocation(v)
If you also need to use the values in x inside ResourceAllocation, there's an example here that shows how to pass additional arguments (in the minimizing using additional arguments section).
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Quadratic Programming and Cone Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!