How to initialize non linear constraints in gamultiobj with integer only variables and array based constraints?

2 views (last 30 days)
I have tried including non linear constraints function in gamultiobj solver with custom selection, crossover and mutation function to use get population of only integer type.
i tried running this code, and it showed no error. But the solutions does not correspond or satisfy the non linear constraints mentioned in "constrF" file. File code is also mentioned next.
options = gaoptimset('PopulationSize',populationSize,...
'CreationFcn', @int_pop,...
'MutationFcn', @int_mutation,...
'CrossoverFcn',@int_crossoverarithmetic,...
'StallGenLimit', stallGenLimit, 'SelectionFcn',@selectiontournament ...
,'Generations', generations,...
'PopulationSize',populationSize,...
'PopInitRange', Bound, 'PlotFcn',{@gaplotpareto,@gaplotdistance});
options.DistanceMeasureFcn = {@distancecrowding,'genotype'};
options = gaoptimset(options,'ParetoFraction',0.5);
options.FunctionTolerance= {0.003};
options.nonlcon={@constrF}; %Non linear constraint file
[x1, f1, exitflag1, output1, population1, score1] = gamultiobj(fitnessFunction,...
numberOfVariables, [],[], [], [], lb, ub,options);
constrF file code
function [c,ceq]= mycon(x) %Non linear constraint file
c=zeros(1,2);
p=[80,75,70,77,60,76,50,48,44,21,27,10,0];
c(1)= -0.9(-p(x(1))-p(x(2))-p(x(3))-p(x(4))-p(x(5))-p(x(6))-p(x(7))-p(x(8))-p(x(9))-p(x(10))...
-p(x(11))-p(x(12))-p(x(13))-p(x(14))-p(x(15))-p(x(16))-p(x(17))-p(x(18))-p(x(19))-p(x(20)))-100;
c(2)= -0.9(-pci(x(21))-pci(x(22))-pci(x(23)))-100;
ceq=[];
end
%constraints are not taken into consideration while run
If i try to initialize the constraints using nonlcon in the output function such as this.
options = gaoptimset('PopulationSize',populationSize,...
'CreationFcn', @int_pop,...
'MutationFcn', @int_mutation,...
'CrossoverFcn',@int_crossoverarithmetic,...
'StallGenLimit', stallGenLimit, 'SelectionFcn',@selectiontournament ...
,'Generations', generations,...
'PopulationSize',populationSize,...
'PopInitRange', Bound, 'PlotFcn',{@gaplotpareto,@gaplotdistance});
options.DistanceMeasureFcn = {@distancecrowding,'genotype'};
options = gaoptimset(options,'ParetoFraction',0.5);
options.FunctionTolerance= {0.003};
[x1, f1, exitflag1, output1, population1, score1] = gamultiobj(fitnessFunction,...
numberOfVariables, [],[], [], [], lb, ub,@constrF,options); %nonlinear constraint mentioned inside
Then as error is displayed that Array indices should be positive integer or logical value. I guess that is because gamultiobj originally took decimal point value which cannot initialize array in constraints. The integer only population is formed by calling "options" feature after nonlcon function in above code.
Can anyone help me out with this issue??

Answers (1)

