-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
84 lines (67 loc) · 2.12 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function f = main
clear
clc;
answer_using_genetic_algorithm=zeros(10,7);
for K = (300:1:300)
% options = gaoptimset('OutputFcns',@calling,'PopulationSize',[K]);
FitnessFunction = @(x) func(x);
options = gaoptimset('Vectorized','on','PopulationSize',[105],'Generation',[]);
global a1;
%[answer_using_genetic_algorithm,val]= ga(@func, 7, [], [],[],[],[1,2,1,2,1,2,1],[3,5,2,3,4,2,4],[],[1,1,2,4,5,6,7],options);
answer_using_genetic_algorithm(K,:)= ga(@func, 7, [], [],[],[],[1,1,1,1,1,1,1],[3,5,3,3,4,3,4],[],[1,2,3,4,5,6,7],options);
val(K,1)=func(answer_using_genetic_algorithm(K,:));
end
[answer_using_genetic_algorithm,val]
end
function a= calling(Population)
global a1;
load data;
for i=(1:1:size(Population,1));
c(i)=B(Population(i,1),2,1)+B(Population(i,2),2,2)+B(Population(i,3),2,3)+B(Population(i,4),2,4)++B(Population(i,5),2,5)+B(Population(i,6),2,6)+B(Population(i,7),2,7);
t(1)=B(Population(i,1),1,1)+B(Population(i,2),1,2)+B(Population(i,5),1,5)+B(Population(i,7),1,7);
t(2)=B(Population(i,1),1,1)+B(Population(i,3),1,3)+B(Population(i,5),1,5)+B(Population(i,7),1,7);
t(3)=B(Population(i,1),1,1)+B(Population(i,4),1,4)+B(Population(i,6),1,6)+B(Population(i,7),1,7);
d(i)=max([t(1),t(2),t(3)]);
end
Population;
a1= [max(c),min(c),max(d),min(d)] ;
a=a1;
%a1= [max(i,c),min(c),max(i,d),min(d)] ;
end
function score = func(x)
load data;
x
popsize=size(x,1);
if(popsize~=1)
calling(x);
end
global a1;
for i =(1:1:popsize)
c =B(x(i,1),2,1)+B(x(i,2),2,2)+B(x(i,3),2,3)+B(x(i,4),2,4)++B(x(i,5),2,5)+B(x(i,6),2,6)+B(x(i,7),2,7)
t(1)=B(x(i,1),1,1)+B(x(i,2),1,2)+B(x(i,5),1,5)+B(x(i,7),1,7);
t(2)=B(x(i,1),1,1)+B(x(i,3),1,3)+B(x(i,5),1,5)+B(x(i,7),1,7);
t(3)=B(x(i,1),1,1)+B(x(i,4),1,4)+B(x(i,6),1,6)+B(x(i,7),1,7);
d=max(t)
if(a1(1)==a1(2) && a1(3)==a1(4))
wc=.5;
wt=.5;
end
if(a1(1)~=a1(2) && a1(3)~=a1(4))
vc=a1(1)/(a1(1)-a1(2));
vt=a1(3)/(a1(3)-a1(4));
v=vc+vt;
wc=vc/v;
wt=vt/v;
end
if(a1(1)~=a1(2) && a1(3)==a1(4))
wc=0.1;
wt=0.9;
end
if(a1(3)~=a1(4) && a1(1)==a1(2))
wc=0.9;
wt=0.1;
end
score(i,1)=1*(wc*(a1(1)-c)/(a1(1)-a1(2)+1)+wt*(a1(3)-d)/(a1(3)-a1(4)+1));
end
a1
end