Changeset 575 for branches/devel/Cbc/src/CoinSolve.cpp
 Timestamp:
 Mar 11, 2007 1:25:20 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/src/CoinSolve.cpp
r546 r575 22 22 23 23 #include "ClpFactorization.hpp" 24 #include "ClpQuadraticObjective.hpp" 24 25 #include "CoinTime.hpp" 25 26 #include "ClpSimplex.hpp" … … 40 41 //#define CLP_MALLOC_STATISTICS 41 42 #ifdef CLP_MALLOC_STATISTICS 43 #include <malloc.h> 42 44 #include <exception> 43 45 #include <new> … … 1181 1183 int tunePreProcess=5; 1182 1184 int testOsiParameters=1; 1183 // 0 normal, 1 from ampl , 2 from other input1185 // 0 normal, 1 from ampl or MIQP etc (2 allows cuts) 1184 1186 int complicatedInteger=0; 1185 1187 OsiSolverInterface * solver = model.solver(); … … 1202 1204 int * cut=NULL; 1203 1205 int * sosPriority=NULL; 1206 CoinModel * coinModel = NULL; 1204 1207 #ifdef COIN_HAS_ASL 1205 1208 ampl_info info; 1206 1209 CglStored storedAmpl; 1207 CoinModel * coinModel = NULL;1208 1210 CoinModel saveCoinModel; 1209 1211 int * whichColumn = NULL; … … 1432 1434 parameters[whichParam(INCREMENT,numberParameters,parameters)].setDoubleValue(model.getDblParam(CbcModel::CbcCutoffIncrement)); 1433 1435 parameters[whichParam(TESTOSI,numberParameters,parameters)].setIntValue(testOsiParameters); 1436 parameters[whichParam(FPUMPTUNE,numberParameters,parameters)].setIntValue(1003); 1434 1437 if (testOsiParameters>=0) { 1435 1438 // trying nonlinear  switch off some stuff … … 1439 1442 parameters[whichParam(PREPROCESS,numberParameters,parameters)].setCurrentOption("on"); 1440 1443 parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(128641); 1444 parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(1); 1441 1445 parameters[whichParam(MOREMIPOPTIONS,numberParameters,parameters)].setIntValue(1); 1442 1446 parameters[whichParam(MAXHOTITS,numberParameters,parameters)].setIntValue(100); … … 2449 2453 dynamic_cast<OsiClpSolverInterface *>(solver) ; 2450 2454 assert (si != NULL); 2455 // See if quadratic 2456 if (!complicatedInteger) { 2457 ClpSimplex * lpSolver = si>getModelPtr(); 2458 ClpQuadraticObjective * obj = (dynamic_cast< ClpQuadraticObjective*>(lpSolver>objectiveAsObject())); 2459 if (obj) { 2460 preProcess=0; 2461 parameters[whichParam(TESTOSI,numberParameters,parameters)].setIntValue(0); 2462 // create coin model 2463 coinModel = lpSolver>createCoinModel(); 2464 assert (coinModel); 2465 // load from coin model 2466 OsiSolverLink solver1; 2467 OsiSolverInterface * solver2 = solver1.clone(); 2468 model.assignSolver(solver2,true); 2469 OsiSolverLink * si = 2470 dynamic_cast<OsiSolverLink *>(model.solver()) ; 2471 assert (si != NULL); 2472 si>setDefaultMeshSize(0.001); 2473 // need some relative granularity 2474 si>setDefaultBound(100.0); 2475 si>setDefaultMeshSize(0.01); 2476 si>setDefaultBound(1000.0); 2477 si>setIntegerPriority(1000); 2478 si>setBiLinearPriority(10000); 2479 si>setSpecialOptions2(2+4+8); 2480 CoinModel * model2 = (CoinModel *) coinModel; 2481 si>load(*model2,true,info.logLevel); 2482 // redo 2483 solver = model.solver(); 2484 clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver); 2485 lpSolver = clpSolver>getModelPtr(); 2486 clpSolver>messageHandler()>setLogLevel(0) ; 2487 testOsiParameters=0; 2488 complicatedInteger=2; // allow cuts 2489 OsiSolverInterface * coinSolver = model.solver(); 2490 OsiSolverLink * linkSolver = dynamic_cast< OsiSolverLink*> (coinSolver); 2491 if (linkSolver>quadraticModel()) { 2492 ClpSimplex * qp = linkSolver>quadraticModel(); 2493 //linkSolver>nonlinearSLP(CoinMax(slpValue,10),1.0e5); 2494 qp>nonlinearSLP(CoinMax(slpValue,20),1.0e5); 2495 qp>primal(1); 2496 OsiSolverLinearizedQuadratic solver2(qp); 2497 const double * solution=NULL; 2498 // Reduce printout 2499 solver2.setHintParam(OsiDoReducePrint,true,OsiHintTry); 2500 CbcModel model2(solver2); 2501 // Now do requested saves and modifications 2502 CbcModel * cbcModel = & model2; 2503 OsiSolverInterface * osiModel = model2.solver(); 2504 OsiClpSolverInterface * osiclpModel = dynamic_cast< OsiClpSolverInterface*> (osiModel); 2505 ClpSimplex * clpModel = osiclpModel>getModelPtr(); 2506 2507 // Set changed values 2508 2509 CglProbing probing; 2510 probing.setMaxProbe(10); 2511 probing.setMaxLook(10); 2512 probing.setMaxElements(200); 2513 probing.setMaxProbeRoot(50); 2514 probing.setMaxLookRoot(10); 2515 probing.setRowCuts(3); 2516 probing.setUsingObjective(true); 2517 cbcModel>addCutGenerator(&probing,1,"Probing",true,false,false,100,1,1); 2518 cbcModel>cutGenerator(0)>setTiming(true); 2519 2520 CglGomory gomory; 2521 gomory.setLimitAtRoot(512); 2522 cbcModel>addCutGenerator(&gomory,98,"Gomory",true,false,false,100,1,1); 2523 cbcModel>cutGenerator(1)>setTiming(true); 2524 2525 CglKnapsackCover knapsackCover; 2526 cbcModel>addCutGenerator(&knapsackCover,98,"KnapsackCover",true,false,false,100,1,1); 2527 cbcModel>cutGenerator(2)>setTiming(true); 2528 2529 CglRedSplit redSplit; 2530 cbcModel>addCutGenerator(&redSplit,99,"RedSplit",true,false,false,100,1,1); 2531 cbcModel>cutGenerator(3)>setTiming(true); 2532 2533 CglClique clique; 2534 clique.setStarCliqueReport(false); 2535 clique.setRowCliqueReport(false); 2536 clique.setMinViolation(0.1); 2537 cbcModel>addCutGenerator(&clique,98,"Clique",true,false,false,100,1,1); 2538 cbcModel>cutGenerator(4)>setTiming(true); 2539 2540 CglMixedIntegerRounding2 mixedIntegerRounding2; 2541 cbcModel>addCutGenerator(&mixedIntegerRounding2,98,"MixedIntegerRounding2",true,false,false,100,1,1); 2542 cbcModel>cutGenerator(5)>setTiming(true); 2543 2544 CglFlowCover flowCover; 2545 cbcModel>addCutGenerator(&flowCover,98,"FlowCover",true,false,false,100,1,1); 2546 cbcModel>cutGenerator(6)>setTiming(true); 2547 2548 CglTwomir twomir; 2549 twomir.setMaxElements(250); 2550 cbcModel>addCutGenerator(&twomir,99,"Twomir",true,false,false,100,1,1); 2551 cbcModel>cutGenerator(7)>setTiming(true); 2552 2553 CbcHeuristicFPump heuristicFPump(*cbcModel); 2554 heuristicFPump.setWhen(13); 2555 heuristicFPump.setMaximumPasses(20); 2556 heuristicFPump.setMaximumRetries(7); 2557 heuristicFPump.setAbsoluteIncrement(4332.64); 2558 cbcModel>addHeuristic(&heuristicFPump); 2559 heuristicFPump.setInitialWeight(1); 2560 2561 CbcRounding rounding(*cbcModel); 2562 cbcModel>addHeuristic(&rounding); 2563 2564 CbcHeuristicLocal heuristicLocal(*cbcModel); 2565 heuristicLocal.setSearchType(1); 2566 cbcModel>addHeuristic(&heuristicLocal); 2567 2568 CbcHeuristicGreedyCover heuristicGreedyCover(*cbcModel); 2569 cbcModel>addHeuristic(&heuristicGreedyCover); 2570 2571 CbcHeuristicGreedyEquality heuristicGreedyEquality(*cbcModel); 2572 cbcModel>addHeuristic(&heuristicGreedyEquality); 2573 2574 CbcCompareDefault compare; 2575 cbcModel>setNodeComparison(compare); 2576 cbcModel>setNumberBeforeTrust(5); 2577 cbcModel>setSpecialOptions(2); 2578 cbcModel>messageHandler()>setLogLevel(1); 2579 cbcModel>setMaximumCutPassesAtRoot(100); 2580 cbcModel>setMaximumCutPasses(1); 2581 cbcModel>setMinimumDrop(0.05); 2582 // For branchAndBound this may help 2583 clpModel>defaultFactorizationFrequency(); 2584 clpModel>setDualBound(1.0001e+08); 2585 clpModel>setPerturbation(50); 2586 osiclpModel>setSpecialOptions(193); 2587 osiclpModel>messageHandler()>setLogLevel(0); 2588 osiclpModel>setIntParam(OsiMaxNumIterationHotStart,100); 2589 osiclpModel>setHintParam(OsiDoReducePrint,true,OsiHintTry); 2590 // You can save some time by switching off message building 2591 // clpModel>messagesPointer()>setDetailMessages(100,10000,(int *) NULL); 2592 2593 // Solve 2594 2595 cbcModel>initialSolve(); 2596 if (clpModel>tightenPrimalBounds()!=0) { 2597 std::cout<<"Problem is infeasible  tightenPrimalBounds!"<<std::endl; 2598 exit(1); 2599 } 2600 clpModel>dual(); // clean up 2601 cbcModel>initialSolve(); 2602 cbcModel>branchAndBound(); 2603 OsiSolverLinearizedQuadratic * solver3 = dynamic_cast<OsiSolverLinearizedQuadratic *> (model2.solver()); 2604 assert (solver3); 2605 solution = solver3>bestSolution(); 2606 double bestObjectiveValue = solver3>bestObjectiveValue(); 2607 linkSolver>setBestObjectiveValue(bestObjectiveValue); 2608 linkSolver>setBestSolution(solution,solver3>getNumCols()); 2609 CbcHeuristicDynamic3 dynamic(model); 2610 model.addHeuristic(&dynamic); 2611 // if convex 2612 if ((linkSolver>specialOptions2()&4)!=0) { 2613 int numberColumns = coinModel>numberColumns(); 2614 // add OA cut 2615 double offset; 2616 double * gradient = new double [numberColumns+1]; 2617 memcpy(gradient,qp>objectiveAsObject()>gradient(qp,solution,offset,true,2), 2618 numberColumns*sizeof(double)); 2619 double rhs = 0.0; 2620 int * column = new int[numberColumns+1]; 2621 int n=0; 2622 for (int i=0;i<numberColumns;i++) { 2623 double value = gradient[i]; 2624 if (fabs(value)>1.0e12) { 2625 gradient[n]=value; 2626 rhs += value*solution[i]; 2627 column[n++]=i; 2628 } 2629 } 2630 gradient[n]=1.0; 2631 column[n++]=numberColumns; 2632 storedAmpl.addCut(COIN_DBL_MAX,offset+1.0e7,n,column,gradient); 2633 delete [] gradient; 2634 delete [] column; 2635 } 2636 // could do three way branching round a) continuous b) best solution 2637 printf("obj %g\n",bestObjectiveValue); 2638 linkSolver>initialSolve(); 2639 } 2640 } 2641 } 2451 2642 si>setSpecialOptions(0x40000000); 2452 2643 } … … 2900 3091 6 as 3 but all slack basis! 2901 3092 */ 3093 int logLevel = parameters[log].intValue(); 2902 3094 double value = babModel>solver()>getObjSense()*babModel>solver()>getObjValue(); 2903 3095 int w = pumpTune/10; … … 2920 3112 } 2921 3113 // fake cutoff 2922 printf("Setting "); 3114 if (logLevel>1) 3115 printf("Setting "); 2923 3116 if (c) { 2924 3117 double cutoff; … … 2926 3119 cutoff = CoinMin(cutoff,value + 0.1*fabs(value)*c); 2927 3120 heuristic4.setFakeCutoff(cutoff); 2928 printf("fake cutoff of %g ",cutoff); 3121 if (logLevel>1) 3122 printf("fake cutoff of %g ",cutoff); 2929 3123 } 2930 3124 if (ir) { … … 2933 3127 heuristic4.setAccumulate(accumulate); 2934 3128 heuristic4.setMaximumRetries(r+1); 2935 if (i) 2936 printf("increment of %g ",heuristic4.absoluteIncrement()); 2937 if (accumulate) 2938 printf("accumulate of %d ",accumulate); 2939 printf("%d retries ",r+2); 3129 if (logLevel>1) { 3130 if (i) 3131 printf("increment of %g ",heuristic4.absoluteIncrement()); 3132 if (accumulate) 3133 printf("accumulate of %d ",accumulate); 3134 printf("%d retries ",r+2); 3135 } 2940 3136 } 2941 3137 pumpTune = pumpTune%100; 2942 printf("and setting when to %d\n",pumpTune+10); 3138 if (logLevel>1) 3139 printf("and setting when to %d\n",pumpTune+10); 2943 3140 if (pumpTune==6) 2944 3141 pumpTune =13; … … 2991 3188 switches[numberGenerators++]=0; 2992 3189 } 2993 if (gomoryAction&&( !complicatedIntegergomoryAction==1)) {3190 if (gomoryAction&&(complicatedInteger!=1gomoryAction==1)) { 2994 3191 babModel>addCutGenerator(&gomoryGen,translate[gomoryAction],"Gomory"); 2995 3192 switches[numberGenerators++]=1; … … 3098 3295 // Used to be automatically set 3099 3296 int mipOptions = parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].intValue()%10000; 3100 if (mipOptions!=(1 28641))3297 if (mipOptions!=(1)) 3101 3298 printf("mip options %d\n",mipOptions); 3102 3299 osiclp>setSpecialOptions(mipOptions); … … 3625 3822 if (testOsiOptions>=0) { 3626 3823 printf("Testing OsiObject options %d\n",testOsiOptions); 3627 CbcBranchDefaultDecision decision;3628 OsiChooseStrong choose(babModel>solver());3629 choose.setNumberBeforeTrusted(babModel>numberBeforeTrust());3630 choose.setNumberStrong(babModel>numberStrong());3631 choose.setShadowPriceMode(testOsiOptions);3632 3824 if (!numberSOS) { 3633 3825 babModel>solver()>findIntegersAndSOS(false); … … 3650 3842 8  try doing quadratic linearization 3651 3843 16  try expanding knapsacks 3844 32  OA cuts strictly concave 3652 3845 */ 3653 3846 if ((options&2)) 3654 3847 solver3>setBiLinearPriorities(10); 3655 if ((options&4)) 3848 if ((options&4)) { 3656 3849 solver3>setSpecialOptions2(solver3>specialOptions2()(8+4)); 3850 // say convex 3851 solver3>sayConvex((options&32)==0); 3852 } 3657 3853 if ((options&1)!=0&&slpValue>0) 3658 3854 solver3>setFixedPriority(slpValue); 3659 3855 double cutoff=COIN_DBL_MAX; 3660 if ((options& 4))3856 if ((options&8)) 3661 3857 cutoff=solver3>linearizedBAB(&stored); 3662 3858 if (cutoff<babModel>getCutoff()) … … 3667 3863 CglTemporary temp; 3668 3864 babModel>addCutGenerator(&temp,1,"OnceOnly"); 3669 choose.setNumberBeforeTrusted(2000);3670 choose.setNumberStrong(20);3865 //choose.setNumberBeforeTrusted(2000); 3866 //choose.setNumberStrong(20); 3671 3867 } 3672 3868 #endif … … 3676 3872 //babModel>addObjects(babModel>solver()>numberObjects(),babModel>solver()>objects()); 3677 3873 } 3678 decision.setChooseMethod(choose); 3874 CbcBranchDefaultDecision decision; 3875 if (babModel>numberStrong()) { 3876 OsiChooseStrong choose(babModel>solver()); 3877 choose.setNumberBeforeTrusted(babModel>numberBeforeTrust()); 3878 choose.setNumberStrong(babModel>numberStrong()); 3879 choose.setShadowPriceMode(testOsiOptions); 3880 decision.setChooseMethod(choose); 3881 } else { 3882 OsiChooseVariable choose(babModel>solver()); 3883 decision.setChooseMethod(choose); 3884 } 3679 3885 babModel>setBranchingMethod(decision); 3680 3886 if (useCosts&&testOsiOptions>=0) { … … 4276 4482 bool deleteModel2=false; 4277 4483 ClpSimplex * model2 = lpSolver; 4484 if (dualize) { 4485 model2 = ((ClpSimplexOther *) model2)>dualOfModel(); 4486 printf("Dual of model has %d rows and %d columns\n", 4487 model2>numberRows(),model2>numberColumns()); 4488 model2>setOptimizationDirection(1.0); 4489 } 4278 4490 #ifdef COIN_HAS_ASL 4279 4491 if (info.numberSos&&doSOS&&usingAmpl) { … … 4501 4713 good=false; 4502 4714 if (good) { 4503 char ** columnNames = columnNames =new char * [numberColumns];4715 char ** columnNames = new char * [numberColumns]; 4504 4716 pseudoDown= (double *) malloc(numberColumns*sizeof(double)); 4505 4717 pseudoUp = (double *) malloc(numberColumns*sizeof(double));
Note: See TracChangeset
for help on using the changeset viewer.