Please help me to using genetic algorithm

I write this code but I want to solve this problem with 'ga' not with 'intlinprog' solver!
Can anyone guide me?
costprob = optimproblem;
% Indices
k = 15;
j = 2;
f = 10;
l = 5;
r0 = 6;
r = 6;
% Parameters
cr0 = 0 + 1*rand(1,r0);
dr0f = 0 + 1*rand(r0,f);
csl = 0 + 1*rand(1,l);
DE = 200 + 100*rand(1,1);
csur0f = 2000 + 1000*rand(r0,f);
ctl = 1000 + 1000*rand(1,l);
cvl = 10 + 10*rand(1,l);
cpjk = 0 + 1*rand(j,k);
corj = 0 + 1*rand(r,j);
pr0f = 0 + 1*rand(r0,f);
vjk = 0 + 1*rand(j,k);
cvjrk = 0 + 1*rand(j,r,k);
M = 10000000000000;
% Variables
xl = optimvar('xl',1,l,'LowerBound',0);
yr0f = optimvar('yr0f',r0,f,'Type','integer','LowerBound',0,'UpperBound',1);
xx1r0f = optimvar('xx1r0f',r0,f,'LowerBound',0);
xx2r0f = optimvar('xx2r0f',r0,f,'LowerBound',0);
yjk1 = optimvar('yjk1',j,k,'Type','integer','LowerBound',0,'UpperBound',1);
yl2 = optimvar('yl2',1,l,'Type','integer','LowerBound',0,'UpperBound',1);
zjkr = optimvar('zjkr',j,k,r,'LowerBound',0);
wrj = optimvar('wrj',r,j,'LowerBound',0);
% Objective function
objfun1 = sum(sum(dr0f.*xx1r0f,2).*cr0',1);
objfun2 = sum(sum(corj.*wrj,2),1);
objfun3 = sum(sum(pr0f.*xx1r0f,2),1);
objfun4 = sum(sum(cpjk.*yjk1,2),1);
objfun5 = sum(csl.*xl,2);
costprob.Objective = objfun1 + objfun2 + objfun3 + objfun4 + objfun5;
% Constraints
cons1 = sum(xl,2) >= DE;
cons2 = sum(xl,2)*ones(j,1,r) == sum(zjkr,2);
cons3 = xx1r0f <= csur0f.*yr0f;
cons4 = xl <= ctl.*yl2;
cons5 = xl >= cvl.*yl2;
cons6 = sum(yjk1,2) == ones(j,1);
cons7 = squeeze(sum(zjkr,3)) <= M*yjk1;
cons8 = (1-dr0f).*xx1r0f == xx2r0f;
costprob.Constraints.cons1 = cons1;
costprob.Constraints.cons2 = cons2;
costprob.Constraints.cons3 = cons3;
costprob.Constraints.cons4 = cons4;
costprob.Constraints.cons5 = cons5;
costprob.Constraints.cons6 = cons6;
costprob.Constraints.cons7 = cons7;
costprob.Constraints.cons8 = cons8;

2 Kommentare

Stephan
Stephan am 20 Okt. 2019
please post code not pictures of code
S AsZ
S AsZ am 21 Okt. 2019
Can anyone help me?
How can I solve this problem with Genetic Algorithm?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Matt J
Matt J am 21 Okt. 2019
Bearbeitet: Matt J am 21 Okt. 2019

1 Stimme

You can use prob2struct to obtain most of your problem parameters in solver form,
problem=prob2struct(costprob);
problem=rmfield(problem,'solver');
problem.nvars=numel(problem.lb);
problem.fitnessfcn=@(x) dot(problem.f,x);
x=ga(problem);
However your problem, as currently formulated, has both integer and equality constraints, which ga cannot handle. See here, for guidelines on how to rewrite the problem without equality constraints:

5 Kommentare

S AsZ
S AsZ am 21 Okt. 2019
Thank you very much for your good help ?
S AsZ
S AsZ am 23 Okt. 2019
Bearbeitet: S AsZ am 23 Okt. 2019
Excuse me I faced with another problem. I put 'problem.Objective' instead of 'problem.f' in your suggested code:
problem.fitnessfcn = @(x) dot(problem.Objective,x);
But I faced with this error:
Reference to non-existent field 'Objective'.
Can you guide me how can I resolve this error?
Also I have another question about your suggested code. Should I exactly put the phrase 'x' in your suggested code or put my decision variables instead of?
Matt J
Matt J am 23 Okt. 2019
Bearbeitet: Matt J am 23 Okt. 2019
My code as originally posted should have worked, assuming you removed either the equality or integer constraints from the problem.
S AsZ
S AsZ am 29 Nov. 2019
Excuse me
I want to add this constraint to my model but I don't know how can I write the code of this constraint.
Can you help me please? ?
k = 15;
j = 2;
r = 6;
rprim = r;
vjk = 1 + 3*rand(j,k);
ujrrprim = 1 + 10*rand(j,r,rprim);
zjkr = optimvar('zjkr',j,k,r,'LowerBound',0);
I mean rprim is r'.
S AsZ
S AsZ am 29 Nov. 2019
Bearbeitet: S AsZ am 29 Nov. 2019
Excuse me so much I have an author question again:
How can I write multi objective functions with optimproblem format? My mean is using problem based method not using solver based method.
????????

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2019b

Gefragt:

am 20 Okt. 2019

Bearbeitet:

am 29 Nov. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by