Changeset 2424


Ignore:
Timestamp:
Nov 17, 2018 10:29:59 AM (8 months ago)
Author:
unxusr
Message:

more functions to the C API

Location:
trunk/Cbc/src
Files:
2 edited

Legend:

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

    r2363 r2424  
    783783    if (VERBOSE > 0) printf("%s return\n", prefix);
    784784}
     785
     786
     787/** Adds a new column */
     788COINLIBAPI void COINLINKAGE
     789Cbc_addCol( Cbc_Model *model, const char *name, double lb, double ub, double obj, bool isInteger)
     790{
     791    OsiSolverInterface * solver = model->model_->solver();
     792
     793    /* to be used as dummy pointers */
     794    int rows; double coefs;
     795
     796    solver->addCol( 0, &rows, &coefs, lb, ub, obj, std::string(name) );
     797    if (isInteger)
     798        solver->setInteger(solver->getNumCols()-1 );
     799}
     800
     801/** Adds a new row */
     802COINLIBAPI void COINLINKAGE
     803Cbc_addRow( Cbc_Model *model, const char *name, int nz,
     804            const int *cols, const double *coefs, char sense, double rhs )
     805{
     806    OsiSolverInterface * solver = model->model_->solver();
     807    double rowLB = -DBL_MAX, rowUB = DBL_MAX;
     808    switch (toupper(sense))
     809    {
     810        case 'E':
     811            rowLB = rowUB = rhs;
     812            break;
     813        case 'L':
     814            rowUB = rhs;
     815            break;
     816        case 'G':
     817            rowLB = rhs;
     818            break;
     819        default:
     820            fprintf( stderr, "unkow row sense." );
     821            abort();
     822    }
     823    solver->addRow( nz, cols, coefs, rowLB, rowUB );
     824    solver->setRowName( solver->getNumCols()-1, std::string(name) );
     825}
     826 
    785827/** Add SOS constraints to the model using row-order matrix */
    786828
  • trunk/Cbc/src/Cbc_C_Interface.h

    r2363 r2424  
    212212    COINLIBAPI void COINLINKAGE
    213213    Cbc_setInteger(Cbc_Model * model, int iColumn)
     214    ;
     215    /** Adds a new column */
     216    COINLIBAPI void COINLINKAGE
     217    Cbc_addCol( Cbc_Model *model, const char *name, double lb,
     218            double ub, double obj, bool isInteger)
     219    ;
     220    /** Adds a new row */
     221    COINLIBAPI void COINLINKAGE
     222    Cbc_addRow( Cbc_Model *model, const char *name, int nz,
     223            const int *cols, const double *coefs, char sense, double rhs )
    214224    ;
    215225    /** Add SOS constraints to the model using row-order matrix */
Note: See TracChangeset for help on using the changeset viewer.