Changeset 2428 for trunk


Ignore:
Timestamp:
Nov 20, 2018 8:02:05 AM (7 months ago)
Author:
unxusr
Message:

more functions in Cbc_C_interface and possibility to solve (or resolve) just the lp relax

Location:
trunk/Cbc/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/Cbc_C_Interface.cpp

    r2427 r2428  
    241241
    242242    Cbc_Model * model = new Cbc_Model();
    243     OsiClpSolverInterface solver1;
    244     model->solver_    = &solver1;
     243    OsiClpSolverInterface solver1; // will be release at the end of the scope, CbcModel clones it
    245244    model->model_     = new CbcModel(solver1);
     245    model->solver_    = dynamic_cast<OsiClpSolverInterface *>(model->model_->solver());
    246246    CbcMain0(*model->model_);
    247247    model->handler_   = NULL;
     248    model->relax_ = 0;
    248249
    249250    if (VERBOSE > 0) printf("%s return\n", prefix);
     
    430431}
    431432
     433
     434COINLIBAPI int COINLINKAGE
     435Cbc_getNumIntegers(Cbc_Model * model)
     436{
     437    return model->model_->solver()->getNumIntegers();
     438}
     439
     440
    432441// Column starts in matrix
    433442COINLIBAPI const CoinBigIndex * COINLINKAGE
     
    551560}
    552561
     562COINLIBAPI void COINLINKAGE
     563Cbc_setSolveRelax(Cbc_Model * model, char solveOnlyRelax )
     564{
     565    model->relax_ = solveOnlyRelax;
     566}
    553567
    554568COINLIBAPI int COINLINKAGE
    555569Cbc_solve(Cbc_Model * model)
    556570{
     571    OsiSolverInterface *solver = model->solver_;
     572    if ( solver->getNumIntegers() == 0 || model->relax_ == 1 )
     573    {
     574        if ( solver->basisIsAvailable() ) {
     575            solver->resolve();
     576        }
     577        else {
     578            solver->initialSolve();
     579        }
     580
     581        if (solver->isProvenOptimal())
     582            return 0;
     583       
     584        return 1;
     585    }
     586
    557587    const char prefix[] = "Cbc_C_Interface::Cbc_solve(): ";
    558588    int result = 0;
     
    630660
    631661
    632 
    633662CbcGetProperty(int, getNumCols)
    634663CbcGetProperty(int, getNumRows)
    635664CbcGetProperty(int, getIterationCount)
    636 CbcGetProperty(int, isAbandoned)
    637 CbcGetProperty(int, isProvenOptimal)
    638 CbcGetProperty(int, isProvenInfeasible)
     665
     666/** Are there a numerical difficulties? */
     667COINLIBAPI int COINLINKAGE
     668Cbc_isAbandoned(Cbc_Model * model)
     669{
     670    if ( Cbc_getNumIntegers(model)==0 || model->relax_==1 )
     671        return model->solver_->isAbandoned();
     672    else
     673        return model->model_->isAbandoned();
     674}
     675
     676/** Is optimality proven? */
     677COINLIBAPI int COINLINKAGE
     678Cbc_isProvenOptimal(Cbc_Model * model)
     679{
     680    if ( Cbc_getNumIntegers(model)==0 || model->relax_==1 )
     681        return model->solver_->isProvenOptimal();
     682    else
     683        return model->model_->isProvenOptimal();
     684}
     685
     686COINLIBAPI int COINLINKAGE
     687Cbc_isProvenInfeasible(Cbc_Model * model)
     688{
     689    if ( Cbc_getNumIntegers(model)==0 || model->relax_==1 )
     690        return (model->solver_->isProvenDualInfeasible() || model->solver_->isProvenPrimalInfeasible());
     691    else
     692        return model->model_->isProvenInfeasible();
     693}
     694
    639695CbcGetProperty(int, isContinuousUnbounded)
    640696CbcGetProperty(int, isNodeLimitReached)
     
    669725CbcGetProperty(double, getObjValue)
    670726CbcGetProperty(double, getBestPossibleObjValue)
     727
     728COINLIBAPI double*  COINLINKAGE
     729Cbc_bestSolution(Cbc_Model * model)
     730{
     731    return model->model_->bestSolution();
     732}
    671733
    672734/* Print model */
     
    755817    result->handler_   = NULL;
    756818    result->cmdargs_   = model->cmdargs_;
     819    result->relax_     = model->relax_;
    757820
    758821    if (VERBOSE > 0) printf("%s return\n", prefix);
  • trunk/Cbc/src/Cbc_C_Interface.h

    r2427 r2428  
    8282    Cbc_readMps(Cbc_Model * model, const char *filename)
    8383    ;
     84    /** Read an lp file from the given filename */
     85    COINLIBAPI int COINLINKAGE
     86    Cbc_readLp(Cbc_Model * model, const char *filename)
     87    ;
    8488    /** Write an mps file from the given filename */
    8589    COINLIBAPI void COINLINKAGE
    8690    Cbc_writeMps(Cbc_Model * model, const char *filename)
    8791    ;
    88     /** Read an lp file from the given filename */
    89     COINLIBAPI int COINLINKAGE
    90     Cbc_readLp(Cbc_Model * model, const char *filename)
     92    /** Write an lp file from the given filename */
     93    COINLIBAPI void COINLINKAGE
     94    Cbc_writeLp(Cbc_Model * model, const char *filename)
    9195    ;
    9296    /** Provide an initial feasible solution to accelerate branch-and-bound
     
    152156    COINLIBAPI int COINLINKAGE
    153157    Cbc_getNumCols(Cbc_Model * model)
     158    ;
     159    /** Number of integer variables in the model */
     160    COINLIBAPI int COINLINKAGE
     161    Cbc_getNumIntegers(Cbc_Model * model)
    154162    ;
    155163    /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */
     
    354362    COINLIBAPI double COINLINKAGE
    355363    Cbc_getBestPossibleObjValue(Cbc_Model * model)
     364    ;
     365    /** Best integer feasible solution or NULL if no integer feas sol found */
     366    COINLIBAPI double*  COINLINKAGE
     367    Cbc_bestSolution(Cbc_Model * model)
    356368    ;
    357369    /** Number of nodes explored in B&B tree */
Note: See TracChangeset for help on using the changeset viewer.