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