00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <assert.h>
00028 #include <stdlib.h>
00029 #ifdef _MSC_VER
00030 #else
00031 #include <unistd.h>
00032 #include <sys/time.h>
00033 #endif
00034
00035 #include <stdio.h>
00036 #include <string.h>
00037
00038
00039 #include <iostream>
00040 #include <cerrno>
00041 #include <fstream>
00042
00043 #include "pomdpCassandraWrapper.h"
00044 #include "POMDP.h"
00045 #include "MathLib.h"
00046
00047 using namespace std;
00048 using namespace momdp;
00049
00050 namespace momdp {
00051
00052
00053
00054
00055
00056 static void reaDenseVector(char *data, DenseVector& b, int numValues)
00057 {
00058 int i;
00059 char *inp = data;
00060 char *tok;
00061
00062 for (i=0; i < numValues; i++) {
00063 tok = strtok(inp," ");
00064 if (0 == tok) {
00065 cout << "ERROR: not enough entries in initial belief distribution"
00066 << endl;
00067 exit(EXIT_FAILURE);
00068 }
00069 inp = 0;
00070
00071 b(i) = atof(tok);
00072 }
00073 }
00074
00075 static void trimTrailingWhiteSpace(char *s)
00076 {
00077 int n = strlen(s);
00078 int i;
00079 for (i = n-1; i >= 0; i--) {
00080 if (!isspace(s[i])) break;
00081 }
00082 s[i+1] = '\0';
00083 }
00084
00085
00086
00087
00088
00089 POMDP::POMDP( std::string& fileName, bool useFastParser)
00090 {
00091 this->fileName = fileName;
00092 size_t backslash = this->fileName.rfind( "/", this->fileName.length() );
00093 if ( backslash != std::string::npos ) this->fileName = this->fileName.substr(backslash+1);
00094
00095 readFromFile(fileName, useFastParser);
00096 }
00097
00098 void POMDP::readFromFile( std::string& fileName,
00099 bool useFastParser)
00100 {
00101 if (useFastParser) {
00102 readFromFileFast2(fileName);
00103 } else {
00104 readFromFileCassandra(fileName);
00105 }
00106
00107
00108 #if USE_DEBUG_PRINT
00109 printf("POMDP::readFromFile: marking zero-reward absorbing states as terminal\n");
00110 #endif
00111 isPOMDPTerminalState.resize(numStates, true);
00112 FOR (s, numStates) {
00113 FOR (a, numActions) {
00114 if ((fabs(1.0 - T[a](s,s)) > OBS_IS_ZERO_EPS) || R(s,a) != 0.0) {
00115 isPOMDPTerminalState[s] = false;
00116 break;
00117 }
00118 }
00119 }
00120 }
00121
00122
00123
00124 SparseMatrix& POMDP::getTransitionMatrix(int a) {
00125 return T[a];
00126 }
00127
00128 SparseMatrix& POMDP::getTransposedTransitionMatrix(int a) {
00129 return Ttr[a];
00130 }
00131
00132 SparseMatrix& POMDP::getObservationMatrix(int a) {
00133 return O[a];
00134 }
00135
00136 SparseMatrix& POMDP::getTransposedObservationMatrix(int a) {
00137 return Otr[a];
00138 }
00139
00140 SparseMatrix& POMDP::getRewardMatrix() {
00141 return R;
00142 }
00143
00144 REAL_VALUE POMDP::getMaxReward() {
00145 return R.getMaxValue();
00146 }
00147
00148
00149
00150
00151 belief_vector& POMDP::getInitialBelief(void)
00152 {
00153
00154 return initialBelief;
00155 }
00156
00157 obs_prob_vector& POMDP::getObsProbVector(obs_prob_vector& result,
00158 belief_vector& b,
00159 int a)
00160 {
00161 DenseVector tmp, tmp2;
00162
00163
00164 mult( tmp, Ttr[a], b );
00165
00166 mult( tmp2, tmp, O[a] );
00167
00168 copy(result, tmp2);
00169 return result;
00170 }
00171
00172
00173
00174 belief_vector& POMDP::getNextBelief(belief_vector& result,
00175 belief_vector& b,
00176 int a, int o)
00177 {
00178 belief_vector tmp;
00179
00180
00181 mult( tmp, Ttr[a], b );
00182 emult_column( result, O[a], o, tmp );
00183
00184
00185 result *= (1.0/(result.norm_1()));
00186
00187 return result;
00188 }
00189
00190 REAL_VALUE POMDP::getReward( belief_vector& b, int a)
00191 {
00192 return inner_prod_column( R, a, b );
00193 }
00194
00195 bool POMDP::getIsTerminalState( belief_vector& s)
00196 {
00197 REAL_VALUE nonTerminalSum = s.maskedSum(isPOMDPTerminalState);
00198 return (nonTerminalSum < 1e-10);
00199 }
00200
00201 void POMDP::readFromFileCassandra( string& fileName) {
00202 #if USE_DEBUG_PRINT
00203 timeval startTime, endTime;
00204 cout << "reading problem from " << fileName << endl;
00205 gettimeofday(&startTime,0);
00206 #endif
00207
00208 PomdpCassandraWrapper p;
00209 p.readFromFile(fileName);
00210
00211 numStates = p.getNumStates();
00212 setBeliefSize(numStates);
00213 numActions = p.getNumActions();
00214 numObservations = p.getNumObservations();
00215 discount = p.getDiscount();
00216
00217
00218 cout << "input file : " << fileName << endl;
00219
00220
00221 kmatrix Rk;
00222 copy(Rk, p.getRTranspose(), numStates);
00223 kmatrix_transpose_in_place(Rk);
00224 copy(R, Rk);
00225
00226
00227 kmatrix Tk, Ok;
00228 T.resize(numActions);
00229 Ttr.resize(numActions);
00230 O.resize(numActions);
00231 Otr.resize(numActions);
00232 FOR (a, numActions) {
00233 copy(Tk, p.getT(a), numStates);
00234 copy(T[a], Tk);
00235 kmatrix_transpose_in_place(Tk);
00236 copy(Ttr[a], Tk);
00237
00238 copy(Ok, p.getO(a), numObservations);
00239 copy(O[a], Ok);
00240 kmatrix_transpose_in_place(Ok);
00241 copy(Otr[a], Ok);
00242 }
00243
00244
00245 DenseVector initialBeliefD;
00246 initialBeliefD.resize(numStates);
00247 FOR (s, numStates) {
00248 initialBeliefD(s) = p.getInitialBelief(s);
00249 }
00250 copy(initialBelief, initialBeliefD);
00251 initialBelief.finalize();
00252
00253
00254
00255 #if 0
00256 DenseVector initialBeliefx;
00257 std::vector<bool> isPOMDPTerminalStatex;
00258 kmatrix Rx;
00259 std::vector<kmatrix> Tx, Ox;
00260
00261
00262 initialBeliefx.resize(numStates);
00263 set_to_zero(initialBeliefx);
00264 isPOMDPTerminalStatex.resize(numStates, false);
00265 Rx.resize(numStates, numActions);
00266 Tx.resize(numActions);
00267 Ox.resize(numActions);
00268 FOR (a, numActions) {
00269 Tx[a].resize(numStates, numStates);
00270 Ox[a].resize(numStates, numObservations);
00271 }
00272
00273
00274 FOR (s, numStates) {
00275 initialBeliefx(s) = p.getInitialBelief(s);
00276 isPOMDPTerminalStatex[s] = p.isTerminalState(s);
00277 FOR (a, numActions) {
00278 kmatrix_set_entry( Rx, s, a, p.R(s,a) );
00279 FOR (sp, numStates) {
00280 kmatrix_set_entry( Tx[a], s, sp, p.T(s,a,sp) );
00281 }
00282 FOR (o, numObservations) {
00283 kmatrix_set_entry( Ox[a], s, o, p.O(s,a,o) );
00284 }
00285 }
00286 }
00287
00288
00289 copy( initialBelief, initialBeliefx );
00290 isPOMDPTerminalState = isPOMDPTerminalStatex;
00291 copy( R, Rx );
00292 Ttr.resize(numActions);
00293 O.resize(numActions);
00294 T.resize(numActions);
00295 FOR (a, numActions) {
00296 copy( T[a], Tx[a] );
00297 kmatrix_transpose_in_place( Tx[a] );
00298 copy( Ttr[a], Tx[a] );
00299 copy( O[a], Ox[a] );
00300 }
00301 #endif // if 0
00302
00303 #if USE_DEBUG_PRINT
00304 gettimeofday(&endTime,0);
00305 REAL_VALUE numSeconds = (endTime.tv_sec - startTime.tv_sec)
00306 + 1e-6 * (endTime.tv_usec - startTime.tv_usec);
00307 cout << "[file reading took " << numSeconds << " seconds]" << endl;
00308
00309 debugDensity();
00310 #endif
00311 }
00312
00313
00314 string TrimStr( string& Src)
00315 {
00316 string c = " \r\n";
00317 int p2 = Src.find_last_not_of(c);
00318 if (p2 == std::string::npos)
00319 return std::string();
00320 int p1 = Src.find_first_not_of(c);
00321 if (p1 == std::string::npos) p1 = 0;
00322 return Src.substr(p1, (p2-p1)+1);
00323 }
00324
00325
00326 void POMDP::readFromFileFast2( std::string& fileName)
00327 {
00328 int lineNumber;
00329 string curline;
00330 ifstream in;
00331 char sbuf[512];
00332 int numSizesSet = 0;
00333 bool inPreamble = true;
00334
00335
00336
00337
00338
00339
00340
00341 #if USE_DEBUG_PRINT
00342 timeval startTime, endTime;
00343 cout << "reading problem (in fast mode) from " << fileName << endl;
00344 gettimeofday(&startTime,0);
00345 #endif
00346
00347 in.open(fileName.c_str());
00348 if (!in)
00349 {
00350 cerr << "ERROR: couldn't open " << fileName << " for reading: " << endl;
00351 exit(EXIT_FAILURE);
00352 }
00353
00354 DenseVector initialBeliefx;
00355 kmatrix Rx;
00356 std::vector<kmatrix> Tx, Ox;
00357
00358 #define PM_PREFIX_MATCHES_STL(X) ( string::npos != curline.find((X)))
00359
00360 lineNumber = 1;
00361 while (getline(in, curline))
00362 {
00363 if (in.fail() && !in.eof()) {
00364 cerr << "ERROR: readFromFileFast: line too long for buffer"
00365 << " (max length " << curline.size() << ")" << endl;
00366 exit(EXIT_FAILURE);
00367 }
00368
00369 string buf = TrimStr(curline);
00370 if ('#' == buf.c_str()[0]) continue;
00371 if ('\0' == buf.c_str()[0]) continue;
00372
00373 if (inPreamble)
00374 {
00375 if (PM_PREFIX_MATCHES_STL("discount:"))
00376 {
00377 if (1 != sscanf(buf.c_str(),"discount: %lf", &discount))
00378 {
00379 cerr << "ERROR: line " << lineNumber
00380 << ": syntax error in discount statement"
00381 << endl;
00382 exit(EXIT_FAILURE);
00383 }
00384 }
00385 else if (PM_PREFIX_MATCHES_STL("values:"))
00386 {
00387 if (1 != sscanf(buf.c_str(),"values: %s", sbuf))
00388 {
00389 cerr << "ERROR: line " << lineNumber
00390 << ": syntax error in values statement"
00391 << endl;
00392 exit(EXIT_FAILURE);
00393 }
00394 if (0 != strcmp(sbuf,"reward"))
00395 {
00396 cerr << "ERROR: line " << lineNumber
00397 << ": can only handle values of type reward"
00398 << endl;
00399 exit(EXIT_FAILURE);
00400 }
00401 }
00402 else if (PM_PREFIX_MATCHES_STL("actions:"))
00403 {
00404 if (1 != sscanf(buf.c_str(),"actions: %d", &numActions))
00405 {
00406 cerr << "ERROR: line " << lineNumber
00407 << ": syntax error in actions statement"
00408 << endl;
00409 exit(EXIT_FAILURE);
00410 }
00411 numSizesSet++;
00412 }
00413 else if (PM_PREFIX_MATCHES_STL("observations:"))
00414 {
00415 if (1 != sscanf(buf.c_str(),"observations: %d", &numObservations))
00416 {
00417 cerr << "ERROR: line " << lineNumber
00418 << ": syntax error in observations statement"
00419 << endl;
00420 exit(EXIT_FAILURE);
00421 }
00422 numSizesSet++;
00423 }
00424 else if (PM_PREFIX_MATCHES_STL("states:"))
00425 {
00426 if (1 != sscanf(buf.c_str(),"states: %d", &numStates))
00427 {
00428 cerr << "ERROR: line " << lineNumber
00429 << ": syntax error in states statement"
00430 << endl;
00431 exit(EXIT_FAILURE);
00432 }
00433 numSizesSet++;
00434 }
00435 else
00436 {
00437 cerr << "ERROR: line " << lineNumber
00438 << ": got unexpected statement type while parsing preamble"
00439 << endl;
00440 exit(EXIT_FAILURE);
00441 }
00442
00443 if (3 == numSizesSet) {
00444
00445 setBeliefSize(numStates);
00446 initialBeliefx.resize(numStates);
00447 set_to_zero(initialBeliefx);
00448 Rx.resize(numStates, numActions);
00449 Tx.resize(numActions);
00450 Ox.resize(numActions);
00451 FOR (a, numActions) {
00452 Tx[a].resize(numStates, numStates);
00453 Ox[a].resize(numStates, numObservations);
00454 }
00455
00456 inPreamble = false;
00457 }
00458
00459 }
00460 else
00461 {
00462
00463 if (PM_PREFIX_MATCHES_STL("start:"))
00464 {
00465 char *cstr = strdup(buf.c_str());
00466 char *data = cstr + strlen("start: ");
00467 reaDenseVector(data,initialBeliefx,numStates);
00468 free(cstr);
00469
00470
00471 }
00472 else
00473 if (PM_PREFIX_MATCHES_STL("R:"))
00474 {
00475 int s, a;
00476 REAL_VALUE reward;
00477 if (3 != sscanf(buf.c_str(),"R: %d : %d : * : * %lf", &a, &s, &reward)) {
00478 cerr << "ERROR: line " << lineNumber
00479 << ": syntax error in R statement"
00480 << endl;
00481 exit(EXIT_FAILURE);
00482 }
00483 kmatrix_set_entry( Rx, s, a, reward );
00484 }
00485 else if (PM_PREFIX_MATCHES_STL("T:"))
00486 {
00487 int s, a, sp;
00488 REAL_VALUE prob;
00489 if (4 != sscanf(buf.c_str(),"T: %d : %d : %d %lf", &a, &s, &sp, &prob))
00490 {
00491 cerr << "ERROR: line " << lineNumber
00492 << ": syntax error in T statement"
00493 << endl;
00494 exit(EXIT_FAILURE);
00495 }
00496 kmatrix_set_entry( Tx[a], s, sp, prob );
00497 }
00498 else if (PM_PREFIX_MATCHES_STL("O:"))
00499 {
00500 int s, a, o;
00501 REAL_VALUE prob;
00502 if (4 != sscanf(buf.c_str(),"O: %d : %d : %d %lf", &a, &s, &o, &prob))
00503 {
00504 cerr << "ERROR: line " << lineNumber
00505 << ": syntax error in O statement"
00506 << endl;
00507 exit(EXIT_FAILURE);
00508 }
00509 kmatrix_set_entry( Ox[a], s, o, prob );
00510 }
00511 else
00512 {
00513 cerr << "ERROR: line " << lineNumber
00514 << ": got unexpected statement type while parsing body"
00515 << endl;
00516 exit(EXIT_FAILURE);
00517 }
00518 }
00519
00520 lineNumber++;
00521 }
00522
00523 in.close();
00524
00525
00526 copy( initialBelief, initialBeliefx );
00527 initialBelief.finalize();
00528 copy( R, Rx );
00529 Ttr.resize(numActions);
00530 O.resize(numActions);
00531 Otr.resize(numActions);
00532 T.resize(numActions);
00533 FOR (a, numActions) {
00534 copy( T[a], Tx[a] );
00535 kmatrix_transpose_in_place( Tx[a] );
00536 copy( Ttr[a], Tx[a] );
00537 copy( O[a], Ox[a] );
00538 kmatrix_transpose_in_place(Ox[a] );
00539 copy(Otr[a], Ox[a]);
00540 }
00541
00542 #if USE_DEBUG_PRINT
00543 gettimeofday(&endTime,0);
00544 REAL_VALUE numSeconds = (endTime.tv_sec - startTime.tv_sec)
00545 + 1e-6 * (endTime.tv_usec - startTime.tv_usec);
00546 cout << "[file reading took " << numSeconds << " seconds]" << endl;
00547 #endif
00548
00549 debugDensity();
00550
00551 }
00552
00553
00554
00555
00556 void POMDP::readFromFileFast( std::string& fileName)
00557 {
00558 char buf[1<<20];
00559 int lineNumber;
00560 ifstream in;
00561 char sbuf[512];
00562 int numSizesSet = 0;
00563 bool inPreamble = true;
00564 char *data;
00565
00566 #if USE_DEBUG_PRINT
00567 timeval startTime, endTime;
00568 cout << "reading problem (in fast mode) from " << fileName << endl;
00569 gettimeofday(&startTime,0);
00570 #endif
00571
00572 in.open(fileName.c_str());
00573 if (!in) {
00574 cerr << "ERROR: couldn't open " << fileName << " for reading: " << endl;
00575 exit(EXIT_FAILURE);
00576 }
00577
00578 DenseVector initialBeliefx;
00579 kmatrix Rx;
00580 std::vector<kmatrix> Tx, Ox;
00581
00582 #define PM_PREFIX_MATCHES(X) \
00583 (0 == strncmp(buf,(X),strlen(X)))
00584
00585 lineNumber = 1;
00586 while (!in.eof()) {
00587 in.getline(buf,sizeof(buf));
00588 if (in.fail() && !in.eof()) {
00589 cerr << "ERROR: readFromFileFast: line too long for buffer"
00590 << " (max length " << sizeof(buf) << ")" << endl;
00591 exit(EXIT_FAILURE);
00592 }
00593
00594 if ('#' == buf[0]) continue;
00595 trimTrailingWhiteSpace(buf);
00596 if ('\0' == buf[0]) continue;
00597
00598 if (inPreamble) {
00599 if (PM_PREFIX_MATCHES("discount:")) {
00600 if (1 != sscanf(buf,"discount: %lf", &discount)) {
00601 cerr << "ERROR: line " << lineNumber
00602 << ": syntax error in discount statement"
00603 << endl;
00604 exit(EXIT_FAILURE);
00605 }
00606 } else if (PM_PREFIX_MATCHES("values:")) {
00607 if (1 != sscanf(buf,"values: %s", sbuf)) {
00608 cerr << "ERROR: line " << lineNumber
00609 << ": syntax error in values statement"
00610 << endl;
00611 exit(EXIT_FAILURE);
00612 }
00613 if (0 != strcmp(sbuf,"reward")) {
00614 cerr << "ERROR: line " << lineNumber
00615 << ": can only handle values of type reward"
00616 << endl;
00617 exit(EXIT_FAILURE);
00618 }
00619 } else if (PM_PREFIX_MATCHES("actions:")) {
00620 if (1 != sscanf(buf,"actions: %d", &numActions)) {
00621 cerr << "ERROR: line " << lineNumber
00622 << ": syntax error in actions statement"
00623 << endl;
00624 exit(EXIT_FAILURE);
00625 }
00626 numSizesSet++;
00627 } else if (PM_PREFIX_MATCHES("observations:")) {
00628 if (1 != sscanf(buf,"observations: %d", &numObservations)) {
00629 cerr << "ERROR: line " << lineNumber
00630 << ": syntax error in observations statement"
00631 << endl;
00632 exit(EXIT_FAILURE);
00633 }
00634 numSizesSet++;
00635 } else if (PM_PREFIX_MATCHES("states:")) {
00636 if (1 != sscanf(buf,"states: %d", &numStates)) {
00637 cerr << "ERROR: line " << lineNumber
00638 << ": syntax error in states statement"
00639 << endl;
00640 exit(EXIT_FAILURE);
00641 }
00642 numSizesSet++;
00643 } else {
00644 cerr << "ERROR: line " << lineNumber
00645 << ": got unexpected statement type while parsing preamble"
00646 << endl;
00647 exit(EXIT_FAILURE);
00648 }
00649
00650 if (3 == numSizesSet) {
00651
00652 setBeliefSize(numStates);
00653 initialBeliefx.resize(numStates);
00654 set_to_zero(initialBeliefx);
00655 Rx.resize(numStates, numActions);
00656 Tx.resize(numActions);
00657 Ox.resize(numActions);
00658 FOR (a, numActions) {
00659 Tx[a].resize(numStates, numStates);
00660 Ox[a].resize(numStates, numObservations);
00661 }
00662
00663 inPreamble = false;
00664 }
00665
00666 } else {
00667
00668 if (PM_PREFIX_MATCHES("start:")) {
00669 data = buf + strlen("start: ");
00670 reaDenseVector(data,initialBeliefx,numStates);
00671 } else if (PM_PREFIX_MATCHES("R:")) {
00672 int s, a;
00673 REAL_VALUE reward;
00674 if (3 != sscanf(buf,"R: %d : %d : * : * %lf", &a, &s, &reward)) {
00675 cerr << "ERROR: line " << lineNumber
00676 << ": syntax error in R statement"
00677 << endl;
00678 exit(EXIT_FAILURE);
00679 }
00680 kmatrix_set_entry( Rx, s, a, reward );
00681 } else if (PM_PREFIX_MATCHES("T:")) {
00682 int s, a, sp;
00683 REAL_VALUE prob;
00684 if (4 != sscanf(buf,"T: %d : %d : %d %lf", &a, &s, &sp, &prob)) {
00685 cerr << "ERROR: line " << lineNumber
00686 << ": syntax error in T statement"
00687 << endl;
00688 exit(EXIT_FAILURE);
00689 }
00690 kmatrix_set_entry( Tx[a], s, sp, prob );
00691 } else if (PM_PREFIX_MATCHES("O:")) {
00692 int s, a, o;
00693 REAL_VALUE prob;
00694 if (4 != sscanf(buf,"O: %d : %d : %d %lf", &a, &s, &o, &prob)) {
00695 cerr << "ERROR: line " << lineNumber
00696 << ": syntax error in O statement"
00697 << endl;
00698 exit(EXIT_FAILURE);
00699 }
00700 kmatrix_set_entry( Ox[a], s, o, prob );
00701 } else {
00702 cerr << "ERROR: line " << lineNumber
00703 << ": got unexpected statement type while parsing body"
00704 << endl;
00705 exit(EXIT_FAILURE);
00706 }
00707 }
00708
00709 lineNumber++;
00710 }
00711
00712 in.close();
00713
00714
00715 copy( initialBelief, initialBeliefx );
00716 copy( R, Rx );
00717 Ttr.resize(numActions);
00718 O.resize(numActions);
00719 T.resize(numActions);
00720 FOR (a, numActions) {
00721 copy( T[a], Tx[a] );
00722 kmatrix_transpose_in_place( Tx[a] );
00723 copy( Ttr[a], Tx[a] );
00724 copy( O[a], Ox[a] );
00725 }
00726
00727 #if USE_DEBUG_PRINT
00728 gettimeofday(&endTime,0);
00729 REAL_VALUE numSeconds = (endTime.tv_sec - startTime.tv_sec)
00730 + 1e-6 * (endTime.tv_usec - startTime.tv_usec);
00731 cout << "[file reading took " << numSeconds << " seconds]" << endl;
00732 #endif
00733
00734 debugDensity();
00735 }
00736
00737 void POMDP::debugDensity(void) {
00738 int Ttr_size = 0;
00739 int Ttr_filled = 0;
00740 int O_size = 0;
00741 int O_filled = 0;
00742 FOR (a, numActions) {
00743 Ttr_size += Ttr[a].size1() * Ttr[a].size2();
00744 O_size += O[a].size1() * O[a].size2();
00745 Ttr_filled += Ttr[a].filled();
00746 O_filled += O[a].filled();
00747 }
00748 cout << "T density = " << (((REAL_VALUE) Ttr_filled) / Ttr_size)
00749 << ", O density = " << (((REAL_VALUE) O_filled) / O_size)
00750 << endl;
00751 }
00752
00753 void POMDP::getPossibleObservations(vector<int>& result, vector<REAL_VALUE>&
00754 resultProbs, belief_vector& bel, int act)
00755 {
00756 belief_vector obsBel;
00757 SparseMatrix obsMat = Otr[act];
00758 mult(obsBel, obsMat, bel);
00759
00760
00761 obsBel.copyIndex(result);
00762 obsBel.copyValue(resultProbs);
00763 }
00764
00765 void POMDP::getPossibleActions(vector<int>& result, belief_vector bel)
00766 {
00767 int numActs = getNumActions();
00768 result.reserve(numActs);
00769
00770 vector<int> activeIndices;
00771 bel.copyIndex(activeIndices);
00772
00773 vector<int>::const_iterator iter;
00774 for(int i = 0; i< numActs; i++)
00775 {
00776 SparseMatrix transMat = Ttr[i];
00777 for(iter = activeIndices.begin(); iter != activeIndices.end(); iter++)
00778 {
00779 if(!transMat.isColumnEmpty((*iter)))
00780 {
00781 result.push_back(i);
00782 break;
00783 }
00784 }
00785 }
00786 }
00787
00788 };
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960