Please help me to using genetic algorithm

조회 수: 1 (최근 30일)
S AsZ
S AsZ 2019년 10월 20일
편집: S AsZ 2019년 11월 29일
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
Stephan
Stephan 2019년 10월 20일
please post code not pictures of code
S AsZ
S AsZ 2019년 10월 21일
Can anyone help me?
How can I solve this problem with Genetic Algorithm?

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2019년 10월 21일
편집: Matt J 2019년 10월 21일
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
S AsZ
S AsZ 2019년 11월 29일
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 2019년 11월 29일
편집: S AsZ 2019년 11월 29일
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.
????????

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by