+ return;
+ }
+
+ weight_debug_vec.clear();
+
+ quickSort(&leaves_tmp_storage, 0, leaves_tmp_storage.size() - 1);
+ for (uint i = 0; i < leaves_tmp_storage.size(); i++) {
+ Predicate * pred = leaves_tmp_storage[i];
+ double weight = 100.0 / sqrt(pred->get_expl_count() + 1);
+ pred->set_weight(weight);
+ }
+
+ // Update weights in internal nodes
+ while ( !leaves_tmp_storage.empty() ) {
+ Predicate * leaf = leaves_tmp_storage.back();
+ leaves_tmp_storage.pop_back();
+
+ Predicate * curr = leaf->get_parent();
+ while (curr != NULL) {
+ 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];
+
+ double weight = child->get_weight();
+ if (weight != 0)
+ weight_sum += weight;
+ else if ( predicate_leaves.contains(child) ) {
+ // If this child is a leaf
+ double weight = 100.0 / sqrt(child->get_expl_count() + 1);
+ child->set_weight(weight);
+ weight_sum += weight;
+ } else {
+ has_unassigned_node = true;
+ weight_debug_vec.push_back(child); // For debugging purpose
+ break;
+ }
+ }
+
+ 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();
+ }
+ }