コード例 #1
0
void irAddToDecisionTree(Imm_Reward_List node)
{
  int i, j, k;
  custom_Matrix m;

  assert( node != NULL );

  /* ensure the decision tree is initialized (ok to call dtInit() more than once) */
  dtInit(gNumActions, gNumStates, gNumObservations);

  switch( node->type ) {
  case ir_value:
    if ( gProblemType == POMDP_problem_type ) { /* pomdp */
      dtAdd(node->action, node->cur_state, node->next_state, node->obs, node->rep.value);
    } else { /* mdp */
      dtAdd(node->action, node->cur_state, node->next_state, WILDCARD_SPEC, node->rep.value);
    }
    break;
    
  case ir_vector:
    if ( gProblemType == POMDP_problem_type ) { /* pomdp */
      for (i=0; i < gNumObservations; i++) {
	dtAdd(node->action, node->cur_state, node->next_state, i, node->rep.vector[i]);
      }
    } else { /* mdp */
      for (i=0; i < gNumStates; i++) {
	dtAdd(node->action, node->cur_state, i, WILDCARD_SPEC, node->rep.vector[i]);
      }
    }
    break;
    
  case ir_matrix:
    m = node->rep.matrix;
    for (i=0; i < m->num_rows; i++) {
      for (j=0; j < m->row_length[i]; j++) {
	k = m->row_start[i] + j;
	if( gProblemType == POMDP_problem_type )  { /* pomdp */
	  dtAdd(node->action, node->cur_state, i, m->col[k], m->mat_val[k]);
	} else { /* mdp */
	  dtAdd(node->action, i, m->col[k], WILDCARD_SPEC, m->mat_val[k]);
	}
      }
    }
    break;
    
  default:
    assert(0 /* never reach this point */);
  }  /* switch */
}
コード例 #2
0
ファイル: testDecisionTree.c プロジェクト: Rongya/zmdp
void testOnce(void)
{
  double result;

  /* set up table */
  dtInit(5, 5, 5);

  dtAdd(0, 1, 2, 3, 0.5);
  dtAdd(0, 1, 2, 3, 0.7);

  dtAdd(0, 1, 3, -1, -10.1);
  dtAdd(0, 1, 3, -1, -10.3);

  dtAdd(1, 0, 0,  -1, 6.0);
  dtAdd(1, 0, -1, -1, 7.0);

  dtAdd(-1, 2, -1, -1, 2.7);

  /* do a few queries */
  result = dtGet(0, 1, 2, 3);
  printf("expecting: result=%lf\n", 0.7);
  printf("got:       result=%lf\n", result);

  result = dtGet(0, 1, 3, 1);
  printf("expecting: result=%lf\n", -10.3);
  printf("got:       result=%lf\n", result);

  result = dtGet(1, 0, 0, 0);
  printf("expecting: result=%lf\n", 7.0);
  printf("got:       result=%lf\n", result);

  result = dtGet(3, 2, 0, 0);
  printf("expecting: result=%lf\n", 2.7);
  printf("got:       result=%lf\n", result);

  /* clean up */
  dtDeallocate();
}