0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 function [xp_h, lambda_h, gamma_xh, gamma_lh, iter, th] = DynamicSeq_DS_function(A, b, Q_glgx, R_glgx, y, w, xp, lame, gamma_x, gamma_lambda, pk, ak, tau, maxiter)
0035
0036 t0 = cputime;
0037 N = length(xp);
0038 e0 = 0;
0039 gamma_xh = gamma_x;
0040 gamma_lh = gamma_lambda;
0041 xp_h = xp;
0042 lambda_h = lame;
0043 idelta = [];
0044 itheta = [];
0045 epsilon = 0;
0046 pk_old = pk;
0047 pk_old(gamma_lh) = sign(pk_old(gamma_lh))*tau;
0048 ak_old = ak;
0049 ak_old(gamma_xh) = sign(ak_old(gamma_xh));
0050 out_lambda = [];
0051 out_x = [];
0052 in_x = [];
0053 in_lambda = [];
0054
0055 iter = 0;
0056
0057 while iter < maxiter
0058 iter = iter+1;
0059
0060 e0h = e0;
0061
0062
0063
0064 dx = b(:,gamma_lh)'*(b(:,gamma_xh)*xp_h(gamma_xh)-w);
0065
0066
0067
0068
0069
0070
0071 iAb_vec = R_glgx\(Q_glgx'*b(:,gamma_lh)');
0072 ux = (b(:,gamma_xh)*iAb_vec);
0073 delx = -R_glgx\(Q_glgx'*dx);
0074
0075 pk = pk_old;
0076 dk = b'*(b*xp_h-w)+(A'*(A(:,gamma_xh)*delx)+e0h*b'*(b(:,gamma_xh)*delx));
0077 delx_vec = zeros(N,1);
0078 delx_vec(gamma_xh) = delx;
0079
0080 dl = b(:,gamma_xh)'*(b(:,gamma_lh)*lambda_h(gamma_lh));
0081 ul = ux;
0082
0083
0084
0085
0086
0087 del_lam = -Q_glgx*(R_glgx'\dl);
0088
0089 ak = ak_old;
0090 bk = b'*(b*lambda_h)+(A'*(A(:,gamma_lh)*del_lam)+e0h*b'*(b(:,gamma_lh)*del_lam));
0091 del_lam_vec = zeros(N,1);
0092 del_lam_vec(gamma_lh) = del_lam;
0093
0094
0095 temp_gamma = zeros(N,1);
0096 temp_gamma(gamma_lh) = gamma_lh;
0097 gamma_lc = find([1:N]' ~= temp_gamma);
0098
0099 d_constr1 = (tau-pk(gamma_lc))./dk(gamma_lc);
0100 d_constr2 = (tau+pk(gamma_lc))./-dk(gamma_lc);
0101 d_constr3 = (-xp_h(gamma_xh)./delx_vec(gamma_xh));
0102 idelta_1 = find(d_constr1>2*eps);
0103 idelta_2 = find(d_constr2>2*eps);
0104 idelta_3 = find(d_constr3>2*eps);
0105 delta1 = min(d_constr1(idelta_1));
0106 delta2 = min(d_constr2(idelta_2));
0107 delta3 = min(d_constr3(idelta_3));
0108 if isempty(delta1)
0109 delta1 = inf;
0110 end
0111 if isempty(delta2)
0112 delta2 = inf;
0113 end
0114 if isempty(delta3)
0115 delta3 = inf;
0116 end
0117
0118 if delta1>delta2
0119 delta = delta2;
0120 idelta = gamma_lc(find(d_constr2==delta2));
0121 flag_delta = 1;
0122 else
0123 delta = delta1;
0124 idelta = gamma_lc(find(d_constr1==delta1));
0125 flag_delta = 1;
0126 end
0127 if delta3 < delta
0128 delta = delta3;
0129 idelta = gamma_xh(find(d_constr3==delta3));
0130 flag_delta = 0;
0131 end
0132
0133
0134 temp_gamma = zeros(N,1);
0135 temp_gamma(gamma_xh) = gamma_xh;
0136 gamma_xc = find([1:N]' ~= temp_gamma);
0137
0138 b_constr1 = (1-ak(gamma_xc))./bk(gamma_xc);
0139 b_constr2 = (1+ak(gamma_xc))./-bk(gamma_xc);
0140 b_constr3 = (-lambda_h(gamma_lh)./del_lam_vec(gamma_lh));
0141 itheta_1 = find(b_constr1>2*eps);
0142 itheta_2 = find(b_constr2>2*eps);
0143 itheta_3 = find(b_constr3>2*eps);
0144 theta1 = min(b_constr1(itheta_1));
0145 theta2 = min(b_constr2(itheta_2));
0146 theta3 = min(b_constr3(itheta_3));
0147 if isempty(theta1)
0148 theta1 = inf;
0149 end
0150 if isempty(theta2)
0151 theta2 = inf;
0152 end
0153 if isempty(theta3)
0154 theta3 = inf;
0155 end
0156
0157 if theta1>theta2
0158 theta = theta2;
0159 itheta = gamma_xc(find(b_constr2==theta2));
0160 flag_theta = 1;
0161 else
0162 theta = theta1;
0163 itheta = gamma_xc(find(b_constr1==theta1));
0164 flag_theta = 1;
0165 end
0166 if theta3 < theta
0167 theta = theta3;
0168 itheta = gamma_lh(find(b_constr3==theta3));
0169 flag_theta = 0;
0170 end
0171
0172 if 1-theta*ul <=0 & ul >0
0173 stp = 1;
0174 end
0175 if 1-delta*ux <=0 & ux >0
0176 stp = 1;
0177 end
0178
0179 epsilon_x = (delta+e0-e0h*delta*ux)/(1-delta*ux);
0180 epsilon_l = (theta+e0-e0h*theta*ul)/(1-theta*ul);
0181
0182 dteta = min(delta, theta);
0183
0184 if epsilon_l <0
0185 epsilon_l = inf;
0186 end
0187 if epsilon_x < 0
0188 epsilon_x = inf;
0189 end
0190
0191 epsilon = min(epsilon_x,epsilon_l);
0192
0193 if epsilon >=1
0194 dteta_end = ((1-e0)/(1+ux*(1-e0h)));
0195 xp_h = xp_h + dteta_end*delx_vec;
0196 lambda_h = lambda_h + dteta_end*del_lam_vec;
0197 break;
0198 end
0199
0200 gamma_xh_old = gamma_xh;
0201 gamma_lh_old = gamma_lh;
0202 xp_h_old = xp_h;
0203 xp_h = xp_h+dteta*delx_vec;
0204 lambda_h_old = lambda_h;
0205 lambda_h = lambda_h+dteta*del_lam_vec;
0206
0207 pk_t = pk+dteta*dk;
0208 ak_t = ak+dteta*bk;
0209
0210 in_lambda = [];
0211 out_lambda = [];
0212 in_x = [];
0213 out_x = [];
0214 if epsilon_x > epsilon_l
0215
0216
0217
0218 if flag_theta == 1
0219
0220
0221 new_x = itheta;
0222 gamma_xh_app = [gamma_xh; new_x];
0223 in_x = itheta;
0224
0225
0226
0227 Q0 = Q_glgx;
0228 R0 = R_glgx;
0229 [Q_glgx R_glgx] = qrupdate(Q0, R0, (epsilon-e0)*b(:,gamma_lh)',b(:,gamma_xh)');
0230 else
0231
0232
0233 outl_index = find(gamma_lh == itheta);
0234
0235 gamma_lh = gamma_lh([1:outl_index-1 outl_index+1:length(gamma_lh)]);
0236
0237
0238 outx_index = length(gamma_xh);
0239 new_x = gamma_xh(outx_index);
0240
0241 gamma_xh = gamma_xh([1:outx_index-1 outx_index+1:length(gamma_xh)]);
0242 gamma_xh_app = [gamma_xh; new_x];
0243
0244 lambda_h(itheta) = 0;
0245 out_lambda = itheta;
0246
0247
0248
0249 Q0 = Q_glgx;
0250 R0 = R_glgx;
0251 [Q1 R1] = qrupdate(Q0, R0, (epsilon-e0)*b(:,gamma_lh_old)',b(:,gamma_xh_old)');
0252 loc_vector = zeros(length(gamma_lh_old),1);
0253 loc_vector(outl_index) = 1;
0254 rep_row = (A(:,out_lambda)'*A(:,gamma_xh_old)+epsilon*b(:,out_lambda)'*b(:,gamma_xh_old))';
0255 [Q2t R2t] = qrupdate(Q1, R1, loc_vector,-rep_row);
0256 loc_vector = zeros(length(gamma_xh_old),1);
0257 loc_vector(outx_index) = 1;
0258 rep_vec = (A(:,gamma_lh_old)'*A(:,new_x)+epsilon*b(:,gamma_lh_old)'*b(:,new_x));
0259 rep_vec(outl_index) = 1;
0260 [Q3t R3t] = qrupdate(Q2t, R2t, -rep_vec, loc_vector);
0261 Q_glgx = Q3t([1:outl_index-1 outl_index+1:length(gamma_lh_old)],[1:outx_index-1 outx_index+1:length(gamma_xh_old)]);
0262 R_glgx = R3t([1:outx_index-1 outx_index+1:length(gamma_xh_old)],[1:outx_index-1 outx_index+1:length(gamma_xh_old)]);
0263
0264
0265
0266 end
0267 z_x = -sign(ak_t(new_x));
0268
0269 dx = ((A(:,gamma_lh)'*A(:,new_x)+epsilon*b(:,gamma_lh)'*b(:,new_x))*z_x);
0270
0271
0272
0273
0274
0275 del_x_hat = -R_glgx\(Q_glgx'*dx);
0276
0277 del_xhat_vec = zeros(N,1);
0278 del_xhat_vec(gamma_xh) = del_x_hat;
0279 del_xhat_vec(new_x) = z_x;
0280
0281 dk_t = A'*(A*del_xhat_vec)+epsilon*b'*(b*del_xhat_vec);
0282 if flag_theta == 0
0283 if sign(pk_t(itheta))== sign(dk_t(itheta))
0284 z_x = -z_x;
0285 del_xhat_vec = -del_xhat_vec;
0286 dk_t = -dk_t;
0287 end
0288 end
0289 pk_t(out_lambda) = sign(pk_t(out_lambda))*tau;
0290
0291 temp_gamma = zeros(N,1);
0292 temp_gamma(gamma_lh) = gamma_lh;
0293 gamma_lc = find([1:N]' ~= temp_gamma);
0294
0295 d_constr1 = (tau-pk_t(gamma_lc))./dk_t(gamma_lc);
0296 d_constr2 = (tau+pk_t(gamma_lc))./-dk_t(gamma_lc);
0297 d_constr3 = (-xp_h(gamma_xh_app)./del_xhat_vec(gamma_xh_app));
0298 idelta_1 = find(d_constr1>2*eps);
0299 idelta_2 = find(d_constr2>2*eps);
0300 idelta_3 = find(d_constr3>2*eps);
0301 delta1 = min(d_constr1(idelta_1));
0302 delta2 = min(d_constr2(idelta_2));
0303 delta3 = min(d_constr3(idelta_3));
0304
0305 if delta1>delta2
0306 delta = delta2;
0307 idelta = gamma_lc(find(d_constr2==delta2));
0308 flag_delta = 1;
0309 else
0310 delta = delta1;
0311 idelta = gamma_lc(find(d_constr1==delta1));
0312 flag_delta = 1;
0313 end
0314 if delta3 < delta
0315 delta = delta3;
0316 idelta = gamma_xh_app(find(d_constr3==delta3));
0317 flag_delta = 0;
0318 end
0319
0320 xp_h_old = xp_h;
0321 xp_h = xp_h + delta*del_xhat_vec;
0322
0323 if flag_delta == 1
0324 gamma_xh_old = gamma_xh;
0325 gamma_lh_old = gamma_lh;
0326 gamma_lh = [gamma_lh; idelta];
0327 gamma_xh = gamma_xh_app;
0328 in_lambda = idelta;
0329
0330
0331
0332 Q0 = Q_glgx;
0333 R0 = R_glgx;
0334 Q0t = [Q0 zeros(length(gamma_xh_old),1); zeros(1,length(gamma_lh_old)) 1];
0335 R0t = [R0 zeros(length(gamma_xh_old),1); zeros(1,length(gamma_lh_old)) 1];
0336 loc_vector = zeros(length(gamma_lh),1);
0337 loc_vector(end) = 1;
0338 rep_row = (A(:,in_lambda)'*A(:,gamma_xh)+epsilon*b(:,in_lambda)'*b(:,gamma_xh))';
0339 [Q2t R2t] = qrupdate(Q0t, R0t, loc_vector, rep_row);
0340 rep_vec = A(:,gamma_lh)'*A(:,new_x)+epsilon*b(:,gamma_lh)'*b(:,new_x);
0341 rep_vec(end) = -1;
0342 [Q_glgx R_glgx] = qrupdate(Q2t, R2t, rep_vec, loc_vector);
0343
0344
0345
0346 else
0347 gamma_xh_old = gamma_xh;
0348 gamma_lh_old = gamma_lh;
0349
0350
0351 outx_index = find(gamma_xh==idelta);
0352 out_x = idelta;
0353 xp_h(out_x) = 0;
0354
0355 if ~isempty(outx_index)
0356 gamma_xh(outx_index) = new_x;
0357
0358
0359
0360 Q0 = Q_glgx;
0361 R0 = R_glgx;
0362 loc_vector = zeros(length(gamma_xh),1);
0363 loc_vector(outx_index) = 1;
0364 [Q_glgx, R_glgx] = qrupdate(Q0,R0, A(:,gamma_lh)'*A(:,new_x)+epsilon*b(:,gamma_lh)'*b(:,new_x)-(A(:,gamma_lh)'*A(:,out_x)+epsilon*b(:,gamma_lh)'*b(:,out_x)),loc_vector);
0365 end
0366 end
0367
0368 pk_old = pk_t+delta*dk_t;
0369 pk_old(gamma_lh) = sign(pk_old(gamma_lh))*tau;
0370 ak_old = ak_t;
0371 ak_old(gamma_xh_app) = sign(ak_old(gamma_xh_app));
0372 else
0373
0374
0375
0376 if flag_delta == 1
0377
0378
0379 new_lambda = idelta;
0380 gamma_lh_app = [gamma_lh; new_lambda];
0381 in_lambda = idelta;
0382
0383
0384 Q0 = Q_glgx;
0385 R0 = R_glgx;
0386 [Q_glgx R_glgx] = qrupdate(Q0, R0, (epsilon-e0)*b(:,gamma_lh)',b(:,gamma_xh)');
0387 else
0388 gamma_lh_old = gamma_lh;
0389 gamma_xh_old = gamma_xh;
0390
0391
0392
0393 outx_index = find(gamma_xh==idelta);
0394
0395 gamma_xh = gamma_xh([1:outx_index-1 outx_index+1:length(gamma_xh)]);
0396
0397
0398 outl_index = length(gamma_lh);
0399 new_lambda = gamma_lh(outl_index);
0400
0401 gamma_lh = gamma_lh([1:outl_index-1 outl_index+1:length(gamma_lh)]);
0402 gamma_lh_app = [gamma_lh; new_lambda];
0403 xp_h(idelta) = 0;
0404 out_x = idelta;
0405
0406
0407
0408 Q0 = Q_glgx;
0409 R0 = R_glgx;
0410 [Q1 R1] = qrupdate(Q0, R0, (epsilon-e0)*b(:,gamma_lh_old)',b(:,gamma_xh_old)');
0411 loc_vector = zeros(length(gamma_lh_old),1);
0412 loc_vector(outl_index) = 1;
0413 rep_row = (A(:,new_lambda)'*A(:,gamma_xh_old)+epsilon*b(:,new_lambda)'*b(:,gamma_xh_old))';
0414 [Q2t R2t] = qrupdate(Q1, R1, loc_vector,-rep_row);
0415 loc_vector = zeros(length(gamma_xh_old),1);
0416 loc_vector(outx_index) = 1;
0417 rep_vec = (A(:,gamma_lh_old)'*A(:,out_x)+epsilon*b(:,gamma_lh_old)'*b(:,out_x));
0418 rep_vec(outl_index) = 1;
0419 [Q3t R3t] = qrupdate(Q2t, R2t, -rep_vec, loc_vector);
0420 Q_glgx = Q3t([1:outl_index-1 outl_index+1:length(gamma_lh_old)],[1:outx_index-1 outx_index+1:length(gamma_xh_old)]);
0421 R_glgx = R3t([1:outx_index-1 outx_index+1:length(gamma_xh_old)],[1:outx_index-1 outx_index+1:length(gamma_xh_old)]);
0422
0423
0424
0425 end
0426 z_l = sign(pk_t(new_lambda));
0427
0428 dl = ((A(:,gamma_xh)'*A(:,new_lambda)+epsilon*b(:,gamma_xh)'*b(:,new_lambda))*z_l);
0429
0430
0431
0432
0433
0434 del_lam_hat = -Q_glgx*(R_glgx'\dl);
0435
0436 del_lhat_vec = zeros(N,1);
0437 del_lhat_vec(gamma_lh) = del_lam_hat;
0438 del_lhat_vec(new_lambda) = z_l;
0439
0440 bk_t = A'*(A*del_lhat_vec)+epsilon*b'*(b*del_lhat_vec);
0441 if flag_delta == 0
0442 if sign(ak_t(idelta))==sign(bk_t(idelta))
0443 z_l = -z_l;
0444 del_lhat_vec = -del_lhat_vec;
0445 bk_t = -bk_t;
0446 end
0447 end
0448 ak_t(out_x) = sign(ak_t(out_x));
0449
0450 temp_gamma = zeros(N,1);
0451 temp_gamma(gamma_xh) = gamma_xh;
0452 gamma_xc = find([1:N]' ~= temp_gamma);
0453
0454 b_constr1 = (1-ak_t(gamma_xc))./bk_t(gamma_xc);
0455 b_constr2 = (1+ak_t(gamma_xc))./-bk_t(gamma_xc);
0456 b_constr3 = (-lambda_h(gamma_lh_app)./del_lhat_vec(gamma_lh_app));
0457 itheta_1 = find(b_constr1>2*eps);
0458 itheta_2 = find(b_constr2>2*eps);
0459 itheta_3 = find(b_constr3>2*eps);
0460 theta1 = min(b_constr1(itheta_1));
0461 theta2 = min(b_constr2(itheta_2));
0462 theta3 = min(b_constr3(itheta_3));
0463
0464 if theta1>theta2
0465 theta = theta2;
0466 itheta = gamma_xc(find(b_constr2==theta2));
0467 flag_theta = 1;
0468 else
0469 theta = theta1;
0470 itheta = gamma_xc(find(b_constr1==theta1));
0471 flag_theta = 1;
0472 end
0473 if theta3 < theta
0474 theta = theta3;
0475 itheta = gamma_lh_app(find(b_constr3==theta3));
0476 flag_theta = 0;
0477 end
0478
0479 lambda_h_old = lambda_h;
0480 lambda_h = lambda_h + theta*del_lhat_vec;
0481 if flag_theta == 1
0482 gamma_lh_old = gamma_lh;
0483 gamma_xh_old = gamma_xh;
0484 gamma_xh = [gamma_xh; itheta];
0485 gamma_lh = gamma_lh_app;
0486 in_x = itheta;
0487
0488
0489
0490 Q0 = Q_glgx;
0491 R0 = R_glgx;
0492 Q0t = [Q0 zeros(length(gamma_xh_old),1); zeros(1,length(gamma_lh_old)) 1];
0493 R0t = [R0 zeros(length(gamma_xh_old),1); zeros(1,length(gamma_lh_old)) 1];
0494 loc_vector = zeros(length(gamma_lh),1);
0495 loc_vector(end) = 1;
0496 rep_row = (A(:,new_lambda)'*A(:,gamma_xh)+epsilon*b(:,new_lambda)'*b(:,gamma_xh))';
0497 [Q2t R2t] = qrupdate(Q0t, R0t, loc_vector, rep_row);
0498 rep_vec = A(:,gamma_lh)'*A(:,in_x)+epsilon*b(:,gamma_lh)'*b(:,in_x);
0499 rep_vec(end) = -1;
0500 [Q_glgx R_glgx] = qrupdate(Q2t, R2t, rep_vec, loc_vector);
0501
0502
0503
0504 else
0505
0506 outl_index = find(gamma_lh==itheta);
0507 out_lambda = itheta;
0508
0509 out_lambda = itheta;
0510 lambda_h(itheta) = 0;
0511 if ~isempty(outl_index)
0512 gamma_lh_old = gamma_lh;
0513 gamma_xh_old = gamma_xh;
0514 gamma_lh(outl_index) = new_lambda;
0515
0516
0517
0518 Q0 = Q_glgx;
0519 R0 = R_glgx;
0520 loc_vector = zeros(length(gamma_xh),1);
0521 loc_vector(outl_index) = 1;
0522 row_replaced = (A(:,new_lambda)'*A(:,gamma_xh)+epsilon*b(:,new_lambda)'*b(:,gamma_xh)-(A(:,out_lambda)'*A(:,gamma_xh)+epsilon*b(:,out_lambda)'*b(:,gamma_xh)));
0523 [Q_glgx, R_glgx] = qrupdate(Q0,R0, loc_vector,row_replaced');
0524 end
0525
0526 end
0527 ak_old = ak_t+theta*bk_t;
0528 ak_old(gamma_xh) = sign(ak_old(gamma_xh));
0529 pk_old = pk_t;
0530 pk_old(gamma_lh_app) = sign(pk_old(gamma_lh_app))*tau;
0531 end
0532 e0 = epsilon;
0533 end
0534 th = cputime-t0;