Changeset 2016 for trunk/Cbc


Ignore:
Timestamp:
Mar 10, 2014 5:58:20 PM (5 years ago)
Author:
mlubin
Message:

More C interface work. Move C interface to libCbcSolver so that we can use CbcMain0 and CbcMain1.

Location:
trunk/Cbc
Files:
7 edited

Legend:

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

    r1898 r2016  
    232232    model->solver_->OsiClpSolverInterface::setHintParam(OsiDoReducePrint, true, OsiHintTry);
    233233    model->model_     = new CbcModel(solver1);
     234    CbcMain0(*model->model_);
    234235    model->handler_   = NULL;
    235236    model->information_ = NULL;
     
    310311    fflush(stdout);
    311312
    312     if (1) {
    313         solver->loadProblem(numcols, numrows, start, index, value,
    314                             collb, colub, obj, rowlb, rowub);
    315     } else {
    316         solver->loadProblem(0, 0, NULL, NULL, NULL,
    317                             NULL, NULL, NULL, NULL, NULL);
    318     }
     313    solver->loadProblem(numcols, numrows, start, index, value,
     314                        collb, colub, obj, rowlb, rowub);
    319315    if (VERBOSE > 1) printf("%s Finished solver->loadProblem()\n", prefix);
    320316    fflush(stdout);
     
    14791475
    14801476    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
     1477    return result;
     1478}
     1479COINLIBAPI int COINLINKAGE
     1480Cbc_solve(Cbc_Model * model)
     1481{
     1482    const char prefix[] = "Cbc_C_Interface::Cbc_solve(): ";
     1483    int result = 0;
     1484    const char *argv[] = {"Cbc_C_Interface","-solve", "-quit"};
     1485    try {
     1486       
     1487        CbcMain1(3, argv, *model->model_);
     1488    } catch (CoinError e) {
     1489        printf("%s ERROR: %s::%s, %s\n", prefix,
     1490               e.className().c_str(), e.methodName().c_str(), e.message().c_str());
     1491    }
     1492    result = model->model_->status();
     1493
    14811494    return result;
    14821495}
  • trunk/Cbc/src/Cbc_C_Interface.h

    r1898 r2016  
    400400    Cbc_branchAndBound(Cbc_Model * model)
    401401    ;
     402    /* Solve using CbcMain1. This is the recommended default solve function.
     403    */
     404    COINLIBAPI int COINLINKAGE
     405    Cbc_solve(Cbc_Model * model)
     406    ;
    402407    /** Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
    403408    COINLIBAPI void COINLINKAGE
  • trunk/Cbc/src/Makefile.am

    r2000 r2016  
    1919# List all source files for this library, including headers
    2020libCbc_la_SOURCES = \
    21         Cbc_C_Interface.cpp Cbc_C_Interface.h \
    2221        CbcConfig.h \
    2322        CbcBranchActual.hpp \
     
    9493
    9594libCbcSolver_la_SOURCES = \
     95        Cbc_C_Interface.cpp Cbc_C_Interface.h \
    9696        CbcCbcParam.cpp \
    9797        Cbc_ampl.cpp Cbc_ampl.h \
  • trunk/Cbc/src/Makefile.in

    r2000 r2016  
    9292@DEPENDENCY_LINKING_TRUE@libCbc_la_DEPENDENCIES =  \
    9393@DEPENDENCY_LINKING_TRUE@       $(am__DEPENDENCIES_1)
    94 am_libCbc_la_OBJECTS = Cbc_C_Interface.lo CbcBranchAllDifferent.lo \
    95         CbcBranchCut.lo CbcBranchDecision.lo \
    96         CbcBranchDefaultDecision.lo CbcBranchDynamic.lo \
    97         CbcBranchingObject.lo CbcBranchLotsize.lo \
     94am_libCbc_la_OBJECTS = CbcBranchAllDifferent.lo CbcBranchCut.lo \
     95        CbcBranchDecision.lo CbcBranchDefaultDecision.lo \
     96        CbcBranchDynamic.lo CbcBranchingObject.lo CbcBranchLotsize.lo \
    9897        CbcBranchToFixLots.lo CbcCompareDefault.lo CbcCompareDepth.lo \
    9998        CbcCompareEstimate.lo CbcCompareObjective.lo CbcConsequence.lo \
     
    121120@DEPENDENCY_LINKING_TRUE@libCbcSolver_la_DEPENDENCIES =  \
    122121@DEPENDENCY_LINKING_TRUE@       $(am__DEPENDENCIES_1) libCbc.la
    123 am_libCbcSolver_la_OBJECTS = CbcCbcParam.lo Cbc_ampl.lo CbcLinked.lo \
    124         CbcLinkedUtils.lo unitTestClp.lo CbcSolver.lo \
    125         CbcSolverHeuristics.lo CbcSolverAnalyze.lo CbcMipStartIO.lo \
    126         CbcSolverExpandKnapsack.lo
     122am_libCbcSolver_la_OBJECTS = Cbc_C_Interface.lo CbcCbcParam.lo \
     123        Cbc_ampl.lo CbcLinked.lo CbcLinkedUtils.lo unitTestClp.lo \
     124        CbcSolver.lo CbcSolverHeuristics.lo CbcSolverAnalyze.lo \
     125        CbcMipStartIO.lo CbcSolverExpandKnapsack.lo
    127126libCbcSolver_la_OBJECTS = $(am_libCbcSolver_la_OBJECTS)
    128127@COIN_HAS_CLP_TRUE@am__EXEEXT_1 = cbc$(EXEEXT)
     
    514513# List all source files for this library, including headers
    515514libCbc_la_SOURCES = \
    516         Cbc_C_Interface.cpp Cbc_C_Interface.h \
    517515        CbcConfig.h \
    518516        CbcBranchActual.hpp \
     
    589587
    590588libCbcSolver_la_SOURCES = \
     589        Cbc_C_Interface.cpp Cbc_C_Interface.h \
    591590        CbcCbcParam.cpp \
    592591        Cbc_ampl.cpp Cbc_ampl.h \
  • trunk/Cbc/test/CInterfaceTest.c

    r2010 r2016  
    44   This code is licensed under the terms of the Eclipse Public License (EPL). */
    55
     6#undef NDEBUG /* force asserts to work */
    67#include "Cbc_C_Interface.h"
    78#include <assert.h>
    89#include <math.h>
    910#include <stdio.h>
     11
    1012
    1113void testKnapsack() {
     
    4648    assert(Cbc_optimizationDirection(model) == 1);
    4749
    48     Cbc_branchAndBound(model);
     50    Cbc_solve(model);
    4951
    5052    assert(Cbc_isProvenOptimal(model));
    51     assert(abs( Cbc_objectiveValue(model)- (-16.0) < 1e-6));
     53    assert(fabs( Cbc_objectiveValue(model)- (-16.0) < 1e-6));
    5254   
    5355    sol = Cbc_getColSolution(model);
     
    6163}
    6264
     65void testIntegerInfeasible() {
     66
     67    Cbc_Model *model = Cbc_newModel();
     68
     69    /* Minimize x
     70     * s.t.     x <= -10
     71     * x binary */
     72
     73    CoinBigIndex start[] = {0, 1};
     74    int rowindex[] = {0};
     75    double value[] = {1.0};
     76    double rowlb[] = {-INFINITY};
     77    double rowub[] = {-10};
     78
     79    double collb[] = {0.0};
     80    double colub[] = {1.0};
     81    double obj[] = {1.0};
     82    char integer[] = {1};
     83
     84    Cbc_loadProblem(model, 1, 1, start, rowindex, value, collb, colub, obj, rowlb, rowub);
     85
     86    Cbc_copyInIntegerInformation(model, integer);
     87
     88    assert(Cbc_getNumCols(model) == 1);
     89    assert(Cbc_getNumRows(model) == 1);
     90
     91    Cbc_solve(model);
     92   
     93    assert(!Cbc_isProvenOptimal(model));
     94    assert(Cbc_isProvenPrimalInfeasible(model));
     95
     96}
     97
     98void testIntegerUnbounded() {
     99
     100    Cbc_Model *model = Cbc_newModel();
     101
     102    /* http://list.coin-or.org/pipermail/cbc/2014-March/001276.html
     103     * Minimize x
     104     * s.t. x + y <= 3
     105     *      x - y == 0
     106     *      x,y Free
     107     *      x integer */
     108
     109    CoinBigIndex start[] = {0,2,4};
     110    int rowindex[] = {0, 1, 0, 1};
     111    double value[] = {1, 1, 1, -1};
     112    double rowlb[] = {-INFINITY, 0.0};
     113    double rowub[] = {3.0,0.0};
     114    double collb[] = {-INFINITY, -INFINITY};
     115    double colub[] = {INFINITY, INFINITY};
     116    double obj[] = {1.0};
     117    char integer[] = {1,0};
     118
     119    Cbc_loadProblem(model, 2, 2, start, rowindex, value, collb, colub, obj, rowlb, rowub);
     120
     121    Cbc_copyInIntegerInformation(model, integer);
     122
     123    Cbc_solve(model);
     124   
     125    assert(!Cbc_isProvenOptimal(model));
     126    assert(!Cbc_isProvenPrimalInfeasible(model));
     127    assert(Cbc_isProvenDualInfeasible(model));
     128
     129
     130
     131}
     132
     133
    63134int main() {
    64135
    65136    testKnapsack();
     137    testIntegerInfeasible();
     138    testIntegerUnbounded();
    66139
    67140    return 0;
  • trunk/Cbc/test/Makefile.am

    r2010 r2016  
    9292CInterfaceTest_SOURCES = CInterfaceTest.c
    9393
    94 CInterfaceTest_LDADD = ../src/libCbc.la $(CBCLIB_LIBS)
     94CInterfaceTest_LDADD = ../src/libCbcSolver.la ../src/libCbc.la $(CBCLIB_LIBS)
    9595
    96 CInterfaceTest_DEPENDENCIES = ../src/libCbc.la $(CBCLIB_DEPENDENCIES)
     96CInterfaceTest_DEPENDENCIES = ../src/libCbcSolver.la ../src/libCbc.la $(CBCLIB_DEPENDENCIES)
    9797
    9898ctests: CInterfaceTest$(EXEEXT)
  • trunk/Cbc/test/Makefile.in

    r2010 r2016  
    454454########################################################################
    455455CInterfaceTest_SOURCES = CInterfaceTest.c
    456 CInterfaceTest_LDADD = ../src/libCbc.la $(CBCLIB_LIBS)
    457 CInterfaceTest_DEPENDENCIES = ../src/libCbc.la $(CBCLIB_DEPENDENCIES)
     456CInterfaceTest_LDADD = ../src/libCbcSolver.la ../src/libCbc.la $(CBCLIB_LIBS)
     457CInterfaceTest_DEPENDENCIES = ../src/libCbcSolver.la ../src/libCbc.la $(CBCLIB_DEPENDENCIES)
    458458
    459459########################################################################
Note: See TracChangeset for help on using the changeset viewer.