box naive_icp::solve(box b, contractor & ctc, scoped_vec<shared_ptr<constraint>> const & ctrs, SMTConfig & config, BranchHeuristic& brancher) { thread_local static unordered_set<shared_ptr<constraint>> used_constraints; used_constraints.clear(); thread_local static vector<box> solns; thread_local static vector<box> box_stack; solns.clear(); box_stack.clear(); box_stack.push_back(b); do { DREAL_LOG_INFO << "naive_icp::solve - loop" << "\t" << "box stack Size = " << box_stack.size(); b = box_stack.back(); box_stack.pop_back(); prune(b, ctc, config, used_constraints); if (!b.is_empty()) { if (config.nra_use_stat) { config.nra_stat.increase_branch(); } vector<int> sorted_dims = brancher.sort_branches(b, ctrs, config); if (sorted_dims.size() > 0) { int const i = sorted_dims[0]; tuple<int, box, box> splits = b.bisect_at(sorted_dims[0]); box const & first = get<1>(splits); box const & second = get<2>(splits); assert(first.get_idx_last_branched() == i); assert(second.get_idx_last_branched() == i); if (second.is_bisectable()) { box_stack.push_back(second); box_stack.push_back(first); } else { box_stack.push_back(first); box_stack.push_back(second); } if (config.nra_proof) { config.nra_proof_out << "[branched on " << b.get_name(i) << "]" << endl; } } else { config.nra_found_soln++; if (config.nra_multiple_soln > 1) { // If --multiple_soln is used output_solution(b, config, config.nra_found_soln); } if (config.nra_found_soln >= config.nra_multiple_soln) { break; } solns.push_back(b); } } } while (box_stack.size() > 0); ctc.set_used_constraints(used_constraints); if (config.nra_multiple_soln > 1 && solns.size() > 0) { return solns.back(); } else { assert(!b.is_empty() || box_stack.size() == 0); return b; } }
box multiprune_icp::solve(box b, contractor & ctc, scoped_vec<shared_ptr<constraint>> const & ctrs, SMTConfig & config, BranchHeuristic& brancher, unsigned num_try) { #define PRUNEBOX(x) prune((x), ctc, config, used_constraints) thread_local static unordered_set<shared_ptr<constraint>> used_constraints; used_constraints.clear(); thread_local static vector<box> solns; thread_local static vector<box> box_stack; solns.clear(); box_stack.clear(); PRUNEBOX(b); box_stack.push_back(b); do { DREAL_LOG_INFO << "multiprune_icp::solve - loop" << "\t" << "box stack Size = " << box_stack.size(); b = box_stack.back(); box_stack.pop_back(); if (!b.is_empty()) { vector<int> sorted_dims = brancher.sort_branches(b, ctrs, config); if (sorted_dims.size() > num_try) { sorted_dims = vector<int>(sorted_dims.begin(), sorted_dims.begin()+num_try); } if (config.nra_use_stat) { config.nra_stat.increase_branch(); } if (sorted_dims.size() > 0) { int bisectdim = -1; box first = b; box second = b; double score = -INFINITY; for (int dim : sorted_dims) { tuple<int, box, box> splits = b.bisect_at(dim); box a1 = get<1>(splits); box a2 = get<2>(splits); PRUNEBOX(a1); PRUNEBOX(a2); double cscore = -a1.volume() * a2.volume(); if (cscore > score || bisectdim == -1) { first.hull(second); a1.intersect(first); a2.intersect(first); first = a1; second = a2; bisectdim = dim; score = cscore; } else { a1.hull(a2); first.intersect(a1); second.intersect(a1); } } assert(bisectdim != -1); assert(first.get_idx_last_branched() == bisectdim); assert(second.get_idx_last_branched() == bisectdim); if (second.is_bisectable()) { box_stack.push_back(second); box_stack.push_back(first); } else { box_stack.push_back(first); box_stack.push_back(second); } if (config.nra_proof) { config.nra_proof_out << "[branched on " << b.get_name(bisectdim) << "]" << endl; } } else { config.nra_found_soln++; if (config.nra_multiple_soln > 1) { // If --multiple_soln is used output_solution(b, config, config.nra_found_soln); } if (config.nra_found_soln >= config.nra_multiple_soln) { break; } solns.push_back(b); } } } while (box_stack.size() > 0); ctc.set_used_constraints(used_constraints); if (config.nra_multiple_soln > 1 && solns.size() > 0) { return solns.back(); } else { assert(!b.is_empty() || box_stack.size() == 0); return b; } #undef PRUNEBOX }