Changeset 2020 for trunk/Cbc/src


Ignore:
Timestamp:
Mar 13, 2014 2:09:41 PM (6 years ago)
Author:
mlubin
Message:

Allow passing arbitrary command-line parameters using the C interface

Location:
trunk/Cbc/src
Files:
2 edited

Legend:

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

    r2019 r2020  
    237237    OsiClpSolverInterface solver1;
    238238    model->solver_    = &solver1;
    239     model->solver_->OsiClpSolverInterface::setHintParam(OsiDoReducePrint, true, OsiHintTry);
    240239    model->model_     = new CbcModel(solver1);
    241240    CbcMain0(*model->model_);
     
    461460}
    462461
    463 /* Objective offset */
    464 COINLIBAPI double COINLINKAGE
    465 Cbc_objectiveOffset(Cbc_Model * /*model*/)
    466 {
    467     const char prefix[] = "Cbc_C_Interface::Cbc_objectiveOffset(): ";
    468 //  const int  VERBOSE = 1;
    469     if (VERBOSE > 0) printf("%s begin\n", prefix);
    470 
    471     double result = 0.0;
    472 // cannot find names in Cbc, Osi, or OsiClp
    473 //tbd  return model->model_->objectiveOffset();
    474     if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
    475 
    476     if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
    477     return result;
    478 }
    479 COINLIBAPI void COINLINKAGE
    480 Cbc_setObjectiveOffset(Cbc_Model * /*model*/, double /*value*/)
    481 {
    482     const char prefix[] = "Cbc_C_Interface::Cbc_setObjectiveOffset(): ";
    483 //  const int  VERBOSE = 1;
    484     if (VERBOSE > 0) printf("%s begin\n", prefix);
    485 
    486 // cannot find names in Cbc, Osi, or OsiClp
    487 //tbd  model->model_->solver()->setObjectiveOffset(value);
    488     if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
    489 
    490     if (VERBOSE > 0) printf("%s return\n", prefix);
    491 }
     462
     463COINLIBAPI void COINLINKAGE
     464Cbc_setParameter(Cbc_Model * model, const char * name, const char * value)
     465{
     466    model->cmdargs_.push_back(std::string("-")+name);
     467    model->cmdargs_.push_back(value);
     468}
     469
    492470/* Fills in array with problem name  */
    493471COINLIBAPI void COINLINKAGE
    494472Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array)
    495473{
    496     const char prefix[] = "Cbc_C_Interface::Cbc_problemName(): ";
    497 //  const int  VERBOSE = 1;
    498     if (VERBOSE > 0) printf("%s begin\n", prefix);
    499 
    500474    std::string name;
    501475    model->model_->solver()->getStrParam(OsiProbName, name);
    502     maxNumberCharacters = CoinMin(maxNumberCharacters, (int)strlen(name.c_str()));
    503     strncpy(array, name.c_str(), maxNumberCharacters - 1);
    504     array[maxNumberCharacters-1] = '\0';
    505 
    506     if (VERBOSE > 0) printf("%s return\n", prefix);
     476    strncpy(array, name.c_str(), maxNumberCharacters);
    507477}
    508478/* Sets problem name.  Must have \0 at end.  */
    509479COINLIBAPI int COINLINKAGE
    510 Cbc_setProblemName(Cbc_Model * model, int /*maxNumberCharacters*/, char * array)
    511 {
    512     const char prefix[] = "Cbc_C_Interface::Cbc_setProblemName(): ";
    513 //  const int  VERBOSE = 1;
    514     if (VERBOSE > 0) printf("%s begin\n", prefix);
    515 
     480Cbc_setProblemName(Cbc_Model * model, const char * array)
     481{
    516482    bool result = false;
    517483    result = model->model_->solver()->setStrParam(OsiProbName, array);
    518484
    519     if (VERBOSE > 0) printf("%s return\n", prefix);
    520485    return (result) ? 1 : 0;
    521486}
     
    718683    const char prefix[] = "Cbc_C_Interface::Cbc_solve(): ";
    719684    int result = 0;
    720     const char *argv[] = {"Cbc_C_Interface","-solve", "-quit"};
     685    std::vector<const char*> argv;
     686    argv.push_back("Cbc_C_Interface");
     687    for (size_t i = 0; i < model->cmdargs_.size(); i++) {
     688        argv.push_back(model->cmdargs_[i].c_str());
     689    }
     690    argv.push_back("-solve");
     691    argv.push_back("-quit");
    721692    try {
    722693       
    723         CbcMain1(3, argv, *model->model_);
     694        CbcMain1((int)argv.size(), &argv[0], *model->model_);
    724695    } catch (CoinError e) {
    725696        printf("%s ERROR: %s::%s, %s\n", prefix,
  • trunk/Cbc/src/Cbc_C_Interface.h

    r2019 r2020  
    112112    /**@name gets and sets - you will find some synonyms at the end of this file */
    113113    /*@{*/
    114     /** Objective offset */
    115     COINLIBAPI double COINLINKAGE
    116     Cbc_objectiveOffset(Cbc_Model * model)
    117     ;
    118     COINLIBAPI void COINLINKAGE
    119     Cbc_setObjectiveOffset(Cbc_Model * model, double value)
     114    /** Set parameter "name" to value "value". Note that this
     115     * translates directly to using "-name value" as a
     116     * command-line argument to Cbc.*/
     117    COINLIBAPI void COINLINKAGE
     118    Cbc_setParameter(Cbc_Model * model, const char * name, const char * value)
    120119    ;
    121120    /** Fills in array with problem name  */
     
    128127    */
    129128    COINLIBAPI int COINLINKAGE
    130     Cbc_setProblemName(Cbc_Model * model, int maxNumberCharacters, char * array)
     129    Cbc_setProblemName(Cbc_Model * model, const char * array)
    131130    ;
    132131    /** Status of problem:
Note: See TracChangeset for help on using the changeset viewer.