int main() { int r,c; Point s; scanf("%d%d\n",&R,&C); char line[501]; for(r=0;r<R;++r){ gets(line); for(c=0;c<C;++c){ map[r][c] = line[c]; if(map[r][c]=='s'){ s.r = r; s.c = c; } } } double result = solv(s.r, s.c, 1.0, 10.0); if(result >= 0) printf("%.12f\n", result); else printf("-1\n"); return 0; }
void SymbolicQr::evaluateSXGen(const SXPtrV& input, SXPtrV& output, bool tr) { // Get arguments casadi_assert(input.at(0)!=0); SX r = *input.at(0); casadi_assert(input.at(1)!=0); SX A = *input.at(1); // Number of right hand sides int nrhs = r.size2(); // Factorize A vector<SX> v = fact_fcn_(A); // Select solve function Function& solv = tr ? solv_fcn_T_ : solv_fcn_N_; // Solve for every right hand side vector<SX> resv; v.resize(3); for (int i=0; i<nrhs; ++i) { v[2] = r(Slice(), i); resv.push_back(solv(v).at(0)); } // Collect the right hand sides casadi_assert(output[0]!=0); *output.at(0) = horzcat(resv); }
int main() { freopen("in.txt","r",stdin); scanf("%d",&n); for(int i=0;i<n;++i) { scanf("%d %d",*(p+i),*(p+i)+1); p[i][2]=i; } printf("%I64d",solv()); return 0; }
Eigen::Matrix4d VertexPointXYZCov::covTransform(){ EigenSolver<Matrix3d> solv(_cov); Matrix3d eigenVectors = solv.eigenvectors().real(); Eigen::Matrix4d covGlTransform; covGlTransform.setIdentity(); for(int i=0; i < 3; ++i) for(int j=0; j < 3; ++j) covGlTransform(i,j) = eigenVectors(i,j); for(int i=0; i < 3; ++i) covGlTransform(i,3) = estimate()(i); return covGlTransform; }
/* ;@cc_solv(a, b, n) ;@ Solve a general linear system A*x = b. ; ; int solv(double a[],double b[],int n) ; ; a = array containing system matrix A in row order ; (altered to L-U factored form by computation) ; ; b = array containing system vector b at entry and ; solution vector x at exit ; ; n = dimension of system ;@ ;@ */ static LISP cc_solv1(LISP a1, LISP a2, LISP b1, LISP b2) { int row, col, sheet; buffer *buf; int ax1 = get_c_long(CAR(a1)), ay1 = get_c_long(CDR(a1)); int ax2 = get_c_long(CAR(a2)), ay2 = get_c_long(CDR(a2)); int bx1 = get_c_long(CAR(b1)), by1 = get_c_long(CDR(b1)); int bx2 = get_c_long(CDR(b2)), by2 = get_c_long(CDR(b2)); int n = by2-by1+1; double *a = fetch_array(ax1, ay1, ax2, ay2); double *b = fetch_array(bx1, by1, bx2, by2); if (a == NULL || b == NULL || solv(a, b, n) == 0) return NIL; get_siod_coords(&row, &col, &sheet, &buf); store_array(row, col, row+n-1, col, b); return flocons(b[0]); }
double solv(int r, int c, double weight, double min) { if(r < 0 || R <= r || c < 0 || C <= c || map[r][c] == '#') return -1; if(map[r][c] == 'g') return min; if(map[r][c] != 's'){ double light = (map[r][c] - '0') * weight; if(light < min) min = light; } double max=-1, l; Point n[4] = {{r-1,c}, {r+1,c}, {r,c-1}, {r,c+1}}; int i; char b = map[r][c]; weight *= 0.99; map[r][c] = '#'; for(i=0;i<4;++i){ l = solv(n[i].r, n[i].c, weight, min); if(l>max) max = l; } map[r][c] = b; return max; }
/** \brief Solve a general linear system A*x = b. \param a = array containing system matrix A in row order (altered to L-U factored form by computation) \param b = array containing system vector b at entry and solution vector x at exit \param n = dimension of system \return 0 -> normal exit; -1 -> singular input */ int G_math_solv(double **a,double *b,int n) { return solv(a[0],b, n); }
void cbranch () { int tid; pthread_mutex_lock(&mMutRec); tid = mThreadId ++; mTids[tid] = tid; pthread_setspecific(mTidKey, (void*)(mTids + tid)); MMRegistry::registerMemManager(mManagers[tid]); pthread_mutex_unlock(&mMutRec); SmartArrayPtr < Set > aq(mMaxLocalQueueSize); FixedVector < Set > ltq((Set*)aq, mMaxLocalQueueSize); Solution asolv[2]; FixedVector < Solution > solv(asolv, 2); SmartArrayPtr < Set > alsetv(mMaxLocalSetBufferSize); FixedVector < Set > lsetv(alsetv, mMaxLocalSetBufferSize); SmartArrayPtr < Solution > alsolv(mMaxLocalSolutionBufferSize); FixedVector < Solution > lsolv(alsolv, mMaxLocalSolutionBufferSize); for(int step = 1; ; step ++) { Set s; if(ltq.empty()) { pthread_mutex_lock(&mMutTaskQueue); mStarv ++; mSteps = BNBMAX(mSteps, step); while(mTaskQueue.empty() && (mStarv != mNumThreads) && (mSteps < mLocalSteps)) { mLocalCounters[tid].mStarv ++; struct timeval tv; double t1, t2; gettimeofday(&tv, NULL); t1 = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; pthread_cond_wait(&mCV, &mMutTaskQueue); gettimeofday(&tv, NULL); t2 = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; mLocalCounters[tid].mStarvTime += (t2 - t1); } if(mSteps >= mLocalSteps) { pthread_cond_broadcast(&mCV); pthread_mutex_unlock(&mMutTaskQueue); break; } else if(!mTaskQueue.empty()) { s = mTaskQueue.top (); mTaskQueue.pop (); mStarv --; mLocalCounters[tid].mGet ++; pthread_mutex_unlock(&mMutTaskQueue); } else { pthread_cond_broadcast(&mCV); pthread_mutex_unlock(&mMutTaskQueue); break; } } else { s = ltq.back(); ltq.pop_back(); } if (!mSetFactory->discard (s, getRecord())){ mSetFactory->branch (s, lsetv, lsolv, getRecord(), mInfos + tid, ltq.size()); typename ProblemFactory::ValueType rec = getRecord(); while(!lsolv.empty()) { Solution s = lsolv.back(); lsolv.pop_back(); if(((Factory::getProblemType() == BNB_MAXIMIZE) && (s.getValue() > rec)) || ((Factory::getProblemType() == BNB_MINIMIZE) && (s.getValue() < rec))) { rec = s.getValue(); if(!solv.empty()) solv.pop_back(); solv.push_back(s); } } updateRecord(rec); while(!lsetv.empty()) { Set s = lsetv.back(); lsetv.pop_back(); if(!mSetFactory->discard (s, rec)) ltq.push_back(s); else mInfos[tid].mDiscardedByRecord ++; } mSteps = BNBMAX(mSteps, step); if(mSteps >= mLocalSteps) { pthread_mutex_lock(&mMutTaskQueue); if(mStarv) pthread_cond_broadcast(&mCV); pthread_mutex_unlock(&mMutTaskQueue); break; } if((step % mUpdateRatio) == 0) { if(!ltq.empty()) { pthread_mutex_lock(&mMutTaskQueue); struct timeval tv; double t1, t2; gettimeofday(&tv, NULL); t1 = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; mLocalCounters[tid].mDonat ++; for(int i = 0; i < mPutChunk; i ++) { if(!ltq.empty()) { MMRegistry::registerMemManager(mAuxMemManager); Set s = ltq.back(); mTaskQueue.push(s); MMRegistry::registerMemManager(mManagers[tid]); ltq.pop_back(); mLocalCounters[tid].mPut ++; } else break; } mQLen = mTaskQueue.size(); mMaxQLen = BNBMAX(mQLen, mMaxQLen); if(mStarv) pthread_cond_broadcast(&mCV); t2 = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; mLocalCounters[tid].mDonatTime += t2 - t1; pthread_mutex_unlock(&mMutTaskQueue); } } } else { mInfos[tid].mDiscardedByRecord ++; } } pthread_mutex_lock(&mMutTaskQueue); while(!ltq.empty()) { Set s = ltq.back(); ltq.pop_back(); mTaskQueue.push(s); } pushSolutions (solv, mInfos + tid); pthread_mutex_unlock(&mMutTaskQueue); }
int main(int argc, char *argv[]) { WINDOW *my_win, *score; WINDOW **car; game newGame, tmpGame; MEVENT event; int ch = 0, choosenCar = -1, soluce_move = 0; char message[1024]; bool quit = false; bool show_solution = false; gameStruct *resultSolv = NULL; //INIT setup(); //END INIT //Wait for good size wait_for_size(MINH, MINW); //Instruction show_instruction(MINH, MINW); while (!quit) { quit = false; show_solution = false; soluce_move = 0; strcpy(message, "Playing"); //Select game newGame = select_game(); //Check for level file if (handle_level(&tmpGame)) { delete_game(newGame); newGame = tmpGame; MAXCOL = game_width(newGame); MAXROW = game_height(newGame); MINH = MAXROW * SIZE + 2; MINW = MAXCOL * SIZE; } car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame)); //First draw draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh); //Loop while the game is not finished while (!game_over(newGame)) { //Print on bottom of grid mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :"); ch = getch(); if (ch == 's' && !show_solution) { show_solution = true; strcpy(message, "Solution"); resultSolv = solv(newGame, gameOverRh,true); if(!resultSolv){ strcpy(message, "No solution"); show_solution=false; } } if (show_solution) { newGame = play_solution(newGame, resultSolv, soluce_move++); } else { if (KEY_MOUSE == ch) { /* Mouse event. */ if (OK == getmouse(&event)) { choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame)); } } else { if (ch == 'q') { quit = true; break; } play_input(newGame, ch, &choosenCar); } } wait_for_size(MINH, MINW); erase_game(newGame, my_win, car, score); draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh); } if (!quit) { display_score(newGame); } for (int i = 0; i < game_nb_pieces(newGame); i++) { destroy_win(car[i]); } destroy_win(my_win); destroy_win(score); free(car); delete_game(newGame); if (resultSolv != NULL) { delete_game(resultSolv->current); free(resultSolv->move); free(resultSolv); resultSolv = NULL; } } endwin(); /* End curses mode */ return 0; }