Changeset 2032 for trunk


Ignore:
Timestamp:
May 8, 2014 12:11:17 AM (5 years ago)
Author:
mlubin
Message:

Implement Cbc_setInitialSolution for providing a feasible solution.

Location:
trunk/Cbc
Files:
3 edited

Legend:

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

    r2026 r2032  
    348348    if (VERBOSE > 0) printf("%s return\n", prefix);
    349349    return;
     350}
     351
     352
     353COINLIBAPI void COINLINKAGE
     354Cbc_setInitialSolution(Cbc_Model *model, const double * sol)
     355{
     356    int n = Cbc_getNumCols(model);
     357    // We need to manually compute the objective here for some reason
     358    const double *objvec = Cbc_getObjCoefficients(model);
     359    double objval = 0;
     360    for (int i = 0; i < n; i++) {
     361        objval += objvec[i]*sol[i];
     362    }
     363    model->model_->setBestSolution(sol, n, objval, true);
    350364}
    351365
  • trunk/Cbc/src/Cbc_C_Interface.h

    r2026 r2032  
    7676    COINLIBAPI void COINLINKAGE
    7777    Cbc_writeMps(Cbc_Model * model, const char *filename)
     78    ;
     79    /** Provide an initial feasible solution to accelerate branch-and-bound */
     80    COINLIBAPI void COINLINKAGE
     81    Cbc_setInitialSolution(Cbc_Model *model, const double * sol)
    7882    ;
    7983    /** Deletes rows */
  • trunk/Cbc/test/CInterfaceTest.c

    r2021 r2032  
    4040    double colub[] = {1,1,1,1,1};
    4141    double obj[] = {5, 3, 2, 7, 4};
     42    double feasible[] = {1,1,0,0,0};
    4243    double rowlb[] = {-INFINITY};
    4344    double rowub[] = {10};
     
    6970
    7071    Cbc_registerCallBack(model, test_callback);
     72
     73    Cbc_setInitialSolution(model, feasible);
    7174
    7275    Cbc_solve(model);
Note: See TracChangeset for help on using the changeset viewer.