A very simple question for GA
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Seth DeLand
2012-6-27
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 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!