Ignore:
Timestamp:
Mar 17, 2014 4:21:18 PM (5 years ago)
Author:
mlubin
Message:

Improved documentation. Tests for callbacks and row/column names. More restructuring.

File:
1 edited

Legend:

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

    r2020 r2021  
    44// This code is licensed under the terms of the Eclipse Public License (EPL).
    55
    6 #include <math.h>
     6#include <cmath>
    77#include <cfloat>
    88
     
    220220
    221221/* Version */
    222 COINLIBAPI double COINLINKAGE Cbc_getVersion()
    223 {
    224     double v = 1.0;
    225     return v;
     222COINLIBAPI const char* COINLINKAGE Cbc_getVersion()
     223{
     224    return CBC_VERSION;
    226225}
    227226
     
    485484    return (result) ? 1 : 0;
    486485}
    487 /* Status of problem:
    488    0 - optimal
    489    1 - primal infeasible
    490    2 - dual infeasible
    491    3 - stopped on iterations etc
    492    4 - stopped due to errors
    493 */
     486
    494487CbcGetProperty(int, status)
    495488
    496 /* Secondary status of problem - may get extended
    497    0 - none
    498    1 - primal infeasible because dual limit reached
    499    2 - scaled problem optimal - unscaled has primal infeasibilities
    500    3 - scaled problem optimal - unscaled has dual infeasibilities
    501    4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
    502 */
    503489CbcGetProperty(int, secondaryStatus)
    504 
    505 COINLIBAPI void COINLINKAGE
    506 Cbc_setSecondaryStatus(Cbc_Model * /*model*/, int /*status*/)
    507 {
    508     const char prefix[] = "Cbc_C_Interface::Cbc_setSecondaryStatus(): ";
    509 //  const int  VERBOSE = 1;
    510     if (VERBOSE > 0) printf("%s begin\n", prefix);
    511 
    512 // cannot find this in Cbc, Osi, or OsiClp
    513 //tbd  model->model_->setSecondaryStatus(status);
    514     if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
    515 
    516     if (VERBOSE > 0) printf("%s return\n", prefix);
    517 }
    518490
    519491/* Number of elements in matrix */
     
    558530}
    559531
    560 // Column vector lengths in matrix
    561 COINLIBAPI const int * COINLINKAGE
    562 Cbc_getVectorLengths(Cbc_Model * model)
    563 {
    564     const char prefix[] = "Cbc_C_Interface::Cbc_getVectorLengths(): ";
    565 //  const int  VERBOSE = 1;
    566     if (VERBOSE > 0) printf("%s begin\n", prefix);
    567 
    568     const int * result = NULL;
    569     const CoinPackedMatrix * matrix = NULL;
    570     matrix = model->model_->solver()->getMatrixByCol();
    571     result = (matrix == NULL) ? NULL : matrix->getVectorLengths();
    572 
    573     if (VERBOSE > 0)
    574         printf("%s return %p\n", prefix, static_cast<const void*>(result));
    575     return result;
    576 }
    577532
    578533// Element values in matrix
     
    606561    if (VERBOSE > 0) printf("%s begin\n", prefix);
    607562
    608     // reuse existing log level
    609     int oldLogLevel = model->model_->messageHandler()->logLevel();
    610563    // Will be copy of users one
    611564    delete model->handler_;
     
    614567    model->handler_->setModel(model);
    615568    model->model_->passInMessageHandler(model->handler_);
    616     model->model_->messageHandler()->setLogLevel(oldLogLevel);
    617569
    618570    if (VERBOSE > 0) printf("%s return\n", prefix);
     
    632584}
    633585/* length of names (0 means no names0 */
    634 COINLIBAPI int COINLINKAGE
    635 Cbc_lengthNames(Cbc_Model * /*model*/)
    636 {
    637     const char prefix[] = "Cbc_C_Interface::Cbc_lengthNames(): ";
    638 //  const int  VERBOSE = 1;
    639     if (VERBOSE > 0) printf("%s begin\n", prefix);
    640 
    641     int result = 0;
    642 // cannot find names in Cbc, Osi, or OsiClp
    643 //tbd  result = model->model_->lengthNames();
    644     if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
    645 
    646     if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
     586COINLIBAPI size_t COINLINKAGE
     587Cbc_maxNameLength(Cbc_Model * model)
     588{
     589    size_t result = 0;
     590    OsiSolverInterface::OsiNameVec const & rownames = model->model_->solver()->getRowNames();
     591    for (size_t i = 0; i < rownames.size(); i++) {
     592        if (rownames[i].length() > result) result = rownames[i].length();
     593    }
     594    OsiSolverInterface::OsiNameVec const & colnames = model->model_->solver()->getColNames();
     595    for (size_t i = 0; i < colnames.size(); i++) {
     596        if (colnames[i].length() > result) result = colnames[i].length();
     597    }
    647598    return result;
    648599}
    649 /* Fill in array (at least lengthNames+1 long) with a row name */
    650 COINLIBAPI void COINLINKAGE
    651 Cbc_rowName(Cbc_Model * /*model*/, int iRow, char * name)
    652 {
    653     const char prefix[] = "Cbc_C_Interface::Cbc_rowName(): ";
    654 //  const int  VERBOSE = 1;
    655     if (VERBOSE > 0) printf("%s begin\n", prefix);
    656 
    657     sprintf(name, "ROW%5i", iRow);
    658 // cannot find names in Cbc, Osi, or OsiClp
    659 //tbd  std::string rowName=model->model_->rowName(iRow);
    660 //tbd  strcpy(name,rowName.c_str());
    661 
    662     if (VERBOSE > 0) printf("%s return\n", prefix);
    663 }
    664 /* Fill in array (at least lengthNames+1 long) with a column name */
    665 // cannot find names in Cbc, Osi, or OsiClp
    666 COINLIBAPI void COINLINKAGE
    667 Cbc_columnName(Cbc_Model * /*model*/, int iColumn, char * name)
    668 {
    669     const char prefix[] = "Cbc_C_Interface::Cbc_columnName(): ";
    670 //  const int  VERBOSE = 1;
    671     if (VERBOSE > 0) printf("%s begin\n", prefix);
    672 
    673     sprintf(name, "COL%5i", iColumn);
    674 //tbd  std::string columnName= model->model_->columnName(iColumn);
    675 //tbd  strcpy(name,columnName.c_str());
    676 
    677     if (VERBOSE > 0) printf("%s return\n", prefix);
    678 }
     600COINLIBAPI void COINLINKAGE
     601Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength)
     602{
     603    std::string rowname = model->model_->solver()->getRowName(iRow);
     604    strncpy(name, rowname.c_str(), maxLength);
     605    name[maxLength-1] = '\0';
     606}
     607COINLIBAPI void COINLINKAGE
     608Cbc_getColName(Cbc_Model * model, int iRow, char * name, size_t maxLength)
     609{
     610    std::string colname = model->model_->solver()->getColName(iRow);
     611    strncpy(name, colname.c_str(), maxLength);
     612    name[maxLength-1] = '\0';
     613}
     614
     615COINLIBAPI void COINLINKAGE
     616Cbc_setColName(Cbc_Model * model, int iColumn, const char * name)
     617{
     618    model->model_->solver()->setColName(iColumn, name);
     619}
     620
     621COINLIBAPI void COINLINKAGE
     622Cbc_setRowName(Cbc_Model * model, int iRow, const char * name)
     623{
     624    model->model_->solver()->setRowName(iRow, name);
     625}
     626
    679627
    680628COINLIBAPI int COINLINKAGE
     
    782730CbcGetProperty(const double*, getColSolution)
    783731
    784 COINLIBAPI void COINLINKAGE
    785 Cbc_setColSolution(Cbc_Model * model, const double * input)
    786 {
    787     const char prefix[] = "Cbc_C_Interface::Cbc_setColSolution(): ";
    788 //  const int  VERBOSE = 1;
    789     if (VERBOSE > 0) printf("%s begin\n", prefix);
    790 
    791     OsiSolverInterface * solver = model->model_->solver();
    792     solver->setColSolution(input);
    793 
    794     if (VERBOSE > 0) printf("%s return\n", prefix);
    795     return;
    796 }
    797 
    798732CbcGetProperty(const double*, getRowLower)
    799733CbcGetProperty(const double*, getRowUpper)
     
    803737
    804738CbcGetProperty(double, getObjValue)
     739CbcGetProperty(double, getBestPossibleObjValue)
    805740
    806741/* Print model */
     
    874809}
    875810
    876 COINLIBAPI double COINLINKAGE
    877 Cbc_cpuTime(Cbc_Model * /*model*/)
    878 {
    879     const char prefix[] = "Cbc_C_Interface::Cbc_cpuTime(): ";
    880 //  const int  VERBOSE = 1;
    881     if (VERBOSE > 0) printf("%s begin\n", prefix);
    882 
    883     double result = 0;
    884     result = CoinCpuTime() ;
    885 
    886     if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
    887     return result;
    888 }
    889 
    890811CbcGetProperty(int, getNodeCount)
    891812
     
    902823    result->solver_    = dynamic_cast< OsiClpSolverInterface*> (result->model_->solver());
    903824    result->handler_   = NULL;
     825    result->cmdargs_   = model->cmdargs_;
    904826
    905827    if (VERBOSE > 0) printf("%s return\n", prefix);
     
    1075997}
    1076998
    1077 /** Delete all object information */
    1078 COINLIBAPI void  COINLINKAGE
    1079 Cbc_deleteObjects(Cbc_Model * model)
    1080 {
    1081     const char prefix[] = "Cbc_C_Interface::Cbc_deleteObjects(): ";
    1082 //  const int  VERBOSE = 2;
    1083     if (VERBOSE > 0) printf("%s begin\n", prefix);
    1084 
    1085     model->model_->deleteObjects();
    1086 
    1087     if (VERBOSE > 0) printf("%s return\n", prefix);
    1088     return;
    1089 }
    1090 
    1091999/** Print the solution */
    10921000COINLIBAPI void  COINLINKAGE
Note: See TracChangeset for help on using the changeset viewer.