Borrar filtros
Borrar filtros

Please help me to using genetic algorithm

1 visualización (últimos 30 días)
S AsZ
S AsZ el 20 de Oct. de 2019
Editada: S AsZ el 29 de Nov. de 2019
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 comentarios
Stephan
Stephan el 20 de Oct. de 2019
please post code not pictures of code
S AsZ
S AsZ el 21 de Oct. de 2019
Can anyone help me?
How can I solve this problem with Genetic Algorithm?

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 21 de Oct. de 2019
Editada: Matt J el 21 de Oct. de 2019
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 comentarios
S AsZ
S AsZ el 29 de Nov. de 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 el 29 de Nov. de 2019
Editada: S AsZ el 29 de Nov. de 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.
????????

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by