float racoR(Element x[SIZE][SIZE],int n,int k[2*SIZE],int t,int arr[2],float best,int fl) { float d1,d2,p,q,sum[2] ; int p1[2*SIZE],p2[2*SIZE],i,a,b ; sum[0] = 0; sum[1] = 0; int l[SIZE],m[SIZE],g[2],h[2]; d1 = optTSPr(x,n,k,1,arr,MAX,(fl/20)); d1 = optTSPr(x,n,k,(3*t/5),arr,best,fl); /*for(i=0;i<2*n;i++) d[i]=k[i];*/ if(n>70) { Element A[SIZE][SIZE],B[SIZE][SIZE]; float check =0; int r=0; partitionR(x,n,k,A,B,l,m,g,h,sum); sum[1] += d1 ; printf("\n total = %f , sum[0] = %f ,sum[1] =%f \n",d1,sum[0],sum[1]) ; if(n%2==0) a= n/2; else a = (n/2 + 1); b = (int)(0.65*t) ; p=racoR(A,(n/2),p1,b,g,sum[0],(fl*2)); opt2(A,(n/2),p1,p,g); q=racoR(B,a,p2,b,h,sum[1],(fl*2)); opt2(B,a,p2,q,h); join(x,n,A,B,l,m); printf(" \n values of rec are %f , %f " ,p,q); /* check = p + q ; if(check < (sum[0] + sum[1])) { printf(" check = %f,p = %f q = %f ",check,p,q); for(i=0;i<n;i++) { k[i] = l[p1[i]]; } k[n] = l[p1[n-1]] ; printf(" p1[n-1] = %d k[n-1] =%d",l[p1[n-1]],k[n-1]); k[n+1] = m[p2[0]] ; for(i = n+2;i< 2*n;i++) { k[i] = m[p2[(i-n-2)]]; } d1 = check + x[l[p1[n-1]]][m[p2[0]]].e ; } */ } d2 = optTSPr(x,n,k,(int)(2*t/5),arr,d1,fl); if(d1<d2) { printf(" d1 = %f ",d1) ; return d1; } else { /*for(i=0;i<2*n;i++) k[i]=d[i];*/ return d2; } }
int ft_option_printf(va_list ap, char *c, int *i, t_specs opt) { char *str; wchar_t *wstr; int r; str = NULL; wstr = NULL; if (c[*i] == 'c' && !(opt.modif & 0x04)) str = ft_option_c(ap); else if (c[*i] == 'C' || (c[*i] == 'c' && opt.modif & 0x04)) wstr = ft_option_big_c(ap); else if (verif_str("bkqtQfFegdDiEGpoOuUxX", c[*i])) str = treat_convs(ap, opt, c, i); else if (c[*i] == 's' && !(opt.modif & 0x04)) str = treat_conv_s(ap, opt, c, i); else if ((c[*i] == 'S' || (c[*i] == 's' && opt.modif & 0x04))) wstr = treat_conv_big_s(ap, opt, c, i); else str = treat_else(opt, c, i); if (c[*i] == 'c' && !(opt.modif & 0x04) && (r = opt2(opt, c, i, &str)) > 0) return (r); else if ((c[*i] == 'C' || ((c[*i] == 'c') && opt.modif & 0x04)) && (r = ft_option_big_c2(opt, c, i, &wstr)) > 0) return (r); split_if(str, &i); return ((r = split_if2(&wstr, i)) ? r : (int)ft_strlen(str)); }
void solve_tsp(graph g, size_t *tour) { // fputs("\n", stderr); /* for(size_t i = 0; i < g.n; ++i) tour[i] = i; shuffle(tour, g.n);*/ for(size_t i = 0; i < g.n; ++i) tour[i] = greedy_tour[i]; // print_tour(g, tour); size_t nexts[g.n]; for(size_t i = 0; i < g.n-1; ++i) { nexts[tour[i]] = tour[i+1]; } nexts[tour[g.n-1]] = tour[0]; //for(int i = 0; i < 100; ++i) // if(!opt2(g, nexts)) // break; // for(size_t i = 0; i < g.n; ++i) // half_opt(g, nexts, i); while(opt2(g, nexts, rand() % g.n)); // for(size_t apa = 0; apa < 2; ++apa) for(size_t i = 0; i < g.n; ++i) half_opt(g, nexts, i); while(opt2(g, nexts, rand() % g.n)); // for(size_t apa = 0; apa < 2; ++apa) for(size_t i = 0; i < g.n; ++i) half_opt(g, nexts, i); // ll => tour size_t next = 0; while(true) { *tour++ = next; next = nexts[next]; if(next == 0) break; } }
help() { char *menu[]={"How To Play","Selecting Option","Credits","About Me","Back"}; int w=0,k,g=130,h=200; setbkcolor(0); settextstyle(3,0,3); setpos(0,0); viewport(); settextstyle(7,0,5); setcolor(14); outtextxy(245,100,"HELP"); settextstyle(1,0,2); setcolor(8); for(k=0;k<5;k++) { outtextxy(g,h,menu[k]); h+=textheight(menu[k])+10; } setpos(0,0); status("Select Any one using mouse pointer"); while(1) { pos(&button,&n,&m); w=opt2(n,m); settextstyle(1,0,2); g=130; h=200; for(k=0;k<5;k++) { if(w==k+1) { setcolor(11); outtextxy(g,h,menu[k]); h+=textheight(menu[k])+10; if(button==1) return w; } else { setcolor(8); outtextxy(g,h,menu[k]); h+=textheight(menu[k])+10; } } if(kbhit()) goto pr; } // getch(); pr: return 0; }
/*! * \brief Recherche locale pour ameliorer la solution * * Cette fonction applique les mouvements precedement codes lorsque c'est possible. Toutes les places sont testees. * * \param instance : instance sur laquelle on travaille. */ void Solution::rechercheLocale(Instance * instance) { bool cont = true; Solution * bestSol = new Solution(); bestSol->copySol(this); unsigned bestTime = _dateFin, bestNbTour = _first.size(), bestTTime = _sommeDureeTournee; float bestDist = _distParcourue; for (unsigned tour1 = 0; tour1 < _first.size(); ++tour1) { for (unsigned tour2 = tour1; tour2 < _first.size(); ++tour2) { for (unsigned cl1 = _first[tour1]; cl1 != 0; cl1 = _succ[cl1]) { for (unsigned cl2 = _first[tour2]; cl2 != 0; cl2 = _succ[cl2]) { if (cl1 != cl2) { cont = true; if (cont && tour1 != tour2 && opt2(cl1, tour1, cl2, tour2, instance) != -1) { computeDateDist(instance); if (_dateFin < bestTime || _distParcourue < bestDist || _first.size() < bestNbTour) { bestTime = std::min(_dateFin, bestTime); bestTTime = std::min(_sommeDureeTournee, bestTTime); bestDist = std::min(_distParcourue, bestDist); bestNbTour = std::min(_first.size(), bestNbTour); bestSol->copySol(this); cont = false; // on recommence quand on a change quelque chose! tour1 = 0; tour2 = 1; cl1 = _first[0]; cl2 = _first[1]; } else { copySol(bestSol); } } else { copySol(bestSol); } if (cont && swap(cl1, tour1, cl2, tour2, instance) != -1) { computeDateDist(instance); if (_dateFin < bestTime || _distParcourue < bestDist || _first.size() < bestNbTour) { bestTime = std::min(_dateFin, bestTime); bestTTime = std::min(_sommeDureeTournee, bestTTime); bestDist = std::min(_distParcourue, bestDist); bestNbTour = std::min(_first.size(), bestNbTour); bestSol->copySol(this); cont = false; // on recommence quand on a change quelque chose! tour1 = 0; tour2 = 1; cl1 = _first[0]; cl2 = _first[1]; } else { copySol(bestSol); } } else { copySol(bestSol); } if (cont && shift(cl1, tour1, cl2, tour2, instance, false) != -1) { computeDateDist(instance); if (_dateFin < bestTime || _distParcourue < bestDist || _first.size() < bestNbTour) { bestTime = std::min(_dateFin, bestTime); bestTTime = std::min(_sommeDureeTournee, bestTTime); bestDist = std::min(_distParcourue, bestDist); bestNbTour = std::min(_first.size(), bestNbTour); bestSol->copySol(this); cont = false; // on recommence quand on a change quelque chose! tour1 = 0; tour2 = 1; cl1 = _first[0]; cl2 = _first[1]; } else { copySol(bestSol); } } else { copySol(bestSol); } if (cont && shift(cl1, tour1, cl2, tour2, instance, true) != -1) { computeDateDist(instance); if (_dateFin < bestTime || _distParcourue < bestDist || _first.size() < bestNbTour) { bestTime = std::min(_dateFin, bestTime); bestTTime = std::min(_sommeDureeTournee, bestTTime); bestDist = std::min(_distParcourue, bestDist); bestNbTour = std::min(_first.size(), bestNbTour); bestSol->copySol(this); cont = false; // on recommence quand on a change quelque chose! tour1 = 0; tour2 = 1; cl1 = _first[0]; cl2 = _first[1]; } else { copySol(bestSol); } } else { copySol(bestSol); } } } } } } }
int main(int argc,char **argv) { log4cxx::PropertyConfigurator::configure("../comm/log4cxx.properties"); //插入非数值型数据 std::string dbname1 = "test"; std::string collection_name1 = "kelp"; try{ kelp::MongoOperator opt(dbname1,collection_name1); std::string key = "handsome"; std::string value = "Chenjian"; opt.Insert(key,value);//非数值型数据 value = "ChenChen"; mongo::BSONObj key_value =BSON(key<<value); opt.Insert(key_value); //插入bool型数据 bool bool_value = "true"; for(int i = 0;i < 10; i++) opt.Insert(key,bool_value); //查询非数值型数据,测试键值对查询方式 mongo::BSONObj query_condition = BSON(key<<value); std::vector<mongo::BSONObj>query_outcome; opt.QueryData(query_condition,query_outcome); for(std::vector<mongo::BSONObj> ::iterator it =query_outcome.begin();it!=query_outcome.end();++it) std::cout << (*it).toString() << std::endl; } catch(std::runtime_error &r) { std::cout << r.what() << std::endl; return -1; } //插入数值型数据,测试非键值对插入方式 std::string dbname2 = "test"; std::string collection_name2 = "xuxijian"; try{ kelp::MongoOperator opt2(dbname2,collection_name2); std::string double_key = "id"; int value_size = 5; double double_value[5] = {10086.12345,12.332,76.12,521.123,67.2234}; for(int i = 0;i < value_size;i++) opt2.Insert(double_key,double_value[i]); //查询数值数据 std::vector<mongo::BSONObj>query_outcome_2; mongo::BSONObj query_condition = BSON(double_key<<double_value[0]); opt2.QueryData(query_condition,query_outcome_2); for(std::vector<mongo::BSONObj> ::iterator it =query_outcome_2.begin();it!=query_outcome_2.end();++it) std::cout << (*it).toString() << std::endl; //插入图片 //const std::string filename = "~/Kelp/src/comm/test.jpg"; //opt2.Insert(filename); } catch(std::runtime_error &r) { std::cout << r.what() <<std::endl; return -1; } return 0; }
void Style::drawComplexControl ( ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget ) const { if (shouldNotHandle(widget)) { QProxyStyle::drawComplexControl(control, option, painter, widget); return; } switch(control) { // FIXME: this is a workaround for the WebKit bug #104116 (or a variation on it). case QStyle::CC_ScrollBar: { if (qobject_cast<const QWebView*>(widget) != 0 && option->type == QStyleOption::SO_Slider) { // WebKit tries to hide scrollbars, but mistakenly hides QWebView - NULL-ify styleObject to prevent. const QStyleOptionSlider *optSlider = static_cast<const QStyleOptionSlider*>(option); QStyleOptionSlider opt2( *optSlider ); opt2.styleObject = NULL; QProxyStyle::drawComplexControl( control, &opt2, painter, widget ); return; } } case QStyle::CC_ToolButton: { // TODO: We only draw either text, or icon, or arrow const QToolButton *toolBtn = qobject_cast<const QToolButton*>(widget); if (!toolBtn) break; Q_ASSERT(toolBtn); const QStyleOptionToolButton *toolOption = static_cast<const QStyleOptionToolButton*>(option); painter->save(); QRect r = option->rect; if (option->state & QStyle::State_On) { painter->setBrush( option->palette.color(QPalette::Dark) ); painter->setPen( option->palette.color(QPalette::Shadow) ); painter->drawRect( r.adjusted(0,0,-1,-1) ); } else { bool highlight = option->state & QStyle::State_MouseOver; if (highlight) { QColor fill = option->palette.color(QPalette::Button); painter->setBrush(fill); painter->setPen(Qt::NoPen); painter->drawRect(r.adjusted(0,0,0,-1)); } if (qobject_cast<QTabBar*>(toolBtn->parent())) { if (!highlight) { QColor fill = option->palette.color(QPalette::Mid); painter->setBrush(fill); painter->setPen(Qt::NoPen); painter->drawRect(r.adjusted(0,0,0,-1)); } if (toolBtn->arrowType() == Qt::LeftArrow) { painter->setPen( option->palette.color(QPalette::Shadow) ); painter->drawLine( option->rect.topLeft(), option->rect.bottomLeft() ); } } } painter->restore(); QIcon icon = toolOption->icon; if (!icon.isNull()) { QIcon::Mode iconMode = option->state & QStyle::State_Enabled ? ( option->state & QStyle::State_MouseOver ? QIcon::Active : QIcon::Normal ) : QIcon::Disabled; QIcon::State iconState = option ->state & QStyle::State_Selected ? QIcon::On : QIcon::Off; QPixmap pixmap = icon.pixmap(toolOption->iconSize, iconMode, iconState); QRect pixRect = pixmap.rect(); pixRect.moveCenter( option->rect.center() ); painter->drawPixmap(pixRect.topLeft(), pixmap); } else { QStyle::PrimitiveElement elem = Style::PE_CustomBase; switch(toolBtn->arrowType()) { case Qt::LeftArrow: elem = PE_IndicatorArrowLeft; break; case Qt::RightArrow: elem = PE_IndicatorArrowRight; break; case Qt::DownArrow: elem = PE_IndicatorArrowDown; break; case Qt::UpArrow: elem = PE_IndicatorArrowUp; break; default: break; } if (elem != Style::PE_CustomBase) { drawPrimitive( elem, option, painter, widget ); } else if (!toolOption->text.isEmpty()) { painter->drawText( toolOption->rect, Qt::AlignCenter | Qt::TextShowMnemonic, toolOption->text ); } } return; } default: break; } QProxyStyle::drawComplexControl(control, option, painter, widget); }
void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyleOptionViewItemV4 opt = option; initStyleOption ( &opt, index ); painter->save(); painter->setClipRect ( opt.rect ); opt.features |= QStyleOptionViewItem::WrapText; opt.text = index.data().toString(); opt.textElideMode = Qt::ElideRight; opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); //const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); const int iconSize = 48; QRect iconbox = opt.rect; const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1; QRect textRect = opt.rect; QRect textHighlightRect = textRect; // clip the decoration on top, remove width padding textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 ); textHighlightRect.adjust ( 0,iconSize + 5,0,0 ); // draw background { QSize textSize = viewItemTextSize ( &opt ); QPalette::ColorGroup cg; QStyleOptionViewItemV4 opt2(opt); if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled)) { if(! ( opt.state & QStyle::State_Active )) cg = QPalette::Inactive; else cg = QPalette::Normal; } else { cg = QPalette::Disabled; } opt2.palette.setCurrentColorGroup(cg); // fill in background, if any if ( opt.backgroundBrush.style() != Qt::NoBrush ) { QPointF oldBO = painter->brushOrigin(); painter->setBrushOrigin ( opt.rect.topLeft() ); painter->fillRect ( opt.rect, opt.backgroundBrush ); painter->setBrushOrigin ( oldBO ); } if ( opt.showDecorationSelected ) { drawSelectionRect(painter,opt2, opt.rect); drawFocusRect(painter,opt2, opt.rect); //painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) ); } else { //if ( opt.state & QStyle::State_Selected ) { //QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, opt.widget ); //painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) ); drawSelectionRect(painter,opt2, textHighlightRect); drawFocusRect(painter,opt2, textHighlightRect); } } } // draw the icon { QIcon::Mode mode = QIcon::Normal; if ( ! ( opt.state & QStyle::State_Enabled ) ) mode = QIcon::Disabled; else if ( opt.state & QStyle::State_Selected ) mode = QIcon::Selected; QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; iconbox.setHeight ( iconSize ); opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state ); } // set the text colors QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) ) cg = QPalette::Inactive; if ( opt.state & QStyle::State_Selected ) { painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) ); } else { painter->setPen ( opt.palette.color ( cg, QPalette::Text ) ); } // draw the text QTextOption textOption; textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); textOption.setTextDirection ( opt.direction ); textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) ); QTextLayout textLayout; textLayout.setTextOption ( textOption ); textLayout.setFont ( opt.font ); textLayout.setText ( opt.text ); qreal width, height; viewItemTextLayout ( textLayout, iconbox.width(), height, width ); const int lineCount = textLayout.lineCount(); const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( iconbox.width(), int ( height ) ), textRect ); const QPointF position = layoutRect.topLeft(); for ( int i = 0; i < lineCount; ++i ) { const QTextLine line = textLayout.lineAt ( i ); line.draw ( painter, position ); } painter->restore(); }
// // THIS TEST SHOULD FAIL TO COMPILE // void test_no_unsupported_conversion() { boost::optional<int> opt1(1) ; boost::optional< std::string > opt2( opt1 ) ; // Cannot convert from "int" to "std::string" }
bool test_feature(const vector<accelerator>& devices) { int edata[_rank]; for (int i = 0; i < _rank; i++) edata[i] = 3; printf("Found %d devices\n", devices.size()); for (size_t i = 0; i < devices.size()-1; i++) { accelerator device1 = devices[i]; accelerator device2 = devices[i+1]; if (_rank > 0) { const int rank = 1; Concurrency::array<_type, rank> src1(edata[0], device1.get_default_view()); Concurrency::array<_type, rank> src2(edata[0], device2.get_default_view()); // let the kernel initialize data; extent<1> e1(edata); parallel_for_each(e1, [&](index<rank> idx) __GPU_ONLY { src1[idx] = _rank; src2[idx] = _rank; }); // Copy data to CPU vector<_type> opt1(e1.size()); opt1 = src1; vector<_type> opt2(e1.size()); opt2 = src2; for (unsigned int i = 0; i < e1.size(); i++) { if ((opt1[i] != _rank) || (opt2[i] != _rank)) return false; } printf ("Passed for rank %d\n", rank); rank_step = rank; } if (_rank > 1) { const int rank = 2; rank_step = rank; Concurrency::array<_type, rank> src1(edata[0], edata[1], device1.get_default_view()); Concurrency::array<_type, rank> src2(edata[0], edata[1], device2.get_default_view()); // let the kernel initialize data; extent<rank> e1(edata); parallel_for_each(e1, [&](index<rank> idx) __GPU_ONLY { src1[idx] = _rank; src2[idx] = _rank; }); // Copy data to CPU vector<_type> opt1(e1.size()); opt1 = src1; vector<_type> opt2(e1.size()); opt2 = src2; for (unsigned int i = 0; i < e1.size(); i++) { if ((opt1[i] != _rank) || (opt2[i] != _rank)) return false; } printf ("Passed for rank %d\n", rank); rank_step = rank; }