BALAJI KARTHEEK
BALAJI KARTHEEK on 20 Apr 2020
Here, I am attaching u how to write the nonlinear constraints for ga multiobj, and more importing u have given ur nonlinear function name as mycons and ur it calling it in gamultiobj as constrF, which is wrong, u want to call it with the same function name, so in second file i am attaching how to call a nonlinear function in gamultiobj...
hope u found the answer, for any more details u can feel free to coontact me
function [c,ceq] = mycons(x,sum_dem1,ev_soc,beq,load1h,h,dis,g1,g2,g3,g4,g5,p_ch_max,bin_ev_ava)
c=[x(9)*((sign(x(9))+1)/2)-sum_dem1(1);
x(10)*((sign(x(10))+1)/2)-sum_dem1(2);
x(11)*((sign(x(11))+1)/2)-sum_dem1(3);
x(12)*((sign(x(12))+1)/2)-sum_dem1(4);
x(13)*((sign(x(13))+1)/2)-sum_dem1(5);
x(14)*((sign(x(14))+1)/2)-sum_dem1(6);
x(15)*((sign(x(15))+1)/2)-sum_dem1(7);
x(16)*((sign(x(16))+1)/2)-sum_dem1(8);
x(17)*((sign(x(17))+1)/2)-sum_dem1(9);
x(18)*((sign(x(18))+1)/2)-sum_dem1(10);
x(19)*((sign(x(19))+1)/2)-sum_dem1(11);
x(20)*((sign(x(20))+1)/2)-sum_dem1(12);
x(21)*((sign(x(21))+1)/2)-sum_dem1(13);];
ceq=[(x(9)*((sign(x(9))+1)/2)+x(10)*((sign(x(10))+1)/2)+x(11)*((sign(x(11))+1)/2)+x(12)*((sign(x(12))+1)/2)+x(13)*((sign(x(13))+1)/2)+x(14)*((sign(x(14))+1)/2)+x(15)*((sign(x(15))+1)/2)+x(16)*((sign(x(16))+1)/2)+x(17)*((sign(x(17))+1)/2)+x(18)*((sign(x(18))+1)/2)...
+x(19)*((sign(x(19))+1)/2)+x(20)*((sign(x(20))+1)/2)+x(21)*((sign(x(21))+1)/2)+x(22)*((sign(x(22))+1)/2)+x(23)*((sign(x(23))+1)/2)+x(24)*((sign(x(24))+1)/2)+x(25)*((sign(x(25))+1)/2)+x(26)*((sign(x(26))+1)/2)+x(27)*((sign(x(27))+1)/2)+x(28)*((sign(x(28))+1)/2)...
+x(29)*((sign(x(29))+1)/2)+x(30)*((sign(x(30))+1)/2)+x(31)*((sign(x(31))+1)/2)+x(32)*((sign(x(32))+1)/2)+x(33)*((sign(x(33))+1)/2)+x(34)*((sign(x(34))+1)/2)+x(35)*((sign(x(35))+1)/2)+x(36)*((sign(x(36))+1)/2)+x(37)*((sign(x(37))+1)/2)+x(38)*((sign(x(38))+1)/2)...
+x(39)*((sign(x(39))+1)/2)+x(40)*((sign(x(40))+1)/2)+x(41)*((sign(x(41))+1)/2)+x(42)*((sign(x(42))+1)/2)+x(43)*((sign(x(43))+1)/2)+x(44)*((sign(x(44))+1)/2)+x(45)*((sign(x(45))+1)/2)+x(46)*((sign(x(46))+1)/2)+x(47)*((sign(x(47))+1)/2)+x(48)*((sign(x(48))+1)/2)...
+x(49)*((sign(x(49))+1)/2)+x(50)*((sign(x(50))+1)/2)+x(51)*((sign(x(51))+1)/2)+x(52)*((sign(x(52))+1)/2)+x(53)*((sign(x(53))+1)/2)+x(54)*((sign(x(54))+1)/2)+x(55)*((sign(x(55))+1)/2)+x(56)*((sign(x(56))+1)/2)+x(57)*((sign(x(57))+1)/2)+x(58)*((sign(x(58))+1)/2)...
+x(59)*((sign(x(59))+1)/2)+x(60)*((sign(x(60))+1)/2)+x(61)*((sign(x(61))+1)/2)+x(62)*((sign(x(62))+1)/2)+x(63)*((sign(x(63))+1)/2)+x(64)*((sign(x(64))+1)/2)+x(65)*((sign(x(65))+1)/2)+x(66)*((sign(x(66))+1)/2)+x(67)*((sign(x(67))+1)/2)+x(68)*((sign(x(68))+1)/2)-x(69));
(x(9)*((sign(x(9))-1)/2)+x(10)*((sign(x(10))-1)/2)+x(11)*((sign(x(11))-1)/2)+x(12)*((sign(x(12))-1)/2)+x(13)*((sign(x(13))-1)/2)+x(14)*((sign(x(14))-1)/2)+x(15)*((sign(x(15))-1)/2)+x(16)*((sign(x(16))-1)/2)+x(17)*((sign(x(17))-1)/2)+x(18)*((sign(x(18))-1)/2)...
+x(19)*((sign(x(19))-1)/2)+x(20)*((sign(x(20))-1)/2)+x(21)*((sign(x(21))-1)/2)+x(22)*((sign(x(22))-1)/2)+x(23)*((sign(x(23))-1)/2)+x(24)*((sign(x(24))-1)/2)+x(25)*((sign(x(25))-1)/2)+x(26)*((sign(x(26))-1)/2)+x(27)*((sign(x(27))-1)/2)+x(28)*((sign(x(28))-1)/2)...
+x(29)*((sign(x(29))-1)/2)+x(30)*((sign(x(30))-1)/2)+x(31)*((sign(x(31))-1)/2)+x(32)*((sign(x(32))-1)/2)+x(33)*((sign(x(33))-1)/2)+x(34)*((sign(x(34))-1)/2)+x(35)*((sign(x(35))-1)/2)+x(36)*((sign(x(36))-1)/2)+x(37)*((sign(x(37))-1)/2)+x(38)*((sign(x(38))-1)/2)...
+x(39)*((sign(x(39))-1)/2)+x(40)*((sign(x(40))-1)/2)+x(41)*((sign(x(41))-1)/2)+x(42)*((sign(x(42))-1)/2)+x(43)*((sign(x(43))-1)/2)+x(44)*((sign(x(44))-1)/2)+x(45)*((sign(x(45))-1)/2)+x(46)*((sign(x(46))-1)/2)+x(47)*((sign(x(47))-1)/2)+x(48)*((sign(x(48))-1)/2)...
+x(49)*((sign(x(49))-1)/2)+x(50)*((sign(x(50))-1)/2)+x(51)*((sign(x(51))-1)/2)+x(52)*((sign(x(52))-1)/2)+x(53)*((sign(x(53))-1)/2)+x(54)*((sign(x(54))-1)/2)+x(55)*((sign(x(55))-1)/2)+x(56)*((sign(x(56))-1)/2)+x(57)*((sign(x(57))-1)/2)+x(58)*((sign(x(58))-1)/2)...
+x(59)*((sign(x(59))-1)/2)+x(60)*((sign(x(60))-1)/2)+x(61)*((sign(x(61))-1)/2)+x(62)*((sign(x(62))-1)/2)+x(63)*((sign(x(63))-1)/2)+x(64)*((sign(x(64))-1)/2)+x(65)*((sign(x(65))-1)/2)+x(66)*((sign(x(66))-1)/2)+x(67)*((sign(x(67))-1)/2)+x(68)*((sign(x(68))-1)/2)-x(70));
(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)-x(71)-x(72)-x(73)-x(69)+x(70)-load1h);
abs(x(1)+x(2)+x(3)+x(4)+x(5)+x(70)-x(74)*(g1(h)+g2(h)+g3(h)+g4(h)+g5(h)+sum(dis(:,h))*p_ch_max));
((x(9))*((sign(x(9))+1)/2)*beq(1)-sum_dem1(1)*beq(1));
((x(10))*((sign(x(10))+1)/2)*beq(2)-sum_dem1(2)*beq(2));];
constraints1=@(x)mycons(x)
[x1, f1, exitflag1, output1, population1, score1] = gamultiobj(fitnessFunction,...
numberOfVariables, [],[], [], [], lb, ub,constraints1,options);
  3 Comments
