Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Unable to execute GA optimisation algorithm due to Objective Function

조회 수: 1 (최근 30일)
Ryan Smith
Ryan Smith 2016년 11월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Walter Roberson
Walter Roberson 2016년 11월 18일
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 2017년 1월 20일
(Answers Dev) Restored Question.

답변 (1개)

Brendan Hamm
Brendan Hamm 2016년 11월 18일
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 .

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by