6 #include "concretepredicate.h"
11 FuncNode::FuncNode(ModelHistory * history) :
21 predicate_tree_position(),
29 predicate_tree_entry = new Predicate(NULL, true);
30 predicate_tree_entry->add_predicate_expr(NOPREDICATE, NULL, true);
32 predicate_tree_exit = new Predicate(NULL, false, true);
33 predicate_tree_exit->set_depth(MAX_DEPTH);
35 /* Snapshot data structures below */
36 action_list_buffer = new SnapList<action_list_t *>();
37 read_locations = new loc_set_t();
38 write_locations = new loc_set_t();
39 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
40 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
42 //values_may_read_from = new value_set_t();
45 /* Reallocate snapshotted memories when new executions start */
46 void FuncNode::set_new_exec_flag()
48 action_list_buffer = new SnapList<action_list_t *>();
49 read_locations = new loc_set_t();
50 write_locations = new loc_set_t();
51 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
52 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
54 //values_may_read_from = new value_set_t();
57 /* Check whether FuncInst with the same type, position, and location
58 * as act has been added to func_inst_map or not. If not, add it.
60 void FuncNode::add_inst(ModelAction *act)
63 const char * position = act->get_position();
65 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
66 * actions are not tagged with their source line numbers
71 FuncInst * func_inst = func_inst_map.get(position);
73 /* This position has not been inserted into hashtable before */
74 if (func_inst == NULL) {
75 func_inst = create_new_inst(act);
76 func_inst_map.put(position, func_inst);
80 /* Volatile variables that use ++ or -- syntax may result in read and write actions with the same position */
81 if (func_inst->get_type() != act->get_type()) {
82 FuncInst * collision_inst = func_inst->search_in_collision(act);
84 if (collision_inst == NULL) {
85 collision_inst = create_new_inst(act);
86 func_inst->add_to_collision(collision_inst);
89 func_inst = collision_inst;
93 ASSERT(func_inst->get_type() == act->get_type());
94 int curr_execution_number = model->get_execution_number();
96 /* Reset locations when new executions start */
97 if (func_inst->get_execution_number() != curr_execution_number) {
98 func_inst->set_location(act->get_location());
99 func_inst->set_execution_number(curr_execution_number);
102 /* Mark the memory location of such inst as not unique */
103 if (func_inst->get_location() != act->get_location())
104 func_inst->not_single_location();
107 FuncInst * FuncNode::create_new_inst(ModelAction * act)
109 FuncInst * func_inst = new FuncInst(act, this);
110 int exec_num = model->get_execution_number();
111 func_inst->set_execution_number(exec_num);
113 inst_list.push_back(func_inst);
119 /* Get the FuncInst with the same type, position, and location
122 * @return FuncInst with the same type, position, and location as act */
123 FuncInst * FuncNode::get_inst(ModelAction *act)
126 const char * position = act->get_position();
128 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
129 * actions are not tagged with their source line numbers
131 if (position == NULL)
134 FuncInst * inst = func_inst_map.get(position);
138 action_type inst_type = inst->get_type();
139 action_type act_type = act->get_type();
141 if (inst_type == act_type) {
144 /* RMWRCAS actions are converted to RMW or READ actions */
145 else if (inst_type == ATOMIC_RMWRCAS &&
146 (act_type == ATOMIC_RMW || act_type == ATOMIC_READ)) {
149 /* Return the FuncInst in the collision list */
151 return inst->search_in_collision(act);
156 void FuncNode::add_entry_inst(FuncInst * inst)
161 mllnode<FuncInst *> * it;
162 for (it = entry_insts.begin();it != NULL;it = it->getNext()) {
163 if (inst == it->getVal())
167 entry_insts.push_back(inst);
171 * @brief Convert ModelAdtion list to FuncInst list
172 * @param act_list A list of ModelActions
174 void FuncNode::update_tree(action_list_t * act_list)
176 if (act_list == NULL || act_list->size() == 0)
179 HashTable<void *, value_set_t *, uintptr_t, 0> * write_history = history->getWriteHistory();
181 /* build inst_list from act_list for later processing */
182 func_inst_list_t inst_list;
183 action_list_t rw_act_list;
185 for (sllnode<ModelAction *> * it = act_list->begin();it != NULL;it = it->getNext()) {
186 ModelAction * act = it->getVal();
187 FuncInst * func_inst = get_inst(act);
188 void * loc = act->get_location();
190 if (func_inst == NULL)
193 inst_list.push_back(func_inst);
194 bool act_added = false;
196 if (act->is_write()) {
197 rw_act_list.push_back(act);
199 if (!write_locations->contains(loc)) {
200 write_locations->add(loc);
201 history->update_loc_wr_func_nodes_map(loc, this);
205 if (act->is_read()) {
207 rw_act_list.push_back(act);
209 /* If func_inst may only read_from a single location, then:
211 * The first time an action reads from some location,
212 * import all the values that have been written to this
213 * location from ModelHistory and notify ModelHistory
214 * that this FuncNode may read from this location.
216 if (!read_locations->contains(loc) && func_inst->is_single_location()) {
217 read_locations->add(loc);
218 value_set_t * write_values = write_history->get(loc);
219 add_to_val_loc_map(write_values, loc);
220 history->update_loc_rd_func_nodes_map(loc, this);
225 // model_print("function %s\n", func_name);
226 // print_val_loc_map();
228 update_inst_tree(&inst_list);
229 update_predicate_tree(&rw_act_list);
231 // print_predicate_tree();
235 * @brief Link FuncInsts in inst_list - add one FuncInst to another's predecessors and successors
236 * @param inst_list A list of FuncInsts
238 void FuncNode::update_inst_tree(func_inst_list_t * inst_list)
240 if (inst_list == NULL)
242 else if (inst_list->size() == 0)
246 sllnode<FuncInst *>* it = inst_list->begin();
247 sllnode<FuncInst *>* prev;
249 /* add the first instruction to the list of entry insts */
250 FuncInst * entry_inst = it->getVal();
251 add_entry_inst(entry_inst);
255 prev = it->getPrev();
257 FuncInst * prev_inst = prev->getVal();
258 FuncInst * curr_inst = it->getVal();
260 prev_inst->add_succ(curr_inst);
261 curr_inst->add_pred(prev_inst);
267 void FuncNode::update_predicate_tree(action_list_t * act_list)
269 if (act_list == NULL || act_list->size() == 0)
273 uint32_t inst_counter = 0;
277 inst_pred_map.reset();
280 // Clear the set of leaves encountered in this path
281 leaves_tmp_storage.clear();
283 sllnode<ModelAction *> *it = act_list->begin();
284 Predicate * curr_pred = predicate_tree_entry;
286 ModelAction * next_act = it->getVal();
287 FuncInst * next_inst = get_inst(next_act);
288 next_inst->set_associated_act(next_act, marker);
290 Predicate * unset_predicate = NULL;
291 bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &unset_predicate);
293 // A branch with unset predicate expression is detected
294 if (!branch_found && unset_predicate != NULL) {
295 bool amended = amend_predicate_expr(curr_pred, next_inst, next_act);
299 curr_pred = unset_predicate;
305 if (!branch_found && inst_id_map.contains(next_inst)) {
306 FuncInst * curr_inst = curr_pred->get_func_inst();
307 uint32_t curr_id = inst_id_map.get(curr_inst);
308 uint32_t next_id = inst_id_map.get(next_inst);
310 if (curr_id >= next_id) {
311 Predicate * old_pred = inst_pred_map.get(next_inst);
312 Predicate * back_pred = old_pred->get_parent();
314 // For updating weights
315 leaves_tmp_storage.push_back(curr_pred);
317 // Add to the set of backedges
318 curr_pred->add_backedge(back_pred);
319 curr_pred = back_pred;
324 // Generate new branches
326 SnapVector<struct half_pred_expr *> half_pred_expressions;
327 infer_predicates(next_inst, next_act, &half_pred_expressions);
328 generate_predicates(curr_pred, next_inst, &half_pred_expressions);
332 if (next_act->is_write())
333 curr_pred->set_write(true);
335 if (next_act->is_read()) {
336 /* Only need to store the locations of read actions */
337 loc_act_map.put(next_act->get_location(), next_act);
340 inst_pred_map.put(next_inst, curr_pred);
341 if (!inst_id_map.contains(next_inst))
342 inst_id_map.put(next_inst, inst_counter++);
345 curr_pred->incr_expl_count();
348 if (curr_pred->get_exit() == NULL) {
349 // Exit predicate is unset yet
350 curr_pred->set_exit(predicate_tree_exit);
353 leaves_tmp_storage.push_back(curr_pred);
354 update_predicate_tree_weight();
357 /* Given curr_pred and next_inst, find the branch following curr_pred that
358 * contains next_inst and the correct predicate.
359 * @return true if branch found, false otherwise.
361 bool FuncNode::follow_branch(Predicate ** curr_pred, FuncInst * next_inst,
362 ModelAction * next_act, Predicate ** unset_predicate)
364 /* Check if a branch with func_inst and corresponding predicate exists */
365 bool branch_found = false;
366 ModelVector<Predicate *> * branches = (*curr_pred)->get_children();
367 for (uint i = 0;i < branches->size();i++) {
368 Predicate * branch = (*branches)[i];
369 if (branch->get_func_inst() != next_inst)
372 /* Check against predicate expressions */
373 bool predicate_correct = true;
374 PredExprSet * pred_expressions = branch->get_pred_expressions();
376 /* Only read and rmw actions my have unset predicate expressions */
377 if (pred_expressions->getSize() == 0) {
378 predicate_correct = false;
379 if (*unset_predicate == NULL)
380 *unset_predicate = branch;
387 PredExprSetIter * pred_expr_it = pred_expressions->iterator();
388 while (pred_expr_it->hasNext()) {
389 pred_expr * pred_expression = pred_expr_it->next();
390 uint64_t last_read, next_read;
393 switch(pred_expression->token) {
395 predicate_correct = true;
398 FuncInst * to_be_compared;
399 ModelAction * last_act;
401 to_be_compared = pred_expression->func_inst;
402 last_act = to_be_compared->get_associated_act(marker);
404 last_read = last_act->get_reads_from_value();
405 next_read = next_act->get_reads_from_value();
406 equality = (last_read == next_read);
407 if (equality != pred_expression->value)
408 predicate_correct = false;
412 next_read = next_act->get_reads_from_value();
413 // TODO: implement likely to be null
414 equality = ( (void*) (next_read & 0xffffffff) == NULL);
415 if (equality != pred_expression->value)
416 predicate_correct = false;
419 predicate_correct = false;
420 model_print("unkown predicate token\n");
427 if (predicate_correct) {
437 /* Infer predicate expressions, which are generated in FuncNode::generate_predicates */
438 void FuncNode::infer_predicates(FuncInst * next_inst, ModelAction * next_act,
439 SnapVector<struct half_pred_expr *> * half_pred_expressions)
441 void * loc = next_act->get_location();
443 if (next_inst->is_read()) {
445 if ( loc_act_map.contains(loc) ) {
446 ModelAction * last_act = loc_act_map.get(loc);
447 FuncInst * last_inst = get_inst(last_act);
448 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
449 half_pred_expressions->push_back(expression);
450 } else if ( next_inst->is_single_location() ) {
451 loc_set_t * loc_may_equal = loc_may_equal_map->get(loc);
453 if (loc_may_equal != NULL) {
454 loc_set_iter * loc_it = loc_may_equal->iterator();
455 while (loc_it->hasNext()) {
456 void * neighbor = loc_it->next();
457 if (loc_act_map.contains(neighbor)) {
458 ModelAction * last_act = loc_act_map.get(neighbor);
459 FuncInst * last_inst = get_inst(last_act);
461 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
462 half_pred_expressions->push_back(expression);
469 // next_inst is not single location
470 uint64_t read_val = next_act->get_reads_from_value();
472 // only infer NULLITY predicate when it is actually NULL.
473 if ( (void*)read_val == NULL) {
474 struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
475 half_pred_expressions->push_back(expression);
480 // TODO: do anything here?
484 /* Able to generate complex predicates when there are multiple predciate expressions */
485 void FuncNode::generate_predicates(Predicate * curr_pred, FuncInst * next_inst,
486 SnapVector<struct half_pred_expr *> * half_pred_expressions)
488 if (half_pred_expressions->size() == 0) {
489 Predicate * new_pred = new Predicate(next_inst);
490 curr_pred->add_child(new_pred);
491 new_pred->set_parent(curr_pred);
493 /* Maintain predicate leaves */
494 predicate_leaves.add(new_pred);
495 predicate_leaves.remove(curr_pred);
497 /* entry predicates and predicates containing pure write actions
498 * have no predicate expressions */
499 if ( curr_pred->is_entry_predicate() )
500 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
501 else if (next_inst->is_write()) {
502 /* next_inst->is_write() <==> pure writes */
503 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
509 SnapVector<Predicate *> predicates;
511 struct half_pred_expr * half_expr = (*half_pred_expressions)[0];
512 predicates.push_back(new Predicate(next_inst));
513 predicates.push_back(new Predicate(next_inst));
515 predicates[0]->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
516 predicates[1]->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
518 for (uint i = 1;i < half_pred_expressions->size();i++) {
519 half_expr = (*half_pred_expressions)[i];
521 uint old_size = predicates.size();
522 for (uint j = 0;j < old_size;j++) {
523 Predicate * pred = predicates[j];
524 Predicate * new_pred = new Predicate(next_inst);
525 new_pred->copy_predicate_expr(pred);
527 pred->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
528 new_pred->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
530 predicates.push_back(new_pred);
534 for (uint i = 0;i < predicates.size();i++) {
535 Predicate * pred= predicates[i];
536 curr_pred->add_child(pred);
537 pred->set_parent(curr_pred);
539 /* Add new predicate leaves */
540 predicate_leaves.add(pred);
543 /* Remove predicate node that has children */
544 predicate_leaves.remove(curr_pred);
546 /* Free memories allocated by infer_predicate */
547 for (uint i = 0;i < half_pred_expressions->size();i++) {
548 struct half_pred_expr * tmp = (*half_pred_expressions)[i];
553 /* Amend predicates that contain no predicate expressions. Currenlty only amend with NULLITY predicates */
554 bool FuncNode::amend_predicate_expr(Predicate * curr_pred, FuncInst * next_inst, ModelAction * next_act)
556 ModelVector<Predicate *> * children = curr_pred->get_children();
558 Predicate * unset_pred = NULL;
559 for (uint i = 0;i < children->size();i++) {
560 Predicate * child = (*children)[i];
561 if (child->get_func_inst() == next_inst) {
567 uint64_t read_val = next_act->get_reads_from_value();
569 // only generate NULLITY predicate when it is actually NULL.
570 if ( !next_inst->is_single_location() && (void*)read_val == NULL ) {
571 Predicate * new_pred = new Predicate(next_inst);
573 curr_pred->add_child(new_pred);
574 new_pred->set_parent(curr_pred);
576 unset_pred->add_predicate_expr(NULLITY, NULL, false);
577 new_pred->add_predicate_expr(NULLITY, NULL, true);
585 void FuncNode::add_to_val_loc_map(uint64_t val, void * loc)
587 loc_set_t * locations = val_loc_map->get(val);
589 if (locations == NULL) {
590 locations = new loc_set_t();
591 val_loc_map->put(val, locations);
594 update_loc_may_equal_map(loc, locations);
596 // values_may_read_from->add(val);
599 void FuncNode::add_to_val_loc_map(value_set_t * values, void * loc)
604 value_set_iter * it = values->iterator();
605 while (it->hasNext()) {
606 uint64_t val = it->next();
607 add_to_val_loc_map(val, loc);
613 void FuncNode::update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations)
615 if ( old_locations->contains(new_loc) )
618 loc_set_t * neighbors = loc_may_equal_map->get(new_loc);
620 if (neighbors == NULL) {
621 neighbors = new loc_set_t();
622 loc_may_equal_map->put(new_loc, neighbors);
625 loc_set_iter * loc_it = old_locations->iterator();
626 while (loc_it->hasNext()) {
627 // new_loc: { old_locations, ... }
628 void * member = loc_it->next();
629 neighbors->add(member);
631 // for each i in old_locations, i : { new_loc, ... }
632 loc_set_t * _neighbors = loc_may_equal_map->get(member);
633 if (_neighbors == NULL) {
634 _neighbors = new loc_set_t();
635 loc_may_equal_map->put(member, _neighbors);
637 _neighbors->add(new_loc);
643 /* Every time a thread enters a function, set its position to the predicate tree entry */
644 void FuncNode::init_predicate_tree_position(thread_id_t tid)
646 int thread_id = id_to_int(tid);
647 if (predicate_tree_position.size() <= (uint) thread_id)
648 predicate_tree_position.resize(thread_id + 1);
650 predicate_tree_position[thread_id] = predicate_tree_entry;
653 void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred)
655 int thread_id = id_to_int(tid);
656 predicate_tree_position[thread_id] = pred;
659 /* @return The position of a thread in a predicate tree */
660 Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid)
662 int thread_id = id_to_int(tid);
663 return predicate_tree_position[thread_id];
666 /* Make sure elements of thrd_inst_act_map are initialized properly when threads enter functions */
667 void FuncNode::init_inst_act_map(thread_id_t tid)
669 int thread_id = id_to_int(tid);
670 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
671 uint old_size = thrd_inst_act_map->size();
673 if (thrd_inst_act_map->size() <= (uint) thread_id) {
674 uint new_size = thread_id + 1;
675 thrd_inst_act_map->resize(new_size);
677 for (uint i = old_size;i < new_size;i++)
678 (*thrd_inst_act_map)[i] = new inst_act_map_t(128);
682 /* Reset elements of thrd_inst_act_map when threads exit functions */
683 void FuncNode::reset_inst_act_map(thread_id_t tid)
685 int thread_id = id_to_int(tid);
686 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
688 inst_act_map_t * map = (*thrd_inst_act_map)[thread_id];
692 void FuncNode::update_inst_act_map(thread_id_t tid, ModelAction * read_act)
694 int thread_id = id_to_int(tid);
695 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
697 inst_act_map_t * map = (*thrd_inst_act_map)[thread_id];
698 FuncInst * read_inst = get_inst(read_act);
699 map->put(read_inst, read_act);
702 inst_act_map_t * FuncNode::get_inst_act_map(thread_id_t tid)
704 int thread_id = id_to_int(tid);
705 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
707 return (*thrd_inst_act_map)[thread_id];
710 /* Add FuncNodes that this node may follow */
711 void FuncNode::add_out_edge(FuncNode * other)
713 if ( !edge_table.contains(other) ) {
714 edge_table.put(other, OUT_EDGE);
715 out_edges.push_back(other);
719 edge_type_t edge = edge_table.get(other);
720 if (edge == IN_EDGE) {
721 edge_table.put(other, BI_EDGE);
722 out_edges.push_back(other);
726 /* Compute the distance between this FuncNode and the target node.
727 * Return -1 if the target node is unreachable or the actual distance
728 * is greater than max_step.
730 int FuncNode::compute_distance(FuncNode * target, int max_step)
734 else if (target == this)
737 SnapList<FuncNode *> queue;
738 HashTable<FuncNode *, int, uintptr_t, 0> distances(128);
740 queue.push_back(this);
741 distances.put(this, 0);
743 while (!queue.empty()) {
744 FuncNode * curr = queue.front();
746 int dist = distances.get(curr);
748 if (max_step <= dist)
751 ModelList<FuncNode *> * outEdges = curr->get_out_edges();
752 mllnode<FuncNode *> * it;
753 for (it = outEdges->begin();it != NULL;it = it->getNext()) {
754 FuncNode * out_node = it->getVal();
756 /* This node has not been visited before */
757 if ( !distances.contains(out_node) ) {
758 if (out_node == target)
761 queue.push_back(out_node);
762 distances.put(out_node, dist + 1);
767 /* Target node is unreachable */
771 void FuncNode::add_failed_predicate(Predicate * pred)
773 failed_predicates.add(pred);
776 /* Implement quick sort to sort leaves before assigning base scores */
777 template<typename _Tp>
778 static int partition(ModelVector<_Tp *> * arr, int low, int high)
780 unsigned int pivot = (*arr)[high] -> get_depth();
783 for (int j = low;j <= high - 1;j ++) {
784 if ( (*arr)[j] -> get_depth() < pivot ) {
786 _Tp * tmp = (*arr)[i];
787 (*arr)[i] = (*arr)[j];
792 _Tp * tmp = (*arr)[i + 1];
793 (*arr)[i + 1] = (*arr)[high];
799 /* Implement quick sort to sort leaves before assigning base scores */
800 template<typename _Tp>
801 static void quickSort(ModelVector<_Tp *> * arr, int low, int high)
804 int pi = partition(arr, low, high);
806 quickSort(arr, low, pi - 1);
807 quickSort(arr, pi + 1, high);
811 void FuncNode::assign_initial_weight()
813 PredSetIter * it = predicate_leaves.iterator();
814 leaves_tmp_storage.clear();
816 while (it->hasNext()) {
817 Predicate * pred = it->next();
818 double weight = 100.0 / sqrt(pred->get_expl_count() + pred->get_fail_count() + 1);
819 pred->set_weight(weight);
820 leaves_tmp_storage.push_back(pred);
824 quickSort(&leaves_tmp_storage, 0, leaves_tmp_storage.size() - 1);
826 // assign scores for internal nodes;
827 while ( !leaves_tmp_storage.empty() ) {
828 Predicate * leaf = leaves_tmp_storage.back();
829 leaves_tmp_storage.pop_back();
831 Predicate * curr = leaf->get_parent();
832 while (curr != NULL) {
833 if (curr->get_weight() != 0) {
838 ModelVector<Predicate *> * children = curr->get_children();
839 double weight_sum = 0;
840 bool has_unassigned_node = false;
842 for (uint i = 0;i < children->size();i++) {
843 Predicate * child = (*children)[i];
845 // If a child has unassigned weight
846 double weight = child->get_weight();
848 has_unassigned_node = true;
851 weight_sum += weight;
854 if (!has_unassigned_node) {
855 double average_weight = (double) weight_sum / (double) children->size();
856 double weight = average_weight * pow(0.9, curr->get_depth());
857 curr->set_weight(weight);
861 curr = curr->get_parent();
866 void FuncNode::update_predicate_tree_weight()
869 // Predicate tree is initially built
870 assign_initial_weight();
874 weight_debug_vec.clear();
876 PredSetIter * it = failed_predicates.iterator();
877 while (it->hasNext()) {
878 Predicate * pred = it->next();
879 leaves_tmp_storage.push_back(pred);
882 failed_predicates.reset();
884 quickSort(&leaves_tmp_storage, 0, leaves_tmp_storage.size() - 1);
885 for (uint i = 0;i < leaves_tmp_storage.size();i++) {
886 Predicate * pred = leaves_tmp_storage[i];
887 double weight = 100.0 / sqrt(pred->get_expl_count() + pred->get_fail_count() + 1);
888 pred->set_weight(weight);
891 // Update weights in internal nodes
892 while ( !leaves_tmp_storage.empty() ) {
893 Predicate * leaf = leaves_tmp_storage.back();
894 leaves_tmp_storage.pop_back();
896 Predicate * curr = leaf->get_parent();
897 while (curr != NULL) {
898 ModelVector<Predicate *> * children = curr->get_children();
899 double weight_sum = 0;
900 bool has_unassigned_node = false;
902 for (uint i = 0;i < children->size();i++) {
903 Predicate * child = (*children)[i];
905 double weight = child->get_weight();
907 weight_sum += weight;
908 else if ( predicate_leaves.contains(child) ) {
909 // If this child is a leaf
910 double weight = 100.0 / sqrt(child->get_expl_count() + 1);
911 child->set_weight(weight);
912 weight_sum += weight;
914 has_unassigned_node = true;
915 weight_debug_vec.push_back(child); // For debugging purpose
920 if (!has_unassigned_node) {
921 double average_weight = (double) weight_sum / (double) children->size();
922 double weight = average_weight * pow(0.9, curr->get_depth());
923 curr->set_weight(weight);
927 curr = curr->get_parent();
931 for (uint i = 0;i < weight_debug_vec.size();i++) {
932 Predicate * tmp = weight_debug_vec[i];
933 ASSERT( tmp->get_weight() != 0 );
937 void FuncNode::print_predicate_tree()
939 model_print("digraph function_%s {\n", func_name);
940 predicate_tree_entry->print_pred_subtree();
941 predicate_tree_exit->print_predicate();
942 model_print("}\n"); // end of graph