A very simple question for GA
조회 수: 2 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!