-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_continousmerit.m
139 lines (93 loc) · 4.02 KB
/
update_continousmerit.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function [meritfxn,oldptsx,oldptsobj,oldptscon,learned, objImprovement,conImprovement]=update_continousmerit(oldptsx,oldptsobj,oldptscon,xfound, objfound,confound, UB,LB,tol,maxzones, Meritinit)
for ag=1:numel(oldptsx)
learned(ag)=0;
objImprovementz(ag)=0;
conImprovementz(ag)=0;
conImprovement(ag)=0;
objImprovement(ag)=0;
ptsx=oldptsx{ag};
ptsobj=oldptsobj{ag};
ptscon=oldptscon{ag};
zones(ag)=max(4,min(maxzones(ag),round(numel(ptsx)/10)));
zone{ag}=linspace(LB(ag),UB(ag),zones(ag));
for z=1:zones(ag)-1
zonepts=(zone{ag}(z)<ptsx & ptsx<=zone{ag}(z+1));
xpts=ptsx.*zonepts;
objpts=ptsobj.*zonepts;
conpts=ptscon.*zonepts;
if any(xpts~=0)
zptsx=xpts(xpts~=0);
zptsobj=objpts(xpts~=0);
zptscon=conpts(xpts~=0);
minconzone=min(zptscon);
mostfeaspts=minconzone==zptscon;
mostfeasx=zptsx(mostfeaspts);
mostfeasobj=zptsobj(mostfeaspts);
%best point is the most feasible
zonerepcon(z)=minconzone;
%that has the best objective value
[zonerepobj(z), loc]=min(mostfeasobj);
%
zonerepx(z)=mostfeasx(loc);
else
zonerepobj(z)=Meritinit;
zonerepcon(z)=Meritinit;
zonerepx(z)=(zone{ag}(z+1)-zone{ag}(z))/2+zone{ag}(z);
end
% learned if better than other points in the zone
if (zone{ag}(z)<xfound(ag) && xfound(ag)<=zone{ag}(z+1))
if confound(ag)<zonerepcon(z)
conImprovementz(ag)=zonerepcon(z)-confound(ag);
if objfound(ag)<zonerepobj(z)
objImprovementz(ag)=zonerepobj(z)-objfound(ag);
else
objImprovementz(ag)=0;
end
learned(ag)=1;
zonerepx(z)=xfound(ag);
zonerepobj(z)=objfound(ag);
zonerepcon(z)=confound(ag);
elseif confound(ag)==zonerepcon(z)
if objfound(ag)<zonerepobj(z)
conImprovementz(ag)=0;
objImprovementz(ag)=zonerepobj(z)-objfound(ag);
learned(ag)=1;
zonerepx(z)=xfound(ag);
zonerepobj(z)=objfound(ag);
zonerepcon(z)=confound(ag);
else
conImprovementz(ag)=0;
objImprovementz(ag)=0;
end
else
conImprovementz(ag)=0;
objImprovementz(ag)=0;
end
else
conImprovementz(ag)=0;
objImprovementz(ag)=0;
end
conImprovement(ag)=conImprovement(ag)+conImprovementz(ag);
objImprovement(ag)=objImprovement(ag)+objImprovementz(ag);
end
xcell{ag}=[LB(ag),zonerepx,UB(ag)+0.0001];
ycell{ag}=[mean([zonerepobj(1),zonerepobj(2)]),zonerepobj,mean([zonerepobj(end),zonerepobj(end-1)])];
zcell{ag}=[mean([zonerepcon(1),zonerepcon(2)]),zonerepcon,mean([zonerepcon(end),zonerepcon(end-1)])];
%create interpolation of merit of each
xx{ag}=xcell{ag}(1):tol(ag):xcell{ag}(end);
%could use interp1 for linear interpolation...
%or spline for spline
%pchip seems to make sense
yy{ag}=pchip(xcell{ag},ycell{ag},xx{ag});
zz{ag}=pchip(xcell{ag},zcell{ag},xx{ag});
%figure(ag)
%plot(xx{ag},yy{ag},ptsx,ptsy,'o');
%add found point to cell
oldptsx{ag}=[oldptsx{ag},xfound(ag)];
oldptsobj{ag}=[oldptsobj{ag},objfound(ag)];
oldptscon{ag}=[oldptscon{ag},confound(ag)];
%create merit function (for use in action selection)
meritfxn{ag}=[xx{ag};yy{ag}; zz{ag}];
clear zonerepx zonerepobj zonerepcon
end
end