Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Unable to execute GA optimisation algorithm due to Objective Function

1 vue (au cours des 30 derniers jours)
Ryan Smith
Ryan Smith le 18 Nov 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Walter Roberson
Walter Roberson le 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
Rena Berman le 20 Jan 2017
(Answers Dev) Restored Question.

Réponses (1)

Brendan Hamm
Brendan Hamm le 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 .

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by