std::vector<Conjunction> hrCandidates( std::vector<Conjunction> const& conjunctions) { boost::unordered_set<Conjunction> _present; std::set<Rule> _running; Conjunction _conjunction; for (auto i=conjunctions.begin() ; i!=conjunctions.end() ; ++i) { for (auto j=i+1 ; j!=conjunctions.end() ; ++j) { if (*i == *j) { continue; } // do the conjunction _running.clear(); _running.insert(i->begin(), i->end()); _running.insert(j->begin(), j->end()); // create a conjunction, where individual components are sorted _conjunction.clear(); _conjunction.insert(_conjunction.begin(), _running.begin(), _running.end()); // if it does not equal to none of its parents, add it if (_conjunction != *i && _conjunction != *j) { _present.insert(_conjunction); } } } std::vector<Conjunction> _result(_present.begin(), _present.end()); return _result; }
/** * コマンド送信 * * @access public * @param string cmd * @return void */ void rediscli::query(std::string cmd) { if (cmd.find(BULK_SEPARATOR) == std::string::npos) { cmd += BULK_SEPARATOR; } evutil_socket_t fd = bufferevent_getfd(bev); write(fd, cmd.c_str(), cmd.length()); _result(); }
big_integer& big_integer::operator+=(big_integer const& b) { big_integer _result(0); _result.data.pop_back(); ll _balance = 0; bool _inv = false; unsigned int _length = (this->data.size() > b.data.size() ? (int) this->data.size() : (int) b.data.size()); if (this->flag == b.flag) { _result.flag = b.flag; } else { _inv = true; if ((*this < -b and b.flag) or (-*this > b and b.flag == 0)) { _result.flag = true; } } for (int i = 0; i < (int)_length; ++i) { ll aa = i < (ll)data.size() ? data[i] : 0; if (_result.flag ^ flag and _inv) aa = -aa; ll bb = i < (ll)b.data.size() ? b.data[i] : 0; if (_result.flag ^ b.flag and _inv) bb = -bb; _result.data.push_back((ui)((ll)mod + aa + bb + _balance) % mod); if (aa + bb + _balance < 0) { _balance = -1; } else if ((ui)((aa + bb + _balance) / mod)) { _balance = 1; } else { _balance = 0; } } _result.data.push_back((ui)_balance); while (!_result.data[_result.data.size() - 1] and _result.data.size() != 1) _result.data.pop_back(); *this = _result; return *this; }
std::vector<Conjunction> hpCandidates( std::vector<Conjunction> const& conjunctions, double const probability=0.1) { boost::unordered_set<Conjunction> _present; std::set<Rule> _running; Conjunction _conjunction; // randomness boost::mt19937 gen; double probs[] = {probability, 1-probability}; boost::random::discrete_distribution<> dist(probs); for (auto i=conjunctions.begin() ; i!=conjunctions.end() ; ++i) { //if (dist(gen) == 1) { // create a new pair with probability // continue; //} for (auto j=i+1 ; j!=conjunctions.end() ; ++j) { if (*i == *j) { continue; } // do the conjunction intersection _running.clear(); _running.insert(i->begin(), i->end()); for (auto k=j->begin() ; k!=j->end() ; ++k) { _running.erase(*k); } if (_running.size() == 0) { continue; // do not allow rule which matches everything } // create a conjunction, where individual components are sorted _conjunction.clear(); _conjunction.insert(_conjunction.begin(), _running.begin(), _running.end()); // if it does not equal to none of its parents, add it if (_conjunction != *i && _conjunction != *j) { _present.insert(_conjunction); } } } std::vector<Conjunction> _result(_present.begin(), _present.end()); return _result; }
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) { if (!m.is_term_ite(f)) return BR_FAILED; expr_ref new_ite(m); new_ite = m.mk_app(f, num, args); expr_ref new_def(m); proof_ref new_def_pr(m); app_ref _result(m); if (m_defined_names.mk_name(new_ite, new_def, new_def_pr, _result, result_pr)) { m_set->assert_expr(new_def, new_def_pr); m_num_fresh++; if (m_produce_models) { if (!m_mc) m_mc = alloc(filter_model_converter, m); m_mc->insert(_result->get_decl()); } } result = _result.get(); return BR_DONE; }
float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p12, bool handleNested ) { CV_INSTRUMENT_REGION(); Mat p1 = _p1.getMat(), p2 = _p2.getMat(); CV_Assert( p1.depth() == CV_32S || p1.depth() == CV_32F ); CV_Assert( p2.depth() == CV_32S || p2.depth() == CV_32F ); int n = p1.checkVector(2, p1.depth(), true); int m = p2.checkVector(2, p2.depth(), true); CV_Assert( n >= 0 && m >= 0 ); if( n < 2 || m < 2 ) { _p12.release(); return 0.f; } AutoBuffer<Point2f> _result(n*2 + m*2 + 1); Point2f *fp1 = _result.data(), *fp2 = fp1 + n; Point2f* result = fp2 + m; int orientation = 0; for( int k = 1; k <= 2; k++ ) { Mat& p = k == 1 ? p1 : p2; int len = k == 1 ? n : m; Point2f* dst = k == 1 ? fp1 : fp2; Mat temp(p.size(), CV_MAKETYPE(CV_32F, p.channels()), dst); p.convertTo(temp, CV_32F); CV_Assert( temp.ptr<Point2f>() == dst ); Point2f diff0 = dst[0] - dst[len-1]; for( int i = 1; i < len; i++ ) { double s = diff0.cross(dst[i] - dst[i-1]); if( s != 0 ) { if( s < 0 ) { orientation++; flip( temp, temp, temp.rows > 1 ? 0 : 1 ); } break; } } } float area = 0.f; int nr = intersectConvexConvex_(fp1, n, fp2, m, result, &area); if( nr == 0 ) { if( !handleNested ) { _p12.release(); return 0.f; } if( pointPolygonTest(_InputArray(fp1, n), fp2[0], false) >= 0 ) { result = fp2; nr = m; } else if( pointPolygonTest(_InputArray(fp2, m), fp1[0], false) >= 0 ) { result = fp1; nr = n; } else { _p12.release(); return 0.f; } area = (float)contourArea(_InputArray(result, nr), false); } if( _p12.needed() ) { Mat temp(nr, 1, CV_32FC2, result); // if both input contours were reflected, // let's orient the result as the input vectors if( orientation == 2 ) flip(temp, temp, 0); temp.copyTo(_p12); } return (float)fabs(area); }