void MotionTrackerFB::drawOpticalFlow(cv::Mat& output, float maxmotion) { // determine motion range: maxrad = maxmotion; if (maxmotion <= 0) { maxrad = 1; for (int y = 0; y < flow.rows; ++y) { for (int x = 0; x < flow.cols; ++x) { cv::Point2f u = flow(y, x); if (!isFlowCorrect(u)) continue; maxrad = std::max(maxrad, (float)sqrt(u.x * u.x + u.y * u.y)); } } } for (int y = 0; y < flow.rows; ++y) { for (int x = 0; x < flow.cols; ++x) { cv::Point2f u = flow(y, x); if (isFlowCorrect(u)) output.at<cv::Vec3b>(y, x) = computeColor(u.x / maxrad, u.y / maxrad); } } }
void RK4_step( // replaces x(t) by x(t + dt) Matrix<double,1>& x, // solution vector double dt, // fixed time step Matrix<double,1> flow(Matrix<double,1>&)) // derivative vector { int n = x.size(); Matrix<double,1> f(n), k1(n), k2(n), k3(n), k4(n), x_temp(n); f = flow(x); for (int i = 0; i < n; i++) { k1[i] = dt * f[i]; x_temp[i] = x[i] + k1[i] / 2; } f = flow(x_temp); for (int i = 0; i < n; i++) { k2[i] = dt * f[i]; x_temp[i] = x[i] + k2[i] / 2; } f = flow(x_temp); for (int i = 0; i < n; i++) { k3[i] = dt * f[i]; x_temp[i] = x[i] + k3[i]; } f = flow(x_temp); for (int i = 0; i < n; i++) k4[i] = dt * f[i]; for (int i = 0; i < n; i++) x[i] += (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) / 6; }
void TerrainEroder::SingleDrop(int x,int y) { int pathlen=0; const int accumthresh=10; //accumulation threshold int soilaccum=0; //accumulated soil bool done=pathlen>=maxpathlen; while(!done) { //25% change of deposit if over threshold if(soilaccum>accumthresh) { DepositSoil(25,x,y,radius,digdepth); --soilaccum; } //else, accumulate 50% of soil surfaces encountered and 25% of rock else soilaccum+=CollectSoil(50,25,x,y,radius,digdepth); ++pathlen; visited(x,y)=true; //move to new position x+=flow(x,y).GetX(); y+=flow(x,y).GetY(); //figure out if done or not done=pathlen>=maxpathlen||x<0||y<0||x>=w||y>=l; done=done||flow(x,y)==intvector3d(0,0,0); done=done||visited(x,y); } //just follow a path defined by flow field until max path length is reached }
VideoTeror::GrayscaleImage VideoTeror::MotionDetection::FarnebackMotionDetector::detect(const GrayscaleImage &curFrame) { GrayscaleImage resized; cv::resize(curFrame, resized, cv::Size(prevFrame.cols, prevFrame.rows)); cv::Mat_<cv::Vec2f> flow(resized.rows, resized.cols); cv::calcOpticalFlowFarneback(prevFrame, resized, flow, 0.75, 3, 10, 20, 5, 1.1, 0); GrayscaleImage test; curFrame.copyTo(test); GrayscaleImage result(resized.rows, resized.cols); for (int y = 0; y < resized.rows; y++) { for (int x = 0; x < resized.cols; x++) { cv::line(test, cv::Point(x*blockSize, y*blockSize), cv::Point(x*blockSize + flow(y, x)[0]*blockSize, y*blockSize + flow(y, x)[1]*blockSize), 255); result(y, x) = 255 * (sqrt(flow(y, x)[0]*flow(y, x)[0] + flow(y, x)[1]*flow(y, x)[1])); // > threshold); } } morphClosure(result, 4); cv::imshow("test", test); resized.copyTo(prevFrame); cv::resize(result, result, cv::Size(curFrame.cols, curFrame.rows), 0, 0, cv::INTER_NEAREST); return result; }
int SharkTargetInvariants::count_monitors() { int result = 0; if (is_synchronized() || target()->has_monitor_bytecodes()) { for (int i = 0; i < flow()->block_count(); i++) { result = MAX2(result, flow()->pre_order_at(i)->monitor_count()); } } return result; }
void Assembly::next(Node node, String& out) { switch (node.type()) { case NodeType::FLOW: { auto flow = node.impl<FlowImpl>(); for (auto& i: flow->flow()) { String tmp; next(i, tmp); } } break; case NodeType::VAR: { auto v = node.impl<VarImpl>(); out = var(v->name()); if (v->term().is<IntTermImpl>()) { *this << out + " = shl i32 " + std::to_string(v->term().as<IntTermImpl>()->number()) + ", 0"; } else if (v->value().is<FuncCallImpl>()) { next(v->value(), out); } else { *this << out + " = shl i32 0, 0; Unknown type"; } } break; case NodeType::FUNC_CALL: { auto call = node.impl<FuncCallImpl>(); auto name = call->name(); if (name == "op_plus") { auto lhs = tmp(), rhs = tmp(); next(call->flow()->flow()[0], lhs); next(call->flow()->flow()[1], rhs); *this << out + " = add i32 " + lhs + ", " + rhs; } else if (name == "print") { auto out = tmp(); next(call->flow()->flow()[0], out); *this << tmp() + " = call i32 @print_i(i32 " + out + ")"; } else if (name == "op_get") { auto name = call->flow()->flow()[0]; auto name_val = name->term().as<StringTermImpl>(); out = var(name_val->str()); } } } }
void led() { unsigned char i; int s; while(i!='!') { i=_getkey(); if(i=='d') { P2=0xff; while(i!='^') { i=_getkey(); switch(i) { case '1' : led1=~led1; break; case '2' : led2=~led2; break; case '3' : led3=~led3; break; case '4' : led4=~led4; break; case '5' : led5=~led5; break; case '6' : led6=~led6; break; case '7' : led7=~led7; break; case '8' : led8=~led8; break; default : break; } } } if(i=='f') { P2=0xff; while(i!='#') { i=_getkey(); if(i!='#') { s=ssscanf(); } if(i=='u') { flow(s,1); } if(i=='b') { flow(s,2); } } } } }
main() { int i,j,k,last,d,n,T; scanf("%d",&T); while(T--) { scanf("%d",&n); t=n*2+1; for(i=0;i<=t;i++) memset(c[i],0,sizeof(c[i])); for(i=d=0;i<n;i++) { scanf("%d:%d %d %d %d %d",&j,&k,&s[i].x1,&s[i].y1,&s[i].x2,&s[i].y2); s[i].time=j*60+k+d; if(s[i].time<last)d+=1440,s[i].time+=1440; last=s[i].time; c[0][i+1]=1; c[i+n+1][t]=1; } for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(i!=j) c[i+1][j+n+1]=s[i]+s[j]; printf("%d\n",n-flow()); } }
int main() { scanf("%d",&receptacleNum); for(int i=0;i<receptacleNum;i++) { scanf("%s",receptacle[i]); graph[0][i+1]=1; pos[i]=i+1; } scanf("%d",&deviceNum); in=receptacleNum+deviceNum+1; for(int i=0;i<deviceNum;i++) { scanf("%s%s",device[i],devicePlug); graph[find(devicePlug)][in-deviceNum+i]=1; graph[in-deviceNum+i][in]=1; } scanf("%d",&adapterNum); for(int i=0;i<adapterNum;i++) { scanf("%s%s",adapter[0],adapter[1]); graph[find(adapter[1])][find(adapter[0])]=0x7FFFFFFF; } int answer=deviceNum; while(bfs()) { answer-=flow(); } printf("%d\n",answer); return 0; }
int main() { Link link("L1", 10000000, 0.01, 64000); Node node1("H1"); Node node2("H2"); NetworkManager* nm = NetworkManager::getInstance(); nm->registerLink(link); nm->registerNode(node1); nm->registerNode(node2); nm->connectLink("L1", "H1", "H2"); Flow flow("F1", "H1", "H2", 20000000, TCP_RENO_t, 1); nm->registerFlow(flow); EventQueue* eq = EventQueue::getInstance(); eq->run(); Logger * logger = Logger::getInstance(); delete logger; return EXIT_SUCCESS; }
static void cb_ready_test_suite (CutRunContext *run_context, CutTestSuite *test_suite, guint n_test_cases, guint n_tests, CutXMLStream *stream) { GString *string; gchar *str; string = g_string_new(NULL); g_string_append(string, " <ready-test-suite>\n"); cut_test_to_xml_string(CUT_TEST(test_suite), string, 4); str = g_strdup_printf("%d", n_test_cases); cut_utils_append_xml_element_with_value(string, 4, "n-test-cases", str); g_free(str); str = g_strdup_printf("%d", n_tests); cut_utils_append_xml_element_with_value(string, 4, "n-tests", str); g_free(str); g_string_append(string, " </ready-test-suite>\n"); flow(stream, "%s", string->str); g_string_free(string, TRUE); }
main() { int i,j,k,t; while(scanf("%d",&n)==1) { t=2*n+1; for(i=0;i<=t;i++) for(j=0;j<=t;j++) cap[i][j]=cost[i][j]=0; for(i=0;i<n;i++) for(j=0;j<n;j++) { scanf("%d",&cost[i+1][j+n+1]); cap[i+1][j+n+1]=1; } for(j=0;j<n;j++) { for(i=k=0;i<n;i++) k+=cost[i+1][j+n+1]; for(i=0;i<n;i++) { cost[i+1][j+n+1]=k-cost[i+1][j+n+1]; cost[j+n+1][i+1]=-cost[i+1][j+n+1]; } cap[0][j+1]=cap[j+n+1][t]=1; } t=n,n=2*n+2; printf("%d\n",flow(t)); } }
void Assembly::push(Node node) { *this << "; jt LLVM compiler production" << "" << "declare i32 @printf(i8* noalias , ...)" << "" << "@.int_print = private unnamed_addr constant [3 x i8] c\"%d\\00\"" << "" << "define i32 @print_i(i32 %a) {" << " %print_str = getelementptr [3 x i8], [3 x i8]* @.int_print, i64 0, i64 0" << " %tmp = tail call i32 (i8*, ...)* @printf(i8* %print_str, i32 %a)" << " ret i32 0" << "}"; *this << "define i32 @main() {"; auto flow = node.impl<FlowImpl>(); for (auto& i: flow->flow()) { String tmp; next(i, tmp); } *this << "ret i32 0" << "}\n"; }
AdjacencyMatrix EdmondsKarp(AdjacencyMatrix& adj, int s, int t) { AdjacencyMatrix flow(adj.size()); adj.Print(); do { AdjacencyMatrix residual = GetResidual(adj, flow); cout << "Flow:" << endl; flow.Print(); cout << "Residual:" << endl; residual.Print(); AdjacencyMatrix path(residual.size()); if(AugmentingPath(path, residual, s, t)) { cout << "Path:" << endl; path.Print(); updateFlow(flow, path, s, t); } else { break; } } while(1); return flow; }
main() { int i, j, k, a, m; while (scanf("%d %d", &n, &m) == 2) { t = n*2 + 1; for (i = 0; i < n+2; ++i) for (j = 0; j < n+2; ++j) d[i][j] = inf; while (m--) { scanf("%d %d", &i, &j); scanf("%d", &d[i][j]); } scanf("%d", &m); a = -1; for (i = 0, j = inf; i <= j; ) { k = (i + j)/2; Init(k); if (flow(m) >= m) { a = k; j = k - 1; } else i = k + 1; } printf("%d\n", a); } }
main(){ int i,j,k,C=0,st,ed,e; struct timeb before, after; double t; /* Timing start */ ftime(&before); while(scanf("%d",&n) && n>0){ for(i=1;i<=n;i++) for(j=1;j<=n;j++) f[i][j]=0; scanf("%d %d %d",&st,&ed,&e); while(e--){ scanf("%d %d %d",&i,&j,&k); f[i][j]+=k; f[j][i]+=k; } printf("Network %d\nThe bandwidth is %d.\n\n",++C,flow(st,ed)); } /* Timing ends */ ftime(&after); /* Get the elapse time between before and after */ t = elapse(&before, &after); /* Print the number of seconds between before and after */ fprintf(stderr,"The elapse time is: %lf seconds\n", t); }
main() { int i,j,m,n1,n2,t; while(scanf("%d %d",&n,&m)==2 && n+m) { for(i=n1=n2=0;i<n;i++) { scanf("%s",map[i]); for(j=0;map[i][j];j++) if(map[i][j]=='H') s1[n1++]=(pt){i,j}; else if(map[i][j]=='m') s2[n2++]=(pt){i,j}; } t=n1*2+1; for(i=0;i<=t;i++) for(j=0;j<=t;j++) cap[i][j]=cost[i][j]=0; for(i=0;i<n1;i++) cap[0][i+1]=cap[n1+i+1][t]=1; for(i=0;i<n1;i++) for(j=0;j<n2;j++) { cost[i+1][n1+j+1]=dis(s1[i],s2[j]); cost[n1+j+1][i+1]=-cost[i+1][n1+j+1]; cap[i+1][n1+j+1]=1; } n=t+1; printf("%d\n",flow(2000,1)); } }
main() { int i,j,k,n,n1,n2,m; char tmp[999]; while(scanf("%d %d %d %d",&n,&n1,&n2,&m)>0) { t=n+1; for(i=0;i<=t;i++) for(j=0;j<=t;j++) c[i][j]=0; while(m--) { scanf("%s",tmp); sscanf(tmp,"(%d,%d)%d",&i,&j,&k); c[i+1][j+1]=k; } while(n1--) { scanf("%s",tmp); sscanf(tmp,"(%d)%d",&i,&k); c[0][i+1]=k; } while(n2--) { scanf("%s",tmp); sscanf(tmp,"(%d)%d",&i,&k); c[i+1][t]=k; } printf("%d\n",flow()); } }
// Adds the miss case for the table. void fp_add_miss(fp::Table* tbl, void* fn) { // cast the flow into a flow instruction fp::Flow_instructions instr = reinterpret_cast<fp::Flow_instructions>(fn); fp::Flow flow(0, fp::Flow_counters(), instr, fp::Flow_timeouts(), 0, 0); tbl->insert_miss(flow); }
static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp) { priv_t * p = (priv_t *)effp->priv; static size_t isamp = 0; if (p->pads_pos != p->npads && p->in_pos != p->pads[p->pads_pos].start) p->in_pos = SOX_SIZE_MAX; /* Invoke the final pad (with no given start) */ return flow(effp, 0, obuf, &isamp, osamp); }
void EmbedderOptimalFlexDraw::optimizeOverEmbeddings( StaticPlanarSPQRTree &T, node parent, node mu, int bends, NodeArray<int> cost[], NodeArray<long long> embedding[]) { cost[bends][mu] = numeric_limits<int>::max(); long long embeddingsCount = T.numberOfNodeEmbeddings(mu); for (long long currentEmbedding = 0; currentEmbedding < embeddingsCount; ++currentEmbedding) { T.embed(mu, currentEmbedding); Skeleton &skeleton = T.skeleton(mu); Graph skeletonGraph = skeleton.getGraph(); ConstCombinatorialEmbedding skeletonEmbedding(skeletonGraph); NodeArray<node> vertexNode(skeletonGraph); EdgeArray<node> edgeNode(skeletonGraph); FaceArray<node> faceNode(skeletonEmbedding); Graph N; EdgeArray<int> upper(N); EdgeArray<int> perUnitCost(N); NodeArray<int> supply(N); createNetwork( parent, mu, bends, cost, embedding, skeleton, edgeNode, N, upper, perUnitCost, supply); EdgeArray<int> lower(N, 0); EdgeArray<int> flow(N); NodeArray<int> dual(N); m_minCostFlowComputer.get().call(N, lower, upper, perUnitCost, supply, flow, dual); int currentCost = 0; for (edge e = N.firstEdge(); e != nullptr; e = e->succ()) currentCost += perUnitCost[e] * flow[e]; for (adjEntry adj = mu->firstAdj(); adj != nullptr; adj = adj->succ()) currentCost += cost[0][adj->twinNode()]; if (currentCost < cost[bends][mu]) { cost[bends][mu] = currentCost; embedding[bends][mu] = currentEmbedding; } } }
bool ImageThumbnailBar::event(QEvent* e) { // reset widget max/min sizes if (e->type() == QEvent::StyleChange || e->type() == QEvent::Show) { setFlow(flow()); } return ImageCategorizedView::event(e); }
int main() { input(); while(findPath()) { flow(); } output(); return 0; }
void MethodLiveness::compute_liveness() { #ifndef PRODUCT if (TraceLivenessGen) { tty->print_cr("################################################################"); tty->print("# Computing liveness information for "); method()->print_short_name(); } if (TimeLivenessAnalysis) _time_total.start(); #endif { TraceTime buildGraph(NULL, &_time_build_graph, TimeLivenessAnalysis); init_basic_blocks(); } { TraceTime genKill(NULL, &_time_gen_kill, TimeLivenessAnalysis); init_gen_kill(); } { TraceTime flow(NULL, &_time_flow, TimeLivenessAnalysis); propagate_liveness(); } #ifndef PRODUCT if (TimeLivenessAnalysis) _time_total.stop(); if (TimeLivenessAnalysis) { // Collect statistics _total_bytes += method()->code_size(); _total_methods++; int num_blocks = _block_list->length(); _total_blocks += num_blocks; _max_method_blocks = MAX2(num_blocks,_max_method_blocks); for (int i=0; i<num_blocks; i++) { BasicBlock *block = _block_list->at(i); int numEdges = block->_normal_predecessors->length(); int numExcEdges = block->_exception_predecessors->length(); _total_edges += numEdges; _total_exc_edges += numExcEdges; _max_block_edges = MAX2(numEdges,_max_block_edges); _max_block_exc_edges = MAX2(numExcEdges,_max_block_exc_edges); } int numLocals = _bit_map_size_bits; _total_method_locals += numLocals; _max_method_locals = MAX2(numLocals,_max_method_locals); } #endif }
tcpip *tcpdemux::create_tcpip(const flow_addr &flowa, be13::tcp_seq isn,const be13::packet_info &pi) { /* create space for the new state */ flow flow(flowa,flow_counter++,pi); tcpip *new_tcpip = new tcpip(*this,flow,isn); new_tcpip->nsn = isn+1; // expected sequence number of the first byte DEBUG(5) ("%s: new flow. next seq num (nsn):%d", new_tcpip->flow_pathname.c_str(),new_tcpip->nsn); flow_map[flow] = new_tcpip; return new_tcpip; }
void kid_unclimb (struct anim *k) { k->oaction = k->action; k->action = kid_unclimb; k->f.flip = (k->f.dir == RIGHT) ? ALLEGRO_FLIP_HORIZONTAL : 0; if (! flow (k)) return; if (! physics_in (k)) return; next_frame (&k->f, &k->f, &k->fo); physics_out (k); }
void kid_stabilize (struct anim *k) { k->oaction = k->action; k->action = kid_stabilize; k->f.flip = (k->f.dir == RIGHT) ? ALLEGRO_FLIP_HORIZONTAL : 0; if (! flow (k)) return; if (! cutscene && ! physics_in (k)) return; next_frame (&k->f, &k->f, &k->fo); physics_out (k); }
static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp) { priv_t * p = (priv_t *)effp->priv; static size_t isamp = 0; if (p->pads_pos != p->npads && p->in_pos != p->pads[p->pads_pos].start) { if (p->pads[p->pads_pos].align) p->pads[p->pads_pos].pad = pad_align(p->pads[p->pads_pos].align, p->pads[p->pads_pos].align); p->in_pos = UINT64_MAX; /* Invoke the final pad (with no given start) */ } return flow(effp, 0, obuf, &isamp, osamp); }
int match(){ memset(pr, -1, sizeof(pr)); int a = 0; for (int i=0; i<V; i++){ if (pr[i] == -1){ if(flow(i)) a++; else mtp[i] = i; } } return a; }
void guard_normal (struct anim *g) { g->oaction = g->action; g->action = guard_normal; g->f.flip = (g->f.dir == RIGHT) ? ALLEGRO_FLIP_HORIZONTAL : 0; if (! flow (g)) return; if (! physics_in (g)) return; next_frame (&g->f, &g->f, &g->fo); physics_out (g); }