+void FuncNode::assign_base_score()
+{
+ SnapVector<Predicate *> leaves;
+ SnapList<Predicate *> queue;
+ queue.push_front(predicate_tree_entry);
+
+ // assign leaf score
+ while ( !queue.empty() ) {
+ Predicate * node = queue.back();
+ queue.pop_back();
+
+ ModelVector<Predicate *> * children = node->get_children();
+ if (children->empty()) {
+ node->set_weight(1);
+ leaves.push_back(node);
+ }
+
+ for (uint i = 0; i < children->size(); i++)
+ queue.push_front( (*children)[i] );
+ }
+
+ // assign scores for internal nodes;
+ while ( !leaves.empty() ) {
+ Predicate * leaf = leaves.back();
+ leaves.pop_back();
+
+ Predicate * curr = leaf->get_parent();
+ while (curr != NULL) {
+ if (curr->get_weight() != 0) {
+ // Has been exlpored
+ break;
+ }
+
+ ModelVector<Predicate *> * children = curr->get_children();
+ double weight_sum = 0;
+ bool has_unassigned_node = false;
+
+ for (uint i = 0; i < children->size(); i++) {
+ Predicate * child = (*children)[i];
+
+ // If a child has unassigned weight
+ double weight = child->get_weight();
+ if (weight == 0) {
+ has_unassigned_node = true;
+ break;
+ } else
+ weight_sum += weight;
+ }
+
+ if (!has_unassigned_node) {
+ double average_weight = (double) weight_sum / (double) children->size();
+ double weight = average_weight * pow(0.9, curr->get_depth());
+ curr->set_weight(weight);
+ } else
+ break;
+
+ curr = curr->get_parent();
+ }
+ }
+}
+