-
Notifications
You must be signed in to change notification settings - Fork 0
/
Experimento1_1outlier.m
103 lines (89 loc) · 2.3 KB
/
Experimento1_1outlier.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
fator=1 # [RA:1; RAP:2]
pesos=1 # [PUnit:1; PIV:2]
for s=1:4
#rand("state",[4]);randn("state",[4]);
if s==1
ini_int_erro=3; fim_int_erro=6;
elseif s==2
ini_int_erro=6; fim_int_erro=12;
elseif s==3
ini_int_erro=12; fim_int_erro=25;
elseif s==4
ini_int_erro=25; fim_int_erro=100;end
m=20; n=10;
qtd_itr=2000;cont_mask=0;
%qtd_itr se refere aos cenarios sem outliers. para cada um deles, serão 100 cenarios com outliers.
%assim, a qtd de iteracoes serah qtd_itr*100
A=[1 0 0 0 0 0 0 0 0 0;
-1 0 0 0 0 0 0 0 0 1;
0 0 0 0 0 1 0 0 0 -1;
0 0 0 0 0 1 -1 0 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 -1 1 0 0;
0 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 1 -1 0;
-1 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 1 -1;
0 0 0 0 0 -1 0 0 1 0;
0 0 0 0 1 0 0 0 0 -1;
-1 1 0 0 0 0 0 0 0 0;
0 -1 1 0 0 0 0 0 0 0;
0 0 -1 1 0 0 0 0 0 0;
0 0 0 -1 1 0 0 0 0 0;
0 0 0 0 1 -1 0 0 0 0;
-1 0 1 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 -1;
0 1 0 0 0 0 0 0 0 -1];
I = eye(m);
A1 = [A -A -I I];
d=[49 41 38 34 22 13 23 48 15 24 62 49 35 43 20 28 19 39 27 21];
dp=1.0.*sqrt(d);
p=dp.^(-2);
c1=zeros(1,2*n);
if pesos==1
p=ones(1,m);end
c = cat(2,c1,p,p);
ctype=[];
for i=1:m
ctype = [ctype, "S"];
end
vartype=[];
for i=1:(2*(n+m))
vartype = [vartype, "C"];
end
param.dual=1;
param.lpsolver=1;
for q=1:qtd_itr
#Entrada L (rede perfeita) e simulaçoes em L
L=[163854.9;6446.2;57037.0;126209.5;101128.6;296885.8;398014.4;60449.1;173710.4;167264.2;
110227.2;155928.2;52875.0;62904.2;3889.5;42705.7;98891.2;115779.2;113222.5;46428.8];
for z=1:m
do a=randn(1);
until (a<=3)
Laleat(z,1)=L(z)+dp(z)*a;
end
for k=1:100
Lgross=Laleat;
j=randi([1 m]);
choice=randi([-1 0]);
if choice==0
choice=1;end
Lgross(j)=L(j)+choice*dp(j)*(ini_int_erro+(fim_int_erro-ini_int_erro)*rand(1));
[xopt, fopt, erro, extra] = glpk (c, A1, Lgross, lb=[], ub=[], ctype, vartype, s=1, param);
for i=1:m
v(i)=abs(xopt(2*n+i)-xopt(2*n+i+m));
pv(i)=p(i)*v(i);
end
for i=1:m
if fator==1
Y(i)=v(i);
elseif fator==2
Y(i)=pv(i);end
end
if max(Y)!=Y(j)
cont_mask=cont_mask+1;end
end;
end
ini_int_erro
PPCOMR=(1-(cont_mask/200000))*100
end