VNode* DESPOT::ConstructTree(vector<State*>& particles, RandomStreams& streams, ScenarioLowerBound* lower_bound, ScenarioUpperBound* upper_bound, const DSPOMDP* model, History& history, double timeout, SearchStatistics* statistics) { if (statistics != NULL) { statistics->num_particles_before_search = model->NumActiveParticles(); } for (int i = 0; i < particles.size(); i++) { particles[i]->scenario_id = i; } VNode* root = new VNode(particles); logd << "[DESPOT::ConstructTree] START - Initializing lower and upper bounds at the root node."; InitBounds(root, lower_bound, upper_bound, streams, history); logd << "[DESPOT::ConstructTree] END - Initializing lower and upper bounds at the root node."; if (statistics != NULL) { statistics->initial_lb = root->lower_bound(); statistics->initial_ub = root->upper_bound(); } double used_time = 0; int num_trials = 0; do { double start = clock(); VNode* cur = Trial(root, streams, lower_bound, upper_bound, model, history, statistics); used_time += double(clock() - start) / CLOCKS_PER_SEC; start = clock(); Backup(cur); if (statistics != NULL) { statistics->time_backup += double(clock() - start) / CLOCKS_PER_SEC; } used_time += double(clock() - start) / CLOCKS_PER_SEC; num_trials++; } while (used_time * (num_trials + 1.0) / num_trials < timeout && (root->upper_bound() - root->lower_bound()) > 1e-6); if (statistics != NULL) { statistics->num_particles_after_search = model->NumActiveParticles(); statistics->num_policy_nodes = root->PolicyTreeSize(); statistics->num_tree_nodes = root->Size(); statistics->final_lb = root->lower_bound(); statistics->final_ub = root->upper_bound(); statistics->time_search = used_time; statistics->num_trials = num_trials; } return root; }