- Timestamp:
- 10/03/10 23:32:46 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/design/lq_ctrl.h
r1203 r1210 58 58 virtual void redesign() { 59 59 if (curtime == -1) curtime = horizon; 60 61 if (curtime > 0) curtime--; 62 63 if (curtime >= 0){ 60 61 if (curtime > 0){ 62 curtime--; 64 63 generateLmat(curtime); 65 64 } 66 65 //cout << "time " << curtime << endl; 67 66 //report time 0 reached - LQG designing complete 68 67 //if(curtime == 0) cout << "time 0 reached" << endl; … … 198 197 //set data in tmpMatRow - other times then current replace using model 199 198 RV tmpQrv = sourceQfn.rv; 199 //cout << "Qrv " << tmpQrv << endl << "total crv " << trs_crv << endl; 200 200 ivec j_vec(1); 201 vec copycol; 202 ivec copysource; 201 203 for(int j = 0; j < tmpQrv.length(); j++){ 202 204 j_vec(0) = j; 203 204 if( (tmpQrv.time(j) == 0) && (sum(tmpQrv(j_vec).findself(trs_crv)) > (-1)) ) {//sum is only formal, summed vector is in fact scalar 205 //cout << "matrow\n" << tmpMatRow << endl; 206 207 if( /*(tmpQrv.time(j) == 0) &&*/ (sum(tmpQrv(j_vec).findself(trs_crv)) > (-1)) ) {//sum is only formal, summed vector is in fact scalar 205 208 //jth element of tmpQrv is also element of trs_crv with a proper time 209 //cout << "copy" << endl; 206 210 ivec copytarget = (tmpQrv(j_vec)).dataind(trs_crv); //get target column position in tmpMatRow 207 211 ivec copysource = (tmpQrv(j_vec)).dataind(tmpQrv); //get source column position in Losses(i).Q 208 if(copytarget.size() != copysource.size()) {return mat(0); /*error*/} 209 vec copycol; 212 if(copytarget.size() != copysource.size()) {return mat(0); /*error*/} 210 213 for(int k = 0; k < copysource.size(); k++){ 211 214 copycol = sourceQfn.Q._Ch().get_col(copysource(k)); 215 copycol += tmpMatRow.get_col(copytarget(k)); 212 216 tmpMatRow.set_col(copytarget(k), copycol); 213 217 } 214 218 } 215 219 else { 216 //cout << "USING MODEL" << endl; 220 //cout << "USING MODEL on " << tmpQrv(j,j) << endl; 221 //cout << "model" << endl; 217 222 //jth tmpQrv element is not in trs_crv -> using Model to teplace it 218 ivec copysource;// = (tmpQrv(j_vec)).findself(tmpQrv); //get source column position in Losses(i).Q223 // = (tmpQrv(j_vec)).findself(tmpQrv); //get source column position in Losses(i).Q 219 224 220 225 //int selectedModel = -1; … … 320 325 fakeM1.add(RV("1", 1, 0)); 321 326 fakeM1.t_plus(1); //RV in time t+1 => necessary use of Model to get RV in time t 327 fakeM1.set_time((RV("1", 1, 1).findself(fakeM1))(0) , 0); 328 //cout << fakeM1 << endl; 322 329 fakeQfn.rv = fakeM1; 323 330 … … 356 363 357 364 //get matrix row via getMatRow method 365 //cout << "XXXXXXXXXXXXXXX" << endl; 358 366 tmpMatRow = getMatRow(fakeQfn); 367 //cout << tmpMatRow << endl; 359 368 /*cout << "submatrix ( " << rowIndex << ", " << 360 369 (rowIndex + fakeQfn.Q.rows() - 1) << ", 0, " << (trs_crv.countsize() - 1) << ")" << endl; … … 403 412 if(submatidx == 0) qr_submat = post_qr.get(0, (sizeA - 1), 0, (sizeA - 1)); //(int r1, int r2, int c1, int c2) 404 413 else if(submatidx == 1) qr_submat = post_qr.get(0, (sizeA - 1), sizeA, (post_qr.cols() - 1)); 405 else qr_submat = post_qr.get(sizeA, (sizeA + colsB - 1), sizeA, (post_qr.cols() - 1)); 414 else { 415 if(post_qr.cols() > post_qr.rows()) { //extend post_qr matrix to be at least square 416 post_qr.set_size(post_qr.cols(), post_qr.cols(), true); 417 } 418 419 qr_submat = post_qr.get(sizeA, (sizeA + colsB - 1), sizeA, (post_qr.cols() - 1)); 420 421 } 406 422 407 423 return qr_submat; … … 417 433 trs_crv.add(rvc); 418 434 trs_crv.add(RV("1", 1, 0)); 419 435 420 436 //!first time, time = horizon - 1 421 437 if(timestep == (horizon-1)) … … 429 445 qr(pre_qr, tmpQ, post_qr); 430 446 //cout << "preQR " << pre_qr << endl << "postQR" << post_qr << endl; 431 mat qrA = get_qr_submatrix(0); 447 mat qrA = get_qr_submatrix(0); 432 448 mat qrB = get_qr_submatrix(1); 433 449 mat qrC = get_qr_submatrix(2);