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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.