int main(void) { while(scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; scanf("%d%d",&x,&y); for(int i=0; i<n; i++) { scanf("%s",&str[i]); } solveA(m,n,y); //y代表宽度 reserveB(m,n); int total=solveB(n,m,x); //x代表高度 if(x!=y) { reserveA(m,n); solveA(n,m,y); reserveB(n,m); total+=solveB(m,n,x); } printf("%d\n",total); //free memory } return 0; }
int main() { printf("%d\n", special(3)); char op; printConsole(&op); if(op == 'a') { sieveBuild(); vector answer; answer = solveA(); printf("Task (a):\n"); printArray(answer); } else { printf("Task (b):\n"); vector v; v = readArray(); vector ans; ans = solveB(v); printArray(ans); } return 0; }
int main(int argc, char **argv) { //*****************************SET PARAMETERS************************************************* Parameters params(argc, argv, 0); Parameters params2(argc, argv, 1); //******************************************************************************************** //**********************READ DATA AND MAKE SOLUTION******************************************* Solution* sol = constructSolution(params); preprocesData(sol); Solution* sol2 = constructSolution(params2); preprocesData(sol2); //********************************************************************************************* //*****************************SET PARAMETERS************************************************* if(sol->getNumberOfProcesses() * sol->getNumberOfMachines() <= 100 * 1000) { params2.delta = params.delta = 40; params2.nmb_iters_bpr = params.nmb_iters_bpr = 300; params2.nmbRanges = params.nmbRanges = 7; params2.rangeLength = params.rangeLength = sol->getNumberOfProcesses() / params.nmbRanges; } else { params2.nmb_iters_bpr = params.nmb_iters_bpr = 100; params2.nmbRanges = params.nmbRanges = 5; params2.rangeLength = params.rangeLength = sol->getNumberOfProcesses() / params.nmbRanges; params2.numberOfBestProcessesToConsiderShiftSwap = params.numberOfBestProcessesToConsiderShiftSwap = 3; params2.nmbLoops = params.nmbLoops = 2; if(sol->getNumberOfProcesses() * sol->getNumberOfMachines() >= 20000 * 2000) params2.nmbLoops = params.nmbLoops = 1; } params2.seedValue = params.seedValue + 1000; //******************************************************************************************** if(sol->getNumberOfProcesses() * sol->getNumberOfMachines() <= 100 * 1000) // A instances solveA(params, sol, params2, sol2); else // B instances solveB(params, sol, params2, sol2); long timeToSleep = params.time_limit - (time(0) - params.programStartTime) - 3; if (timeToSleep < 0) timeToSleep = 0; sleep(timeToSleep); // Read Solutions From Files And Write a better one sol->setOriginalLoadCostWeights(); sol2->setOriginalLoadCostWeights(); //cout << " sol->solutionFilename " << sol->solutionFilename << endl; //cout << " sol2->solutionFilename " << sol2->solutionFilename << endl; //cout << " sol->getCost() " << sol->getCost() << endl; //cout << " sol2->getCost() " << sol2->getCost() << endl; readSolutionFromFile( sol, sol->solutionFilename); readSolutionFromFile(sol2, sol2->solutionFilename); //cout << " after sol->getCost() " << sol->getCost() << endl; //cout << " after sol2->getCost() " << sol2->getCost() << endl; if ((sol->getCost() < sol2->getCost()) && (sol->checkConflict(false))) sol->writeToFile(params.solution_filename); else sol2->writeToFile(params.solution_filename); //remove solution files ostringstream oss1(""); oss1 << "rm " << sol->solutionFilename; system(oss1.str().c_str()); ostringstream oss2(""); oss2 << "rm " << sol2->solutionFilename; system(oss2.str().c_str()); //*****************************************FILES (REMOVE THIS PART)******************************************************** /*fstream fileResults("results", ios::out | ios::app); fileResults << setw(5) << params.seedValue << setw(30) << params.data_filename << setw(20) << sol->getCost() << setw(20) << sol2->getCost() << setw(20) << *(params.best_objective) << setw(15) << time(0) - params.programStartTime << endl; // running times fstream fileRunnungTimes("runnung_times", ios::out | ios::app); fileRunnungTimes << setw(5) << setw(30) << params.data_filename << setw(20) << *(params.best_objective) << setw(20) << time(0) - params.programStartTime << endl; // check solution with official checker ostringstream oss(""); oss << "./checker " << params.data_filename << " " << params.initial_assignment_filename << " " << params.solution_filename; oss << " >> checkerFile "; system(oss.str().c_str()); */ //************************************************************************************************************************* return 0; }
int main( int argc , char* argv[] ) { snProblem toy; int i, info; int Cold = 0; int n = 2; int m = 3; int ne = 5; int nnCon = 2; int nnObj = 0; int nnJac = 2; int iObj = 2; double ObjAdd = 0; double objective; // snInit must be called first. // 9, 6 are print and summary unit numbers (for Fortran). // 6 == standard out snInit ( &toy, "ToyB", "ToyB.out", 9, 6 ); // Set the problem size and other data. // This will allocate arrays inside snProblem struct. setProblemSize ( &toy, m, n, ne, nnCon, nnJac, nnObj ); setObjective ( &toy, iObj, ObjAdd ); setFuncon ( &toy, (snConB) toycon ); setFunobj ( &toy, (snObjB) toyobj ); // User workspace allocated and set. // May be accesed in the user-defined function toyusrfun. toy.leniu = 2; toy.iu = (int*)malloc( sizeof(int) * toy.leniu ); toy.iu[0] = 0; toy.iu[1] = 1; // Set bounds toy.bl[0] = 0; toy.bu[0] = 1e20; toy.bl[1] = -1e20; toy.bu[1] = 1e20; toy.bl[2] = -1e20; toy.bu[2] = 4; toy.bl[3] = -1e20; toy.bu[3] = 5; toy.bl[4] = -1e20; toy.bu[4] = 1e20; // Initialize states, x and multipliers for ( i = 0; i < n+m; i++ ) { toy.hs[i] = 0; toy.x[i] = 0; toy.rc[i] = 0; } for ( i = 0; i < m; i++ ) { toy.pi[i] = 0; } toy.x[0] = 1.0; toy.x[1] = 1.0; // Set up the Jacobian matrix // Column 1 toy.locJ[0] = 0; toy.indJ[0] = 0; toy.valJ[0] = 0; toy.indJ[1] = 1; toy.valJ[1] = 0; // Column 2 toy.locJ[1] = 2; toy.indJ[2] = 0; toy.valJ[2] = 0; toy.indJ[3] = 1; toy.valJ[3] = 0; toy.indJ[4] = 2; toy.valJ[4] = 1; toy.locJ[2] = 5; // Read options, set options. info = setSpecsfile ( &toy, "sntoy.spc" ); setIntParameter( &toy, "Verify level", 3 ); setIntParameter( &toy, "Derivative option", 3 ); info = solveB( &toy, Cold, &objective ); // Deallocate space. free ( toy.iu ); deleteSNOPT ( &toy ); return 0; }