Unable to execute GA optimisation algorithm due to Objective Function
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
I am currently trying to optimise resource allocation using GA. Pretty new to Matlab but I need to have this working.
Current code I am using:
x4= 5
x5= 1
x6= 6
x7= 2
x8= 15
w1= 6
w2 = 22
w3 = 3
w4 = 24
LB = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
b=[w1+w2+w3+w4;x1;x2;x3;x4;x5;x6;x7;x8;w1;w2;w3;w4];
A=[***own constraints in here***];
nvars = 32;
opts = -gaoptimset (opts,'TolFun',1e-12,'PopulationSize',100);
ObjectiveFunction = @(v) ResourceAllocation (v,x1,x2,x3,x4,x5,x6,x7,x8,w1,w2,w3,w4);
[v,fval] = ga (ObjectiveFunction,nvars,A,b,[],[],LB,[],[],opts).
Errors I am currently getting:
Undefined function or variable 'ResourceAllocation'.
Error in @(v)ResourceAllocation(v,x1,x2,x3,x4,x5,x6,x7,x8,w1,w2,w3,w4)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Please help
2 Commenti
Walter Roberson
il 18 Nov 2016
Note: your line
opts = -gaoptimset (opts,'TolFun',1e-12,'PopulationSize',100);
cannot work, as it attempts to do a unary minus on the struct that results from gaoptimset
Your line
[v,fval] = ga (ObjectiveFunction,nvars,A,b,[],[],LB,[],[],opts).
needs to have the period changed to semi-colon
Rena Berman
il 20 Gen 2017
(Answers Dev) Restored Question.
Risposte (1)
Brendan Hamm
il 18 Nov 2016
MATLAB cannot find the file where you define your objective function evaluation. If you type:
which ResourceAllocation
MATLAB will tell you which version of the file it finds (if any). IF is not returning to you a location of the file, you need to make sure that this function file is on the MATLAB search path .
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!