Changeset 88


Ignore:
Timestamp:
Jul 29, 2008 5:58:23 PM (11 years ago)
Author:
bjarni
Message:

Supports now CbcMain0/1 calls, CBNodeHandler, and CoinGetOptionChanged?

Location:
trunk/CoinMP/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CoinMP/src/CoinMP.cpp

    r68 r88  
    77/*  Author       :  Bjarni Kristjansson                                 */
    88/*                                                                      */
    9 /*  Copyright (c) 2005-2006                     Bjarni Kristjansson     */
     9/*  Copyright (c) 2005-2008                     Bjarni Kristjansson     */
    1010/*                                                                      */
    1111/************************************************************************/
     
    2222#include "CoinHelperFunctions.hpp"
    2323#include "CoinMessageHandler.hpp"
     24
    2425#include "ClpSimplex.hpp"
    2526#include "ClpPrimalColumnSteepest.hpp"
    2627#include "ClpDualRowSteepest.hpp"
    2728#include "ClpEventHandler.hpp"
    28 #include "CbcEventHandler.hpp"
     29
    2930#include "OsiSolverInterface.hpp"
    3031#include "OsiClpSolverInterface.hpp"
     32
    3133#include "CbcModel.hpp"
     34#include "CbcSolver.hpp"
     35#include "CbcEventHandler.hpp"
    3236
    3337#include "CglProbing.hpp"
     
    5155
    5256
     57#define NEW_STYLE_CBCMAIN
    5358
    5459/**************************************************************************/
     
    220225private:
    221226        NODECALLBACK callback_;
     227        int lastSolCount_;
    222228};
    223229
     
    226232{
    227233  callback_ = callback;
     234  lastSolCount_ = 0;
    228235}
    229236
     
    232239{
    233240        int numIter;
     241        int numNodes;
     242        double bestBound;
    234243        double objValue;
     244        int solCount;
    235245        int cancelAsap;
    236246
    237247        if (whichEvent==node) {
    238248                numIter = model_->getIterationCount();
     249                numNodes = model_->getNodeCount();
    239250                objValue = model_->getObjValue();
    240                 cancelAsap = callback_(numIter, 0, 0.0, objValue, 0);
     251                bestBound = model_->getBestPossibleObjValue();
     252                solCount = model_->getSolutionCount();
     253                cancelAsap = callback_(numIter, numNodes, bestBound, objValue, solCount != lastSolCount_);
     254                lastSolCount_ = solCount;
    241255                if (cancelAsap) {
    242256                        return stop;
     
    274288        CBNodeHandler * nodehandler;
    275289
    276    nodehandler = new CBNodeHandler(*this);
     290        nodehandler = new CBNodeHandler(*this);
    277291        nodehandler->callback_ = this->callback_;
     292        nodehandler->lastSolCount_ = this->lastSolCount_;
    278293        return nodehandler;
    279294}
     
    285300typedef struct {
    286301                                ClpSimplex *clp;
     302                                ClpSolve *clp_options;
    287303                                CbcModel *cbc;
     304#ifdef NEW_STYLE_CBCMAIN
     305                                CbcModel *cbc2;
     306#endif
    288307                                OsiClpSolverInterface *osi;
    289308
     
    339358SOLVAPI char*  CoinGetVersionStr(void)
    340359{
    341         return "1.0";
     360        return "1.1";
    342361}
    343362
     
    345364SOLVAPI double CoinGetVersion(void)
    346365{
    347         return 1.0;
     366        return 1.1;
    348367}
    349368
     
    362381
    363382
     383/**************************************************************************/
     384
    364385
    365386SOLVAPI HPROB CoinCreateProblem(char *ProblemName)
    366387{
    367    PCOIN pCoin;
    368 
    369    pCoin = (PCOIN) malloc(sizeof(COININFO));
    370    global_pCoin = pCoin;
    371    pCoin->clp = new ClpSimplex();
     388        PCOIN pCoin;
     389
     390        pCoin = (PCOIN) malloc(sizeof(COININFO));
     391        global_pCoin = pCoin;
     392        pCoin->clp = new ClpSimplex();
     393        pCoin->clp_options = new ClpSolve();
    372394        pCoin->osi = new OsiClpSolverInterface(pCoin->clp);
    373395        pCoin->cbc = NULL;  /* ERRORFIX 2/22/05: Crashes if not NULL when trying to set message handler */
     
    437459
    438460
     461        /* Load names */
    439462        std::vector<std::string> rowNameList;
    440463        rowNameList.reserve(RowCount);
     
    481504                        }
    482505                }
     506#ifdef NEW_STYLE_CBCMAIN
     507                if (CoinGetIntOption(hProb, COIN_INT_MIPUSECBCMAIN)) {
     508                        pCoin->cbc2 = pCoin->cbc;
     509                        CbcMain0(*pCoin->cbc);
     510                }
     511#endif
    483512        }
    484513        //pCoin->cbc->solver()->copyInIntegerInformation(pCoin->IsInt);
     
    617646   PCOIN pCoin = (PCOIN)hProb;
    618647
    619         return SOLV_FAILED;  // BK 7/26/2006: using the NodeCallback crashes CBC!
     648        //return SOLV_FAILED;  // BK 7/26/2006: using the NodeCallback crashes CBC!
    620649
    621650   pCoin->MipNodeCallback = NodeCallback;
     
    627656        pCoin->nodehandler->setCallback(NodeCallback);
    628657        //if (pCoin->iterhandler) pCoin->iterhandler->setNodeCallback(NodeCallback);
    629         if (pCoin->cbc) pCoin->cbc->passInEventHandler(pCoin->nodehandler);
     658#ifdef NEW_STYLE_CBCMAIN
     659        if (CoinGetIntOption(hProb, COIN_INT_MIPUSECBCMAIN)) {
     660                if (pCoin->cbc2) pCoin->cbc2->passInEventHandler(pCoin->nodehandler);
     661                }
     662        else
     663#endif
     664        {
     665                if (pCoin->cbc) pCoin->cbc->passInEventHandler(pCoin->nodehandler);
     666        }
    630667        return SOLV_SUCCESS;
    631668}
     
    634671
    635672/****************************************************************/
     673
     674int coinSetClpOptions(HPROB hProb)
     675{
     676        PCOIN pCoin = (PCOIN)hProb;
     677        ClpSolve::SolveType method;
     678        ClpSolve::PresolveType presolve;
     679        //ClpSolve clp_options;
     680
     681        /* check if it has been changed, leave alone otherwise */
     682        if (CoinGetOptionChanged(hProb, COIN_INT_SCALING))                      pCoin->clp->scaling(CoinGetIntOption(hProb,COIN_INT_SCALING));
     683        if (CoinGetOptionChanged(hProb, COIN_INT_PERTURBATION))         pCoin->clp->setPerturbation(CoinGetIntOption(hProb, COIN_INT_PERTURBATION));
     684
     685        if (CoinGetOptionChanged(hProb, COIN_INT_MAXITER))                      pCoin->clp->setMaximumIterations(CoinGetIntOption(hProb, COIN_INT_MAXITER));
     686
     687        if (CoinGetOptionChanged(hProb, COIN_REAL_PRIMALOBJLIM))        pCoin->clp->setPrimalObjectiveLimit(CoinGetIntOption(hProb, COIN_REAL_PRIMALOBJLIM));
     688        if (CoinGetOptionChanged(hProb, COIN_REAL_DUALOBJLIM))          pCoin->clp->setDualObjectiveLimit(CoinGetIntOption(hProb, COIN_REAL_DUALOBJLIM));
     689        if (CoinGetOptionChanged(hProb, COIN_REAL_PRIMALOBJTOL))        pCoin->clp->setPrimalTolerance(CoinGetIntOption(hProb, COIN_REAL_PRIMALOBJTOL));
     690        if (CoinGetOptionChanged(hProb, COIN_REAL_DUALOBJTOL))          pCoin->clp->setDualTolerance(CoinGetIntOption(hProb, COIN_REAL_DUALOBJTOL));
     691
     692        if (CoinGetOptionChanged(hProb, COIN_INT_PRIMALPIVOTALG)) {
     693                ClpPrimalColumnSteepest primalSteepest(CoinGetIntOption(hProb, COIN_INT_PRIMALPIVOTALG));
     694                pCoin->clp->setPrimalColumnPivotAlgorithm(primalSteepest);
     695        }
     696
     697        if (CoinGetOptionChanged(hProb, COIN_INT_DUALPIVOTALG)) {
     698                ClpDualRowSteepest dualSteepest(CoinGetIntOption(hProb, COIN_INT_DUALPIVOTALG));
     699                pCoin->clp->setDualRowPivotAlgorithm(dualSteepest);
     700        }
     701
     702        if (CoinGetOptionChanged(hProb, COIN_INT_CRASHIND)) {
     703                if (CoinGetIntOption(hProb, COIN_INT_CRASHIND)) {
     704                        pCoin->clp->crash(CoinGetIntOption(hProb, COIN_REAL_CRASHGAP),
     705                                                                CoinGetIntOption(hProb, COIN_INT_CRASHPIVOT));
     706                }
     707        }
     708
     709        if (CoinGetOptionChanged(hProb, COIN_INT_SOLVEMETHOD)) {
     710                switch (CoinGetIntOption(hProb,COIN_INT_SOLVEMETHOD)) {
     711                        case 0: method = ClpSolve::useDual;                             break;
     712                        case 1: method = ClpSolve::usePrimal;                   break;
     713                        case 2: method = ClpSolve::usePrimalorSprint;   break;
     714                        case 3: method = ClpSolve::useBarrier;                  break;
     715                        case 4: method = ClpSolve::useBarrierNoCross;   break;
     716                        case 5: method = ClpSolve::automatic;                   break;
     717                        default: method = ClpSolve::usePrimal;
     718                }
     719                pCoin->clp->setSolveType(method);   //ClpSolve::usePrimal
     720        }
     721
     722        if (CoinGetOptionChanged(hProb, COIN_INT_PRESOLVETYPE)) {   
     723                switch (CoinGetIntOption(hProb,COIN_INT_PRESOLVETYPE)) {
     724                        case 0: presolve = ClpSolve::presolveOn;                 break;
     725                        case 1: presolve = ClpSolve::presolveOff;                break;
     726                        case 2: presolve = ClpSolve::presolveNumber;     break;
     727                        default: presolve = ClpSolve::presolveOn;
     728                }
     729                pCoin->clp_options->setPresolveType(presolve);   //ClpSolve::presolveOn
     730        }
     731        return 1;
     732}
     733
     734
     735int coinSetCbcOptions(HPROB hProb)
     736{
     737        PCOIN pCoin = (PCOIN)hProb;
     738
     739        if (CoinGetOptionChanged(hProb, COIN_INT_MIPMAXNODES))          pCoin->cbc->setMaximumNodes(CoinGetIntOption(hProb, COIN_INT_MIPMAXNODES));
     740        if (CoinGetOptionChanged(hProb, COIN_INT_MIPMAXSOL))            pCoin->cbc->setMaximumSolutions(CoinGetIntOption(hProb, COIN_INT_MIPMAXSOL));
     741        if (CoinGetOptionChanged(hProb, COIN_REAL_MIPMAXSEC))           pCoin->cbc->setDblParam(CbcModel::CbcMaximumSeconds,CoinGetRealOption(hProb, COIN_REAL_MIPMAXSEC));
     742
     743        if (CoinGetOptionChanged(hProb, COIN_INT_MIPFATHOMDISC))        pCoin->cbc->setIntParam(CbcModel::CbcFathomDiscipline,CoinGetIntOption(hProb, COIN_INT_MIPFATHOMDISC));
     744
     745        // JPF commented: pCoin->cbc->setHotstartStrategy(CoinGetIntOption(hProb, COIN_INT_MIPHOTSTART));
     746        //              pCoin->cbc->setForcePriority(CoinGetIntOption(hProb, COIN_INT_MIPFORCEPRIOR));
     747
     748        if (CoinGetOptionChanged(hProb, COIN_INT_MIPMINIMUMDROP))       pCoin->cbc->setMinimumDrop(CoinGetIntOption(hProb, COIN_INT_MIPMINIMUMDROP));
     749        if (CoinGetOptionChanged(hProb, COIN_INT_MIPMAXPASSROOT))       pCoin->cbc->setMaximumCutPassesAtRoot(CoinGetIntOption(hProb, COIN_INT_MIPMAXPASSROOT));
     750        if (CoinGetOptionChanged(hProb, COIN_INT_MIPMAXCUTPASS))        pCoin->cbc->setMaximumCutPasses(CoinGetIntOption(hProb, COIN_INT_MIPMAXCUTPASS));
     751        if (CoinGetOptionChanged(hProb, COIN_INT_MIPSTRONGBRANCH))      pCoin->cbc->setNumberStrong(CoinGetIntOption(hProb, COIN_INT_MIPSTRONGBRANCH));
     752        if (CoinGetOptionChanged(hProb, COIN_INT_MIPSCANGLOBCUTS))      pCoin->cbc->setHowOftenGlobalScan(CoinGetIntOption(hProb, COIN_INT_MIPSCANGLOBCUTS));
     753
     754        if (CoinGetOptionChanged(hProb, COIN_REAL_MIPINTTOL))           pCoin->cbc->setIntegerTolerance(CoinGetRealOption(hProb, COIN_REAL_MIPINTTOL));
     755        if (CoinGetOptionChanged(hProb, COIN_REAL_MIPINFWEIGHT))        pCoin->cbc->setInfeasibilityWeight(CoinGetRealOption(hProb, COIN_REAL_MIPINFWEIGHT));
     756        if (CoinGetOptionChanged(hProb, COIN_REAL_MIPCUTOFF))           pCoin->cbc->setDblParam(CbcModel::CbcCutoffIncrement,CoinGetRealOption(hProb, COIN_REAL_MIPCUTOFF));
     757        if (CoinGetOptionChanged(hProb, COIN_REAL_MIPABSGAP))           pCoin->cbc->setAllowableGap(CoinGetRealOption(hProb, COIN_REAL_MIPABSGAP));
     758        return 1;
     759}
     760
     761
     762int coinSetCglOptions(HPROB hProb)
     763{
     764        PCOIN pCoin = (PCOIN)hProb;
     765
     766        /* see CbcModel.hpp has commments on calling cuts */
     767        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_PROBING)) {
     768                pCoin->probing = new CglProbing();
     769                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_MODE))        pCoin->probing->setMode(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MODE));
     770                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_USEOBJ))      pCoin->probing->setUsingObjective(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_USEOBJ) ? true : false);
     771                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_MAXPASS))     pCoin->probing->setMaxPass(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXPASS));
     772                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_MAXPROBE))    pCoin->probing->setMaxProbe(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXPROBE));
     773                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_MAXLOOK))     pCoin->probing->setMaxLook(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXLOOK));
     774                if (CoinGetOptionChanged(hProb, COIN_INT_MIPPROBE_ROWCUTS))     pCoin->probing->setRowCuts(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_ROWCUTS));
     775                pCoin->cbc->addCutGenerator(pCoin->probing,CoinGetIntOption(hProb, COIN_INT_MIPPROBE_FREQ),"Probing");
     776        }
     777
     778        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_GOMORY)) {
     779                pCoin->gomory = new CglGomory();
     780                if (CoinGetOptionChanged(hProb, COIN_INT_MIPGOMORY_LIMIT))      pCoin->gomory->setLimit(CoinGetIntOption(hProb, COIN_INT_MIPGOMORY_LIMIT));
     781                if (CoinGetOptionChanged(hProb, COIN_REAL_MIPGOMORY_AWAY))      pCoin->gomory->setAway(CoinGetRealOption(hProb, COIN_REAL_MIPGOMORY_AWAY));
     782                pCoin->cbc->addCutGenerator(pCoin->gomory,CoinGetIntOption(hProb, COIN_INT_MIPGOMORY_FREQ),"Gomory");
     783        }
     784
     785        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_KNAPSACK)) {
     786                pCoin->knapsack = new CglKnapsackCover();
     787                if (CoinGetOptionChanged(hProb, COIN_INT_MIPKNAPSACK_MAXIN))    pCoin->knapsack->setMaxInKnapsack(CoinGetIntOption(hProb, COIN_INT_MIPKNAPSACK_MAXIN));
     788                pCoin->cbc->addCutGenerator(pCoin->knapsack,CoinGetIntOption(hProb, COIN_INT_MIPKNAPSACK_FREQ),"Knapsack");
     789        }
     790
     791        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_ODDHOLE)) {
     792                pCoin->oddhole= new CglOddHole();
     793                if (CoinGetOptionChanged(hProb, COIN_REAL_MIPODDHOLE_MINVIOL))  pCoin->oddhole->setMinimumViolation(CoinGetRealOption(hProb, COIN_REAL_MIPODDHOLE_MINVIOL));
     794                if (CoinGetOptionChanged(hProb, COIN_REAL_MIPODDHOLE_MINVIOLPER))       pCoin->oddhole->setMinimumViolationPer(CoinGetRealOption(hProb, COIN_REAL_MIPODDHOLE_MINVIOLPER));
     795                if (CoinGetOptionChanged(hProb, COIN_INT_MIPODDHOLE_MAXENTRIES))        pCoin->oddhole->setMaximumEntries(CoinGetIntOption(hProb, COIN_INT_MIPODDHOLE_MAXENTRIES));
     796                pCoin->cbc->addCutGenerator(pCoin->oddhole,CoinGetIntOption(hProb, COIN_INT_MIPODDHOLE_FREQ),"OddHole");
     797        }
     798
     799        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_CLIQUE)) {
     800                pCoin->clique= new CglClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_PACKING) ? true : false);
     801                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_STAR))               pCoin->clique->setDoStarClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STAR) ? true : false);
     802                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_STARMETHOD)) pCoin->clique->setStarCliqueNextNodeMethod((CglClique::scl_next_node_method)CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARMETHOD));
     803                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_STARMAXLEN)) pCoin->clique->setStarCliqueCandidateLengthThreshold(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARMAXLEN));
     804                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_STARREPORT)) pCoin->clique->setStarCliqueReport(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARREPORT) ? true : false);
     805                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_ROW))                pCoin->clique->setDoRowClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROW) ? true : false);
     806                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_ROWMAXLEN))  pCoin->clique->setRowCliqueCandidateLengthThreshold(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROWMAXLEN));
     807                if (CoinGetOptionChanged(hProb, COIN_INT_MIPCLIQUE_ROWREPORT))  pCoin->clique->setRowCliqueReport(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROWREPORT) ? true : false);
     808                if (CoinGetOptionChanged(hProb, COIN_REAL_MIPCLIQUE_MINVIOL))   pCoin->clique->setMinViolation(CoinGetRealOption(hProb, COIN_REAL_MIPCLIQUE_MINVIOL));
     809                pCoin->cbc->addCutGenerator(pCoin->clique,CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_FREQ),"Clique");
     810        }
     811
     812        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_LIFTPROJECT)) {
     813                pCoin->liftpro = new CglLiftAndProject();
     814                if (CoinGetOptionChanged(hProb, COIN_INT_MIPLIFTPRO_BETAONE))   pCoin->liftpro->setBeta(CoinGetIntOption(hProb, COIN_INT_MIPLIFTPRO_BETAONE) ? 1 : -1);
     815                pCoin->cbc->addCutGenerator(pCoin->liftpro,CoinGetIntOption(hProb, COIN_INT_MIPLIFTPRO_FREQ),"LiftProject");
     816        }
     817
     818        if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_SIMPROUND)) {
     819                pCoin->rounding = new CglSimpleRounding();
     820                pCoin->cbc->addCutGenerator(pCoin->rounding,CoinGetIntOption(hProb, COIN_INT_MIPSIMPROUND_FREQ),"Rounding");
     821        }
     822        return 1;
     823}
     824
    636825
    637826SOLVAPI int CoinOptimizeProblem(HPROB hProb, int Method)
    638827{               
    639    PCOIN pCoin = (PCOIN)hProb;
    640    ClpSolve clp_options;
    641         ClpSolve::SolveType method;
    642         ClpSolve::PresolveType presolve;
    643 
    644         pCoin->clp->scaling(CoinGetIntOption(hProb,COIN_INT_SCALING));
    645         pCoin->clp->setPerturbation(CoinGetIntOption(hProb, COIN_INT_PERTURBATION));
    646 
    647         pCoin->clp->setMaximumIterations(CoinGetIntOption(hProb, COIN_INT_MAXITER));
    648 
    649         pCoin->clp->setPrimalObjectiveLimit(CoinGetIntOption(hProb, COIN_REAL_PRIMALOBJLIM));
    650         pCoin->clp->setDualObjectiveLimit(CoinGetIntOption(hProb, COIN_REAL_DUALOBJLIM));
    651         pCoin->clp->setPrimalTolerance(CoinGetIntOption(hProb, COIN_REAL_PRIMALOBJTOL));
    652         pCoin->clp->setDualTolerance(CoinGetIntOption(hProb, COIN_REAL_DUALOBJTOL));
    653 
    654         /* check if it has been changed, leave alone otherwise */
    655    ClpPrimalColumnSteepest primalSteepest(CoinGetIntOption(hProb, COIN_INT_PRIMALPIVOTALG));
    656    pCoin->clp->setPrimalColumnPivotAlgorithm(primalSteepest);
    657 
    658    ClpDualRowSteepest dualSteepest(CoinGetIntOption(hProb, COIN_INT_DUALPIVOTALG));
    659    pCoin->clp->setDualRowPivotAlgorithm(dualSteepest);
    660 
    661         if (CoinGetIntOption(hProb, COIN_INT_CRASHIND)) {
    662                 pCoin->clp->crash(CoinGetIntOption(hProb, COIN_REAL_CRASHGAP),
    663                                                                 CoinGetIntOption(hProb, COIN_INT_CRASHPIVOT));
    664         }
    665         switch (CoinGetIntOption(hProb,COIN_INT_SOLVEMETHOD)) {
    666                 case 0: method = ClpSolve::useDual;                              break;
    667                 case 1: method = ClpSolve::usePrimal;                    break;
    668                 case 2: method = ClpSolve::usePrimalorSprint; break;
    669                 case 3: method = ClpSolve::useBarrier;                   break;
    670                 case 4: method = ClpSolve::useBarrierNoCross; break;
    671                 case 5: method = ClpSolve::automatic;                    break;
    672                 default: method = ClpSolve::usePrimal;
    673         }
    674         pCoin->clp->setSolveType(method);   //ClpSolve::usePrimal
    675 
    676         switch (CoinGetIntOption(hProb,COIN_INT_PRESOLVETYPE)) {
    677                 case 0: presolve = ClpSolve::presolveOn;                 break;
    678                 case 1: presolve = ClpSolve::presolveOff;                break;
    679                 case 2: presolve = ClpSolve::presolveNumber;     break;
    680                 default: presolve = ClpSolve::presolveOn;
    681         }
    682         clp_options.setPresolveType(presolve);   //ClpSolve::presolveOn
     828        PCOIN pCoin = (PCOIN)hProb;
    683829
    684830        if (!pCoin->SolveAsMIP) {
    685                 pCoin->clp->initialSolve(clp_options);
     831                coinSetClpOptions(hProb);
     832                if (CoinGetOptionChanged(hProb, COIN_INT_PRESOLVETYPE))
     833                        pCoin->clp->initialSolve(*pCoin->clp_options);
     834                else {
     835                        pCoin->clp->initialSolve();
     836                }
    686837                pCoin->SolutionStatus = pCoin->clp->status();
    687838                }
    688839        else {
    689                 pCoin->cbc->setMaximumNodes(CoinGetIntOption(hProb, COIN_INT_MIPMAXNODES));
    690                 pCoin->cbc->setMaximumSolutions(CoinGetIntOption(hProb, COIN_INT_MIPMAXSOL));
    691                 pCoin->cbc->setDblParam(CbcModel::CbcMaximumSeconds,CoinGetRealOption(hProb, COIN_REAL_MIPMAXSEC));
    692 
    693                 pCoin->cbc->setIntParam(CbcModel::CbcFathomDiscipline,CoinGetIntOption(hProb, COIN_INT_MIPFATHOMDISC));
    694 
    695                 // JPF commented: pCoin->cbc->setHotstartStrategy(CoinGetIntOption(hProb, COIN_INT_MIPHOTSTART));
    696                 //              pCoin->cbc->setForcePriority(CoinGetIntOption(hProb, COIN_INT_MIPFORCEPRIOR));
    697 
    698                 pCoin->cbc->setMinimumDrop(CoinGetIntOption(hProb, COIN_INT_MIPMINIMUMDROP));
    699                 pCoin->cbc->setMaximumCutPassesAtRoot(CoinGetIntOption(hProb, COIN_INT_MIPMAXPASSROOT));
    700                 pCoin->cbc->setMaximumCutPasses(CoinGetIntOption(hProb, COIN_INT_MIPMAXCUTPASS));
    701                 pCoin->cbc->setNumberStrong(CoinGetIntOption(hProb, COIN_INT_MIPSTRONGBRANCH));
    702                 pCoin->cbc->setHowOftenGlobalScan(CoinGetIntOption(hProb, COIN_INT_MIPSCANGLOBCUTS));
    703 
    704                 pCoin->cbc->setIntegerTolerance(CoinGetRealOption(hProb, COIN_REAL_MIPINTTOL));
    705                 pCoin->cbc->setInfeasibilityWeight(CoinGetRealOption(hProb, COIN_REAL_MIPINFWEIGHT));
    706                 pCoin->cbc->setDblParam(CbcModel::CbcCutoffIncrement,CoinGetRealOption(hProb, COIN_REAL_MIPCUTOFF));
    707                 pCoin->cbc->setAllowableGap(CoinGetRealOption(hProb, COIN_REAL_MIPABSGAP));
    708 
    709                 /* see CbcModel.hpp has commments on calling cuts */
    710 
    711                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_PROBING)) {
    712                         pCoin->probing = new CglProbing();
    713                         pCoin->probing->setMode(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MODE));
    714                         pCoin->probing->setUsingObjective(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_USEOBJ) ? true : false);
    715                         pCoin->probing->setMaxPass(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXPASS));
    716                         pCoin->probing->setMaxProbe(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXPROBE));
    717                         pCoin->probing->setMaxLook(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_MAXLOOK));
    718                         pCoin->probing->setRowCuts(CoinGetIntOption(hProb, COIN_INT_MIPPROBE_ROWCUTS));
    719                         pCoin->cbc->addCutGenerator(pCoin->probing,CoinGetIntOption(hProb, COIN_INT_MIPPROBE_FREQ),"Probing");
    720                 }
    721 
    722                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_GOMORY)) {
    723                         pCoin->gomory = new CglGomory();
    724                         pCoin->gomory->setLimit(CoinGetIntOption(hProb, COIN_INT_MIPGOMORY_LIMIT));
    725                         pCoin->gomory->setAway(CoinGetRealOption(hProb, COIN_REAL_MIPGOMORY_AWAY));
    726                         pCoin->cbc->addCutGenerator(pCoin->gomory,CoinGetIntOption(hProb, COIN_INT_MIPGOMORY_FREQ),"Gomory");
    727                 }
    728 
    729                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_KNAPSACK)) {
    730                         pCoin->knapsack = new CglKnapsackCover();
    731                         pCoin->knapsack->setMaxInKnapsack(CoinGetIntOption(hProb, COIN_INT_MIPKNAPSACK_MAXIN));
    732                         pCoin->cbc->addCutGenerator(pCoin->knapsack,CoinGetIntOption(hProb, COIN_INT_MIPKNAPSACK_FREQ),"Knapsack");
    733                 }
    734 
    735                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_ODDHOLE)) {
    736                         pCoin->oddhole= new CglOddHole();
    737                         pCoin->oddhole->setMinimumViolation(CoinGetRealOption(hProb, COIN_REAL_MIPODDHOLE_MINVIOL));
    738                         pCoin->oddhole->setMinimumViolationPer(CoinGetRealOption(hProb, COIN_REAL_MIPODDHOLE_MINVIOLPER));
    739                         pCoin->oddhole->setMaximumEntries(CoinGetIntOption(hProb, COIN_INT_MIPODDHOLE_MAXENTRIES));
    740                         pCoin->cbc->addCutGenerator(pCoin->oddhole,CoinGetIntOption(hProb, COIN_INT_MIPODDHOLE_FREQ),"OddHole");
    741                 }
    742 
    743                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_CLIQUE)) {
    744                         pCoin->clique= new CglClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_PACKING) ? true : false);
    745                         pCoin->clique->setDoStarClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STAR) ? true : false);
    746                         pCoin->clique->setStarCliqueNextNodeMethod((CglClique::scl_next_node_method)CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARMETHOD));
    747                         pCoin->clique->setStarCliqueCandidateLengthThreshold(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARMAXLEN));
    748                         pCoin->clique->setStarCliqueReport(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_STARREPORT) ? true : false);
    749                         pCoin->clique->setDoRowClique(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROW) ? true : false);
    750                         pCoin->clique->setRowCliqueCandidateLengthThreshold(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROWMAXLEN));
    751                         pCoin->clique->setRowCliqueReport(CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_ROWREPORT) ? true : false);
    752                         pCoin->clique->setMinViolation(CoinGetRealOption(hProb, COIN_REAL_MIPCLIQUE_MINVIOL));
    753                         pCoin->cbc->addCutGenerator(pCoin->clique,CoinGetIntOption(hProb, COIN_INT_MIPCLIQUE_FREQ),"Clique");
    754                 }
    755 
    756                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_LIFTPROJECT)) {
    757                         pCoin->liftpro = new CglLiftAndProject();
    758                         pCoin->liftpro->setBeta(CoinGetIntOption(hProb, COIN_INT_MIPLIFTPRO_BETAONE) ? 1 : -1);
    759                         pCoin->cbc->addCutGenerator(pCoin->liftpro,CoinGetIntOption(hProb, COIN_INT_MIPLIFTPRO_FREQ),"LiftProject");
    760                 }
    761 
    762                 if (CoinGetIntOption(hProb, COIN_INT_MIPCUT_SIMPROUND)) {
    763                         pCoin->rounding = new CglSimpleRounding();
    764                         pCoin->cbc->addCutGenerator(pCoin->rounding,CoinGetIntOption(hProb, COIN_INT_MIPSIMPROUND_FREQ),"Rounding");
    765                 }
    766 
    767                 pCoin->cbc->initialSolve();
    768                 pCoin->cbc->branchAndBound();
    769                 pCoin->SolutionStatus = pCoin->cbc->status();
    770         }
    771        
     840#ifdef NEW_STYLE_CBCMAIN
     841                if (CoinGetIntOption(hProb, COIN_INT_MIPUSECBCMAIN)) {
     842                        coinSetClpOptions(hProb);
     843                        coinSetCbcOptions(hProb);
     844                        //coinSetCglOptions(hProb);  BK: CbcMain1 should call the Cgl's automatically
     845                        const int argc = 3;
     846                        const char *argv[] = {"CoinMP", "-solve", "-quit"};
     847                        CbcMain1(argc,argv,*pCoin->cbc);
     848                        pCoin->SolutionStatus = pCoin->cbc->status();
     849                        }
     850                else
     851#endif
     852                {
     853                        coinSetClpOptions(hProb);
     854                        coinSetCbcOptions(hProb);
     855                        coinSetCglOptions(hProb);
     856
     857                        pCoin->cbc->initialSolve();
     858                        pCoin->cbc->branchAndBound();
     859                        pCoin->SolutionStatus = pCoin->cbc->status();
     860                }
     861        }       
    772862        return pCoin->SolutionStatus;
    773863}
     
    791881                case 0: strcpy(pCoin->SolutionText, "Optimal solution found");          break;
    792882                case 1: strcpy(pCoin->SolutionText, "Problem primal infeasible");       break;
    793                 case 2:  strcpy(pCoin->SolutionText, "Problem dual infeasible");                break;
    794                 case 3:  strcpy(pCoin->SolutionText, "Stopped on iterations");                  break;
    795                 case 4:         strcpy(pCoin->SolutionText, "Stopped due to errors");                   break;
    796                 case 5:         strcpy(pCoin->SolutionText, "Stopped by user");         break;
     883                case 2: strcpy(pCoin->SolutionText, "Problem dual infeasible");         break;
     884                case 3: strcpy(pCoin->SolutionText, "Stopped on iterations");                   break;
     885                case 4: strcpy(pCoin->SolutionText, "Stopped due to errors");                   break;
     886                case 5: strcpy(pCoin->SolutionText, "Stopped by user");         break;
    797887        }
    798888        return pCoin->SolutionText;
     
    817907   PCOIN pCoin = (PCOIN)hProb;
    818908
    819    return 0;
     909        if (!pCoin->SolveAsMIP)
     910                return 0;
     911        else {
     912                return pCoin->cbc->getBestPossibleObjValue();
     913        }
    820914}
    821915
     
    825919   PCOIN pCoin = (PCOIN)hProb;
    826920
    827    return pCoin->clp->numberIterations();
     921        if (!pCoin->SolveAsMIP)
     922                return pCoin->clp->numberIterations();
     923        else {
     924                return pCoin->cbc->getIterationCount();
     925        }
    828926}
    829927
     
    870968                        Activity[i] = columnPrimal[i];
    871969                }
    872    }
     970        }
    873971        if (ReducedCost) {
    874972                columnDual = pCoin->clp->dualColumnSolution();
     
    876974                        ReducedCost[i] = columnDual[i];
    877975                }
    878    }
     976        }
    879977        if (SlackValues) {
    880978                rowPrimal = pCoin->clp->primalRowSolution();
     
    882980                        SlackValues[i] = rowPrimal[i];
    883981                }
    884    }
     982        }
    885983        if (ShadowPrice) {
    886984                rowDual = pCoin->clp->dualRowSolution();
     
    888986                        ShadowPrice[i] = rowDual[i];
    889987                }
    890    }
    891    return SOLV_SUCCESS;
     988        }
     989        return SOLV_SUCCESS;
    892990}
    893991
     
    9331031SOLVAPI int CoinWriteFile(HPROB hProb, int FileType, char* WriteFilename)
    9341032{
    935    PCOIN pCoin = (PCOIN)hProb;
     1033        PCOIN pCoin = (PCOIN)hProb;
    9361034
    9371035        switch (FileType) {
     
    9531051SOLVAPI int CoinOpenLogFile(HPROB hProb, char* logFilename)
    9541052{
    955    PCOIN pCoin = (PCOIN)hProb;
     1053        PCOIN pCoin = (PCOIN)hProb;
    9561054
    9571055        return SOLV_SUCCESS;
     
    9611059SOLVAPI int CoinCloseLogFile(HPROB hProb)
    9621060{
    963    PCOIN pCoin = (PCOIN)hProb;
     1061        PCOIN pCoin = (PCOIN)hProb;
    9641062
    9651063        return SOLV_SUCCESS;
     
    9771075
    9781076
    979 #define OPT_NONE                                0
    980 #define OPT_ONOFF                               1
    981 #define OPT_LIST                                2
     1077#define OPT_NONE                        0
     1078#define OPT_ONOFF                       1
     1079#define OPT_LIST                        2
    9821080#define OPT_INT                         3
    983 #define OPT_REAL                                4
     1081#define OPT_REAL                        4
    9841082#define OPT_STRING                      5
    9851083
    986 #define GRP_NONE           0
    987 #define GRP_OTHER          0
     1084#define GRP_NONE                        0
     1085#define GRP_OTHER                       0
    9881086
    9891087#define GRP_SIMPLEX                     1
     
    9911089#define GRP_LOGFILE                     3
    9921090#define GRP_LIMITS                      4
    993 #define GRP_MIPSTRAT                    5
    994 #define GRP_MIPCUTS        6
     1091#define GRP_MIPSTRAT            5
     1092#define GRP_MIPCUTS                     6
    9951093#define GRP_MIPTOL                      7
    9961094#define GRP_BARRIER                     8
     
    10041102
    10051103typedef struct {
    1006            char   OptionName[32];
    1007                           char   ShortName[32];
    1008                           int    GroupType;
    1009            OPTVAL DefaultValue;
    1010            OPTVAL CurrentValue;
    1011            OPTVAL MinValue;
    1012            OPTVAL MaxValue;
    1013                           int           OptionType;
    1014            int    changed;
    1015            int    OptionID;
     1104                        char   OptionName[32];
     1105                        char   ShortName[32];
     1106                        int    GroupType;
     1107                        OPTVAL DefaultValue;
     1108                        OPTVAL CurrentValue;
     1109                        OPTVAL MinValue;
     1110                        OPTVAL MaxValue;
     1111                        int             OptionType;
     1112                        int    changed;
     1113                        int    OptionID;
    10161114        } SOLVOPTINFO, *PSOLVOPT;
    10171115
    10181116
    1019 #define OPTIONCOUNT    66
     1117#define OPTIONCOUNT    67
    10201118
    10211119
     
    11181216          "MipSimpleRoundFrequency","SimpRoundFreq",GRP_MIPCUTS,       -1,       -1,-MAXINT,  MAXINT,  OPT_INT,    0,   COIN_INT_MIPSIMPROUND_FREQ,
    11191217
     1218          "MipUseCbcMain",          "UseCbcMain",   GRP_MIPSTRAT,       1,        1,      0,       1,  OPT_ONOFF,  0,   COIN_INT_MIPUSECBCMAIN,
    11201219        };
    11211220
     
    11831282}
    11841283
     1284SOLVAPI int CoinGetOptionChanged(HPROB hProb, int OptionID)
     1285{
     1286        PCOIN pCoin = (PCOIN)hProb;
     1287        int OptionNr;
     1288
     1289        OptionNr = LocateOptionID(OptionID);
     1290        if (OptionNr < 0) {
     1291                return 0;
     1292        }
     1293        return OptionTable[OptionNr].changed;
     1294}
    11851295
    11861296
     
    11951305        }
    11961306        if (OptionTable[OptionNr].OptionType != OPT_REAL)
    1197                 return OptionTable[OptionNr].CurrentValue;
     1307                return (int)OptionTable[OptionNr].CurrentValue;
    11981308        else {
    11991309                return 0;
     
    12051315SOLVAPI int CoinSetIntOption(HPROB hProb,int OptionID, int IntValue)
    12061316{
    1207    PCOIN pCoin = (PCOIN)hProb;
     1317        PCOIN pCoin = (PCOIN)hProb;
    12081318        int OptionNr;
    12091319
     
    12131323        }
    12141324        if (OptionTable[OptionNr].OptionType != OPT_REAL) {
     1325                CoinWriteMsgLog("%s[%d] = %d (was %d)",OptionTable[OptionNr].OptionName, OptionNr, IntValue, (int)OptionTable[OptionNr].CurrentValue);
    12151326                OptionTable[OptionNr].CurrentValue = IntValue;
     1327                OptionTable[OptionNr].changed = 1;
    12161328           return SOLV_SUCCESS;
    12171329        }
     
    12231335SOLVAPI double CoinGetRealOption(HPROB hProb,int OptionID)
    12241336{
    1225    PCOIN pCoin = (PCOIN)hProb;
     1337        PCOIN pCoin = (PCOIN)hProb;
    12261338        int OptionNr;
    12271339
     
    12401352SOLVAPI int CoinSetRealOption(HPROB hProb,int OptionID, double RealValue)
    12411353{
    1242    PCOIN pCoin = (PCOIN)hProb;
     1354        PCOIN pCoin = (PCOIN)hProb;
    12431355        int OptionNr;
    12441356
     
    12481360        }
    12491361        if (OptionTable[OptionNr].OptionType == OPT_REAL) {
     1362                CoinWriteMsgLog("%s[%d] = %lg (was %lg)",OptionTable[OptionNr].OptionName, OptionNr, RealValue, OptionTable[OptionNr].CurrentValue);
    12501363                OptionTable[OptionNr].CurrentValue = RealValue;
     1364                OptionTable[OptionNr].changed = 1;
    12511365           return SOLV_SUCCESS;
    12521366        }
  • trunk/CoinMP/src/CoinMP.h

    r69 r88  
    144144SOLVAPI int    CoinGetRealOptionMinMax(HPROB hProb, int OptionNr, double *MinValue, double *MaxValue);
    145145
     146SOLVAPI int CoinGetOptionChanged(HPROB hProb, int OptionID);
     147
    146148SOLVAPI int    CoinGetIntOption(HPROB hProb, int OptionID);
    147149SOLVAPI int    CoinSetIntOption(HPROB hProb, int OptionID, int IntValue);
     
    231233int    (SOLVFUNC *CoinGetIntOptionMinMax)(HPROB hProb, int OptionNr, int *MinValue, int *MaxValue);
    232234int    (SOLVFUNC *CoinGetRealOptionMinMax)(HPROB hProb, int OptionNr, double *MinValue, double *MaxValue);
     235
     236int        (SOLVAPI *CoinGetOptionChanged)(HPROB hProb, int OptionID);
    233237
    234238int    (SOLVFUNC *CoinGetIntOption)(HPROB hProb, int OptionID);
     
    337341#define COIN_INT_MIPSIMPROUND_FREQ       181   
    338342
    339 
    340 
    341 #endif
     343#define COIN_INT_MIPUSECBCMAIN           200   
     344
     345
     346#endif
Note: See TracChangeset for help on using the changeset viewer.