BALAJI KARTHEEK
BALAJI KARTHEEK on 21 Apr 2020
I have given just an example, and dont worry abt sum_dem1 and etc,these are related to my project. Here i modified ur constraints file, i think this can help u out
function [c,ceq]= mycon(x) %Non linear constraint file
c=zeros(1,2);
p=[80,75,70,77,60,76,50,48,44,21,27,10,0];
c=[-0.9*(-p(x(1))-p(x(2))-p(x(3))-p(x(4))-p(x(5))-p(x(6))-p(x(7))-p(x(8))-p(x(9))-p(x(10))...
-p(x(11))-p(x(12))-p(x(13))-p(x(14))-p(x(15))-p(x(16))-p(x(17))-p(x(18))-p(x(19))-p(x(20)))-100;
-0.9*(-p(x(21))-p(x(22))-p(x(23)))
-100;];
ceq=[];
end
BALAJI KARTHEEK
BALAJI KARTHEEK on 21 Apr 2020
Edited: BALAJI KARTHEEK on 21 Apr 2020
Bro , The approuch made made by you is wrong. if u give command as options.nonlcon={@mycon}, then options.nonlcon will store it as a cell. To check this thing please go to workspace and open the options struct and then go inside the nonlcon it will just show @mycon. In actual, it should ur constraints.. So gamultiobj is just bypassing the constraints given by you. Thats the reason, why you are not getting any error.. In matlab In gamultiobj, interger constraints are not possible. But it is possible with normal ga function, In order to use normal ga for multiobjective optimization, we want to write the objective function to form the single objective...
for example if i have two functions f1 and f2
in which f1 must be minimized and f2 must be maximized , so in normal, ga will minimize the objective function, so we want to formulate the overall objective function as f1-f2 , which also do the same thing..so i recommand u to GA to apply integer constraints instead of gamultiobj where it is not possible to apply the integer constraints.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!