source: trunk/Cbc/src/Cbc_C_Interface.cpp @ 2016

Last change on this file since 2016 was 2016, checked in by mlubin, 5 years ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 81.8 KB
Line 
1// $Id: Cbc_C_Interface.cpp 2016 2014-03-10 21:58:20Z mlubin $
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#include <math.h>
7#include <cfloat>
8
9#include "CoinPragma.hpp"
10//#include "CoinHelperFunctions.hpp"
11//#include "CoinPackedMatrix.hpp"
12#include "CoinTime.hpp"
13
14#include "CbcModel.hpp"
15#include "CbcBranchActual.hpp"
16
17#include "CoinMessageHandler.hpp"
18#include "OsiClpSolverInterface.hpp"
19
20//  bobe including extras.h to get strdup()
21#if defined(__MWERKS__)
22// #include <extras.h>  // bobe 06-02-14
23#endif
24
25// Get C stuff but with extern C
26#define CBC_EXTERN_C
27#include "Coin_C_defines.h"
28
29const int  VERBOSE = 0;
30
31// To allow call backs
32class Cbc_MessageHandler
33            : public CoinMessageHandler {
34
35public:
36    /**@name Overrides */
37    //@{
38    virtual int print();
39    //@}
40    /**@name set and get */
41    //@{
42    /// Model
43    const Cbc_Model * model() const;
44    void setModel(Cbc_Model * model);
45    /// Call back
46    void setCallBack(cbc_callback callback);
47    //@}
48
49    /**@name Constructors, destructor */
50    //@{
51    /** Default constructor. */
52    Cbc_MessageHandler();
53    /// Constructor with pointer to model
54    Cbc_MessageHandler(Cbc_Model * model,
55                       FILE * userPointer = NULL);
56    /** Destructor */
57    virtual ~Cbc_MessageHandler();
58    //@}
59
60    /**@name Copy method */
61    //@{
62    /** The copy constructor. */
63    Cbc_MessageHandler(const Cbc_MessageHandler&);
64    /** The copy constructor from an CoinSimplexMessageHandler. */
65    Cbc_MessageHandler(const CoinMessageHandler&);
66
67    Cbc_MessageHandler& operator=(const Cbc_MessageHandler&);
68    /// Clone
69    virtual CoinMessageHandler * clone() const ;
70    //@}
71
72
73protected:
74    /**@name Data members
75       The data members are protected to allow access for derived classes. */
76    //@{
77    /// Pointer back to model
78    Cbc_Model * model_;
79    /// call back
80    cbc_callback callback_;
81    //@}
82};
83
84
85//-------------------------------------------------------------------
86// Default Constructor
87//-------------------------------------------------------------------
88Cbc_MessageHandler::Cbc_MessageHandler ()
89        : CoinMessageHandler(),
90        model_(NULL),
91        callback_(NULL)
92{
93}
94
95//-------------------------------------------------------------------
96// Copy constructor
97//-------------------------------------------------------------------
98Cbc_MessageHandler::Cbc_MessageHandler (const Cbc_MessageHandler & rhs)
99        : CoinMessageHandler(rhs),
100        model_(rhs.model_),
101        callback_(rhs.callback_)
102{
103}
104
105Cbc_MessageHandler::Cbc_MessageHandler (const CoinMessageHandler & rhs)
106        : CoinMessageHandler(rhs),
107        model_(NULL),
108        callback_(NULL)
109{
110}
111
112// Constructor with pointer to model
113Cbc_MessageHandler::Cbc_MessageHandler(Cbc_Model * model,
114                                       FILE * /*userPointer*/)
115        : CoinMessageHandler(),
116        model_(model),
117        callback_(NULL)
118{
119}
120
121//-------------------------------------------------------------------
122// Destructor
123//-------------------------------------------------------------------
124Cbc_MessageHandler::~Cbc_MessageHandler ()
125{
126}
127
128//----------------------------------------------------------------
129// Assignment operator
130//-------------------------------------------------------------------
131Cbc_MessageHandler &
132Cbc_MessageHandler::operator=(const Cbc_MessageHandler & rhs)
133{
134    if (this != &rhs) {
135        CoinMessageHandler::operator=(rhs);
136        model_ = rhs.model_;
137        callback_ = rhs.callback_;
138    }
139    return *this;
140}
141//-------------------------------------------------------------------
142// Clone
143//-------------------------------------------------------------------
144CoinMessageHandler * Cbc_MessageHandler::clone() const
145{
146    return new Cbc_MessageHandler(*this);
147}
148int
149Cbc_MessageHandler::print()
150{
151    if (callback_) {
152        int messageNumber = currentMessage().externalNumber();
153        if (currentSource() != "Cbc")
154            messageNumber += 1000000;
155        int i;
156        int nDouble = numberDoubleFields();
157        assert (nDouble <= 200);
158        double vDouble[200];
159        for (i = 0; i < nDouble; i++)
160            vDouble[i] = doubleValue(i);
161        int nInt = numberIntFields();
162        assert (nInt <= 200);
163        int vInt[200];
164        for (i = 0; i < nInt; i++)
165            vInt[i] = intValue(i);
166        int nString = numberStringFields();
167        assert (nString <= 200);
168        char * vString[200];
169        for (i = 0; i < nString; i++) {
170            std::string value = stringValue(i);
171            vString[i] = CoinStrdup(value.c_str());
172        }
173        callback_(model_, messageNumber,
174                  nDouble, vDouble,
175                  nInt, vInt,
176                  nString, vString);
177        for (i = 0; i < nString; i++)
178            free(vString[i]);
179
180    }
181    return CoinMessageHandler::print();
182    return 0;
183}
184const Cbc_Model *
185Cbc_MessageHandler::model() const
186{
187    return model_;
188}
189void
190Cbc_MessageHandler::setModel(Cbc_Model * model)
191{
192    model_ = model;
193}
194// Call back
195void
196Cbc_MessageHandler::setCallBack(cbc_callback callback)
197{
198    callback_ = callback;
199}
200/**
201  *
202  *  C Interface Routines
203  *
204  */
205#include "Cbc_C_Interface.h"
206#include <string>
207#include <stdio.h>
208#include <iostream>
209
210#if defined(__MWERKS__)
211#pragma export on
212#endif
213
214/* Version */
215COINLIBAPI double COINLINKAGE Cbc_getVersion()
216{
217    double v = 1.0;
218    return v;
219}
220
221/* Default Cbc_Model constructor */
222COINLIBAPI Cbc_Model *  COINLINKAGE
223Cbc_newModel()
224{
225    const char prefix[] = "Cbc_C_Interface::Cbc_newModel(): ";
226//  const int  VERBOSE = 1;
227    if (VERBOSE > 0) printf("%s begin\n", prefix);
228
229    Cbc_Model * model = new Cbc_Model;
230    OsiClpSolverInterface solver1;
231    model->solver_    = &solver1;
232    model->solver_->OsiClpSolverInterface::setHintParam(OsiDoReducePrint, true, OsiHintTry);
233    model->model_     = new CbcModel(solver1);
234    CbcMain0(*model->model_);
235    model->handler_   = NULL;
236    model->information_ = NULL;
237
238    if (VERBOSE > 0) printf("%s return\n", prefix);
239    return model;
240}
241/* Cbc_Model Destructor */
242COINLIBAPI void COINLINKAGE
243Cbc_deleteModel(Cbc_Model * model)
244{
245    const char prefix[] = "Cbc_C_Interface::Cbc_deleteModel(): ";
246//  const int  VERBOSE = 1;
247    if (VERBOSE > 0) printf("%s begin\n", prefix);
248    fflush(stdout);
249
250    if (VERBOSE > 1) printf("%s delete model->model_\n", prefix);
251    fflush(stdout);
252    delete model->model_;
253
254    if (VERBOSE > 1) printf("%s delete model->handler_\n", prefix);
255    fflush(stdout);
256    delete model->handler_;
257
258    if (VERBOSE > 1) printf("%s free model->information_\n", prefix);
259    fflush(stdout);
260    if (model->information_) free(model->information_);
261
262    if (VERBOSE > 1) printf("%s delete model\n", prefix);
263    fflush(stdout);
264    delete model;
265
266    if (VERBOSE > 0) printf("%s return\n", prefix);
267    fflush(stdout);
268}
269
270/* Loads a problem (the constraints on the
271    rows are given by lower and upper bounds). If a pointer is NULL then the
272    following values are the default:
273    <ul>
274    <li> <code>colub</code>: all columns have upper bound infinity
275    <li> <code>collb</code>: all columns have lower bound 0
276    <li> <code>rowub</code>: all rows have upper bound infinity
277    <li> <code>rowlb</code>: all rows have lower bound -infinity
278    <li> <code>obj</code>: all variables have 0 objective coefficient
279    </ul>
280
281   Just like the other loadProblem() method except that the matrix is
282   given in a standard column major ordered format (without gaps).
283*/
284COINLIBAPI void COINLINKAGE
285Cbc_loadProblem (Cbc_Model * model,  const int numcols, const int numrows,
286                 const CoinBigIndex * start, const int* index,
287                 const double* value,
288                 const double* collb, const double* colub,
289                 const double* obj,
290                 const double* rowlb, const double* rowub)
291{
292    const char prefix[] = "Cbc_C_Interface::Cbc_loadProblem(): ";
293//  const int  VERBOSE = 2;
294    if (VERBOSE > 0) printf("%s begin\n", prefix);
295
296    OsiSolverInterface * solver = model->model_->solver();
297
298    if (VERBOSE > 1) {
299        printf("%s numcols = %i, numrows = %i\n",
300               prefix, numcols, numrows);
301        printf("%s model = %p, start = %p, index = %p, value = %p\n",
302               prefix, static_cast<void*>(model), static_cast<const void*>(start),
303               static_cast<const void*>(index), static_cast<const void*>(value));
304        printf("%s collb = %p, colub = %p, obj = %p, rowlb = %p, rowub = %p\n",
305               prefix, static_cast<const void*>(collb),
306               static_cast<const void*>(colub), static_cast<const void*>(obj),
307               static_cast<const void*>(rowlb), static_cast<const void*>(rowub));
308    }
309
310    if (VERBOSE > 1) printf("%s Calling solver->loadProblem()\n", prefix);
311    fflush(stdout);
312
313    solver->loadProblem(numcols, numrows, start, index, value,
314                        collb, colub, obj, rowlb, rowub);
315    if (VERBOSE > 1) printf("%s Finished solver->loadProblem()\n", prefix);
316    fflush(stdout);
317
318    if (VERBOSE > 0) printf("%s return\n", prefix);
319} //  Cbc_loadProblem()
320
321/* Read an mps file from the given filename */
322COINLIBAPI int COINLINKAGE
323Cbc_readMps(Cbc_Model * model, const char *filename)
324{
325    const char prefix[] = "Cbc_C_Interface::Cbc_readMps(): ";
326//  const int  VERBOSE = 2;
327    if (VERBOSE > 0) printf("%s begin\n", prefix);
328    if (VERBOSE > 1) printf("%s filename = '%s'\n", prefix, filename);
329
330    int result = 1;
331    result = model->model_->solver()->readMps(filename);
332    assert(result == 0);
333
334    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
335    return result;
336}
337/* Write an mps file from the given filename */
338COINLIBAPI void COINLINKAGE
339Cbc_writeMps(Cbc_Model * model, const char *filename)
340{
341    const char prefix[] = "Cbc_C_Interface::Cbc_writeMps(): ";
342//  const int  VERBOSE = 2;
343    if (VERBOSE > 0) printf("%s begin\n", prefix);
344    if (VERBOSE > 1) printf("%s filename = '%s'\n", prefix, filename);
345
346    model->model_->solver()->writeMps(filename, "mps", Cbc_optimizationDirection(model));
347
348    if (VERBOSE > 0) printf("%s return\n", prefix);
349    return;
350}
351/* Integer information */
352COINLIBAPI char * COINLINKAGE
353Cbc_integerInformation(Cbc_Model * model)
354{
355    const char prefix[] = "Cbc_C_Interface::Cbc_integerInformation(): ";
356//  const int  VERBOSE = 1;
357    if (VERBOSE > 0) printf("%s begin\n", prefix);
358
359    int col;
360    int numcols = Cbc_getNumCols(model);
361
362    // allocate model->information_ if null
363    // this is freed in Cbc_deleteModel() if not null
364    if (!model->information_)
365        model->information_ = (char *) malloc(numcols * sizeof(char));
366
367    for (col = 0; col < numcols; col++)
368        if (model->model_->solver()->isContinuous(col))
369            model->information_[col] = 0;
370        else
371            model->information_[col] = 1;
372
373    char * result = model->information_;
374
375    if (VERBOSE > 0) printf("%s return %p\n", prefix, result);
376    return result;
377}
378/* Copy in integer information */
379COINLIBAPI void COINLINKAGE
380Cbc_copyInIntegerInformation(Cbc_Model * model, const char * information)
381{
382    const char prefix[] = "Cbc_C_Interface::Cbc_copyInIntegerInformation(): ";
383//  const int  VERBOSE = 1;
384    if (VERBOSE > 0) printf("%s begin\n", prefix);
385
386    int col;
387    int numcols = Cbc_getNumCols(model);
388    for (col = 0; col < numcols; col++)
389        if (information[col])
390            model->model_->solver()->setInteger(col);
391        else
392            model->model_->solver()->setContinuous(col);
393
394    if (VERBOSE > 0) printf("%s return\n", prefix);
395}
396/* Drop integer informations */
397COINLIBAPI void COINLINKAGE
398Cbc_deleteIntegerInformation(Cbc_Model * /*model*/)
399{
400    const char prefix[] = "Cbc_C_Interface::Cbc_deleteIntegerInformation(): ";
401//  const int  VERBOSE = 1;
402    if (VERBOSE > 0) printf("%s begin\n", prefix);
403
404//  available through
405//    OsiClpSolverInterface::setContinuous
406//tbd  model->model_->deleteIntegerInformation();
407    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
408
409    if (VERBOSE > 0) printf("%s return\n", prefix);
410}
411/* Resizes rim part of model  */
412COINLIBAPI void COINLINKAGE
413Cbc_resize (Cbc_Model * /*model*/, int /*newNumberRows*/,
414            int /*newNumberColumns*/)
415{
416    const char prefix[] = "Cbc_C_Interface::Cbc_resize(): ";
417//  const int  VERBOSE = 1;
418    if (VERBOSE > 0) printf("%s begin\n", prefix);
419
420// cannot find this in Cbc, Osi, or OsiClp
421//tbd  model->model_->solver()->resize(newNumberRows,newNumberColumns);
422    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
423
424    if (VERBOSE > 0) printf("%s return\n", prefix);
425}
426/* Deletes rows */
427COINLIBAPI void COINLINKAGE
428Cbc_deleteRows(Cbc_Model * model, int number, const int * which)
429{
430    const char prefix[] = "Cbc_C_Interface::Cbc_deleteRows(): ";
431//  const int  VERBOSE = 1;
432    if (VERBOSE > 0) printf("%s begin\n", prefix);
433
434    OsiSolverInterface * solver = model->model_->solver();
435    solver->deleteRows(number, which);
436
437    if (VERBOSE > 0) printf("%s return\n", prefix);
438}
439/* Add rows */
440COINLIBAPI void COINLINKAGE
441Cbc_addRows(Cbc_Model * /*model*/, const int /*number*/,
442            const double * /*rowLower*/,
443            const double * /*rowUpper*/,
444            const int * /*rowStarts*/, const int * /*columns*/,
445            const double * /*elements*/)
446{
447    const char prefix[] = "Cbc_C_Interface::Cbc_addRows(): ";
448//  const int  VERBOSE = 1;
449    if (VERBOSE > 0) printf("%s begin\n", prefix);
450
451// available through OsiClp
452//tbd  model->model_->addRows(number,rowLower,rowUpper,rowStarts,columns,elements);
453    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
454
455    if (VERBOSE > 0) printf("%s return\n", prefix);
456}
457
458/* Deletes columns */
459COINLIBAPI void COINLINKAGE
460Cbc_deleteColumns(Cbc_Model * model, int number, const int * which)
461{
462    const char prefix[] = "Cbc_C_Interface::Cbc_deleteColumns(): ";
463//  const int  VERBOSE = 1;
464    if (VERBOSE > 0) printf("%s begin\n", prefix);
465
466    OsiSolverInterface * solver = model->model_->solver();
467    solver->deleteCols(number, which);
468
469    if (VERBOSE > 0) printf("%s return\n", prefix);
470}
471/* Add columns */
472COINLIBAPI void COINLINKAGE
473Cbc_addColumns(Cbc_Model * /*model*/, int /*number*/,
474               const double * /*columnLower*/,
475               const double * /*columnUpper*/,
476               const double * /*objective*/,
477               const int * /*columnStarts*/, const int * /*rows*/,
478               const double * /*elements*/)
479{
480    const char prefix[] = "Cbc_C_Interface::Cbc_addColumns(): ";
481//  const int  VERBOSE = 1;
482    if (VERBOSE > 0) printf("%s begin\n", prefix);
483
484// available through OsiClp
485//tbd  model->model_->addColumns(number,columnLower,columnUpper,objective,
486//tbd                       columnStarts,rows,elements);
487    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
488
489    if (VERBOSE > 0) printf("%s return\n", prefix);
490}
491/* Drops names - makes lengthnames 0 and names empty */
492COINLIBAPI void COINLINKAGE
493Cbc_dropNames(Cbc_Model * /*model*/)
494{
495    const char prefix[] = "Cbc_C_Interface::Cbc_dropNames(): ";
496//  const int  VERBOSE = 1;
497    if (VERBOSE > 0) printf("%s begin\n", prefix);
498
499// cannot find names in Cbc, Osi, or OsiClp
500//tbd  model->model_->dropNames();
501    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
502
503    if (VERBOSE > 0) printf("%s return\n", prefix);
504}
505/* Copies in names */
506COINLIBAPI void COINLINKAGE
507Cbc_copyNames(Cbc_Model * /*model*/, const char * const * /*rowNamesIn*/,
508              const char * const * /*columnNamesIn*/)
509{
510    const char prefix[] = "Cbc_C_Interface::Cbc_copyNames(): ";
511//  const int  VERBOSE = 1;
512    if (VERBOSE > 0) printf("%s begin\n", prefix);
513
514// cannot find names in Cbc, Osi, or OsiClp
515    /*clean
516      int iRow;
517      std::vector<std::string> rowNames;
518      int numberRows = model->model_->getNumRows();
519      rowNames.reserve(numberRows);
520      for (iRow=0;iRow<numberRows;iRow++) {
521        rowNames.push_back(rowNamesIn[iRow]);
522      }
523
524      int iColumn;
525      std::vector<std::string> columnNames;
526      int numberColumns = model->model_->getNumCols();
527      columnNames.reserve(numberColumns);
528      for (iColumn=0;iColumn<numberColumns;iColumn++) {
529        columnNames.push_back(columnNamesIn[iColumn]);
530      }
531      model->model_->copyNames(rowNames,columnNames);
532    */
533
534    if (VERBOSE > 0) printf("%s return\n", prefix);
535}
536
537/* Number of rows */
538COINLIBAPI int COINLINKAGE
539Cbc_numberRows(Cbc_Model * model)
540{
541    const char prefix[] = "Cbc_C_Interface::Cbc_numberRows(): ";
542//  const int  VERBOSE = 1;
543    if (VERBOSE > 0) printf("%s begin\n", prefix);
544
545    int result = 0;
546    result = model->model_->getNumRows();
547
548    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
549    return result;
550}
551/* Number of columns */
552COINLIBAPI int COINLINKAGE
553Cbc_numberColumns(Cbc_Model * model)
554{
555    const char prefix[] = "Cbc_C_Interface::Cbc_numberColumns(): ";
556//  const int  VERBOSE = 1;
557    if (VERBOSE > 0) printf("%s begin\n", prefix);
558
559    int result = 0;
560    result = model->model_->getNumCols();
561
562    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
563    return result;
564}
565/* Primal tolerance to use */
566COINLIBAPI double COINLINKAGE
567Cbc_primalTolerance(Cbc_Model * model)
568{
569    const char prefix[] = "Cbc_C_Interface::Cbc_primalTolerance(): ";
570//  const int  VERBOSE = 1;
571    if (VERBOSE > 0) printf("%s begin\n", prefix);
572
573    double result = 0.0;
574    model->model_->solver()->getDblParam(OsiPrimalTolerance, result) ;
575
576    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
577    return result;
578}
579COINLIBAPI void COINLINKAGE
580Cbc_setPrimalTolerance(Cbc_Model * model,  double value)
581{
582    const char prefix[] = "Cbc_C_Interface::Cbc_setPrimalTolerance(): ";
583//  const int  VERBOSE = 1;
584    if (VERBOSE > 0) printf("%s begin\n", prefix);
585
586    model->model_->solver()->setDblParam(OsiPrimalTolerance, value) ;
587
588    if (VERBOSE > 0) printf("%s return\n", prefix);
589}
590/* Dual tolerance to use */
591COINLIBAPI double COINLINKAGE
592Cbc_dualTolerance(Cbc_Model * model)
593{
594    const char prefix[] = "Cbc_C_Interface::Cbc_dualTolerance(): ";
595//  const int  VERBOSE = 1;
596    if (VERBOSE > 0) printf("%s begin\n", prefix);
597
598    double result = 0.0;
599    model->model_->solver()->getDblParam(OsiDualTolerance, result) ;
600
601    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
602    return result;
603}
604COINLIBAPI void COINLINKAGE
605Cbc_setDualTolerance(Cbc_Model * model,  double value)
606{
607    const char prefix[] = "Cbc_C_Interface::Cbc_setDualTolerance(): ";
608//  const int  VERBOSE = 1;
609    if (VERBOSE > 0) printf("%s begin\n", prefix);
610
611    model->model_->solver()->setDblParam(OsiDualTolerance, value) ;
612
613    if (VERBOSE > 0) printf("%s return\n", prefix);
614}
615/* Integer tolerance to use */
616COINLIBAPI double COINLINKAGE
617Cbc_integerTolerance(Cbc_Model * model)
618{
619    const char prefix[] = "Cbc_C_Interface::Cbc_primalTolerance(): ";
620//  const int  VERBOSE = 1;
621    if (VERBOSE > 0) printf("%s begin\n", prefix);
622
623    double result = 0.0;
624    result = model->model_->getDblParam(CbcModel::CbcIntegerTolerance) ;
625
626    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
627    return result;
628}
629COINLIBAPI void COINLINKAGE
630Cbc_setIntegerTolerance(Cbc_Model * model,  double value)
631{
632    const char prefix[] = "Cbc_C_Interface::Cbc_setPrimalTolerance(): ";
633//  const int  VERBOSE = 1;
634    if (VERBOSE > 0) printf("%s begin\n", prefix);
635
636    model->model_->setDblParam(CbcModel::CbcIntegerTolerance, value) ;
637
638    if (VERBOSE > 0) printf("%s return\n", prefix);
639}
640/* Dual objective limit */
641COINLIBAPI double COINLINKAGE
642Cbc_dualObjectiveLimit(Cbc_Model * model)
643{
644    const char prefix[] = "Cbc_C_Interface::Cbc_dualObjectiveLimit(): ";
645//  const int  VERBOSE = 1;
646    if (VERBOSE > 0) printf("%s begin\n", prefix);
647
648    double result = 0.0;
649    model->model_->solver()->getDblParam(OsiDualObjectiveLimit, result) ;
650
651    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
652    return result;
653}
654COINLIBAPI void COINLINKAGE
655Cbc_setDualObjectiveLimit(Cbc_Model * model, double value)
656{
657    const char prefix[] = "Cbc_C_Interface::Cbc_setDualObjectiveLimit(): ";
658//  const int  VERBOSE = 1;
659    if (VERBOSE > 0) printf("%s begin\n", prefix);
660
661    model->model_->solver()->setDblParam(OsiDualObjectiveLimit, value) ;
662
663    if (VERBOSE > 0) printf("%s return\n", prefix);
664}
665/* Objective offset */
666COINLIBAPI double COINLINKAGE
667Cbc_objectiveOffset(Cbc_Model * /*model*/)
668{
669    const char prefix[] = "Cbc_C_Interface::Cbc_objectiveOffset(): ";
670//  const int  VERBOSE = 1;
671    if (VERBOSE > 0) printf("%s begin\n", prefix);
672
673    double result = 0.0;
674// cannot find names in Cbc, Osi, or OsiClp
675//tbd  return model->model_->objectiveOffset();
676    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
677
678    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
679    return result;
680}
681COINLIBAPI void COINLINKAGE
682Cbc_setObjectiveOffset(Cbc_Model * /*model*/, double /*value*/)
683{
684    const char prefix[] = "Cbc_C_Interface::Cbc_setObjectiveOffset(): ";
685//  const int  VERBOSE = 1;
686    if (VERBOSE > 0) printf("%s begin\n", prefix);
687
688// cannot find names in Cbc, Osi, or OsiClp
689//tbd  model->model_->solver()->setObjectiveOffset(value);
690    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
691
692    if (VERBOSE > 0) printf("%s return\n", prefix);
693}
694/* Fills in array with problem name  */
695COINLIBAPI void COINLINKAGE
696Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array)
697{
698    const char prefix[] = "Cbc_C_Interface::Cbc_problemName(): ";
699//  const int  VERBOSE = 1;
700    if (VERBOSE > 0) printf("%s begin\n", prefix);
701
702    std::string name;
703    model->model_->solver()->getStrParam(OsiProbName, name);
704    maxNumberCharacters = CoinMin(maxNumberCharacters, (int)strlen(name.c_str()));
705    strncpy(array, name.c_str(), maxNumberCharacters - 1);
706    array[maxNumberCharacters-1] = '\0';
707
708    if (VERBOSE > 0) printf("%s return\n", prefix);
709}
710/* Sets problem name.  Must have \0 at end.  */
711COINLIBAPI int COINLINKAGE
712Cbc_setProblemName(Cbc_Model * model, int /*maxNumberCharacters*/, char * array)
713{
714    const char prefix[] = "Cbc_C_Interface::Cbc_setProblemName(): ";
715//  const int  VERBOSE = 1;
716    if (VERBOSE > 0) printf("%s begin\n", prefix);
717
718    bool result = false;
719    result = model->model_->solver()->setStrParam(OsiProbName, array);
720
721    if (VERBOSE > 0) printf("%s return\n", prefix);
722    return (result) ? 1 : 0;
723}
724/* Number of iterations */
725COINLIBAPI int COINLINKAGE
726Cbc_numberIterations(Cbc_Model * model)
727{
728    const char prefix[] = "Cbc_C_Interface::Cbc_numberIterations(): ";
729//  const int  VERBOSE = 1;
730    if (VERBOSE > 0) printf("%s begin\n", prefix);
731
732    int result = 0;
733    result = model->model_->getIterationCount();
734
735    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
736    return result;
737}
738COINLIBAPI void COINLINKAGE
739Cbc_setNumberIterations(Cbc_Model * /*model*/, int /*numberIterations*/)
740{
741    const char prefix[] = "Cbc_C_Interface::Cbc_setNumberIterations(): ";
742//  const int  VERBOSE = 1;
743    if (VERBOSE > 0) printf("%s begin\n", prefix);
744
745// cannot find this in Cbc, Osi, or OsiClp
746//tbd  model->model_->setNumberIterations(numberIterations);
747    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
748
749    if (VERBOSE > 0) printf("%s return\n", prefix);
750    return;
751}
752/* Maximum number of iterations */
753COINLIBAPI int COINLINKAGE
754Cbc_maximumIterations(Cbc_Model * /*model*/)
755{
756    const char prefix[] = "Cbc_C_Interface::Cbc_maximumIterations(): ";
757//  const int  VERBOSE = 1;
758    if (VERBOSE > 0) printf("%s begin\n", prefix);
759
760    int result = 0;
761// cannot find this in Cbc, Osi, or OsiClp
762//tbd  result = model->model_->solver()->maximumIterations();
763    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
764
765    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
766    return result;
767}
768COINLIBAPI void COINLINKAGE
769Cbc_setMaximumIterations(Cbc_Model * /*model*/, int /*value*/)
770{
771    const char prefix[] = "Cbc_C_Interface::Cbc_setMaximumIterations(): ";
772//  const int  VERBOSE = 1;
773    if (VERBOSE > 0) printf("%s begin\n", prefix);
774
775// cannot find this in Cbc, Osi, or OsiClp
776//tbd  model->model_->setMaximumIterations(value);
777    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
778
779    if (VERBOSE > 0) printf("%s return\n", prefix);
780}
781/* Maximum number of nodes */
782COINLIBAPI int COINLINKAGE
783Cbc_maxNumNode(Cbc_Model * model)
784{
785    const char prefix[] = "Cbc_C_Interface::Cbc_maxNumNode(): ";
786//  const int  VERBOSE = 1;
787    if (VERBOSE > 0) printf("%s begin\n", prefix);
788
789    int result = 0;
790    result = model->model_->getIntParam(CbcModel::CbcMaxNumNode);
791
792    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
793    return result;
794}
795COINLIBAPI void COINLINKAGE
796Cbc_setMaxNumNode(Cbc_Model * model, int value)
797{
798    const char prefix[] = "Cbc_C_Interface::Cbc_setMaxNumNode(): ";
799//  const int  VERBOSE = 1;
800    if (VERBOSE > 0) printf("%s begin\n", prefix);
801
802    model->model_->setIntParam(CbcModel::CbcMaxNumNode, value);
803
804    if (VERBOSE > 0) printf("%s return\n", prefix);
805}
806/* Maximum number of solutions */
807COINLIBAPI int COINLINKAGE
808Cbc_maxNumSol(Cbc_Model * model)
809{
810    const char prefix[] = "Cbc_C_Interface::maxNumSol(): ";
811//  const int  VERBOSE = 1;
812    if (VERBOSE > 0) printf("%s begin\n", prefix);
813
814    int result = 0;
815    result = model->model_->getIntParam(CbcModel::CbcMaxNumSol);
816
817    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
818    return result;
819}
820COINLIBAPI void COINLINKAGE
821Cbc_setMaxNumSol(Cbc_Model * model, int value)
822{
823    const char prefix[] = "Cbc_C_Interface::Cbc_setMaxNumSol(): ";
824//  const int  VERBOSE = 1;
825    if (VERBOSE > 0) printf("%s begin\n", prefix);
826
827    model->model_->setIntParam(CbcModel::CbcMaxNumSol, value);
828
829    if (VERBOSE > 0) printf("%s return\n", prefix);
830}
831/* Maximum time in seconds (from when set called) */
832COINLIBAPI double COINLINKAGE
833Cbc_maximumSeconds(Cbc_Model * model)
834{
835    const char prefix[] = "Cbc_C_Interface::Cbc_maximumSeconds(): ";
836//  const int  VERBOSE = 1;
837    if (VERBOSE > 0) printf("%s begin\n", prefix);
838
839    double result = 0.0;
840    result = model->model_->getDblParam(CbcModel::CbcMaximumSeconds);
841
842    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
843    return result;
844}
845COINLIBAPI void COINLINKAGE
846Cbc_setMaximumSeconds(Cbc_Model * model, double value)
847{
848    const char prefix[] = "Cbc_C_Interface::Cbc_setMaximumSeconds(): ";
849//  const int  VERBOSE = 1;
850    if (VERBOSE > 0) printf("%s begin\n", prefix);
851
852    model->model_->setDblParam(CbcModel::CbcMaximumSeconds, value);
853
854    if (VERBOSE > 0) printf("%s return\n", prefix);
855}
856/* Returns true if hit maximum iteratio`ns (or time) */
857COINLIBAPI int COINLINKAGE
858Cbc_hitMaximumIterations(Cbc_Model * /*model*/)
859{
860    const char prefix[] = "Cbc_C_Interface::Cbc_hitMaximumIterations(): ";
861//  const int  VERBOSE = 1;
862    if (VERBOSE > 0) printf("%s begin\n", prefix);
863
864    int result = 0;
865// cannot find names in Cbc, Osi, or OsiClp
866//tbd  result = model->model_->solver()->hitMaximumIterations() ? 1 : 0;
867    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
868
869    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
870    return result;
871}
872/* Status of problem:
873   0 - optimal
874   1 - primal infeasible
875   2 - dual infeasible
876   3 - stopped on iterations etc
877   4 - stopped due to errors
878*/
879COINLIBAPI int COINLINKAGE
880Cbc_status(Cbc_Model * model)
881{
882    const char prefix[] = "Cbc_C_Interface::Cbc_status(): ";
883//  const int  VERBOSE = 1;
884    if (VERBOSE > 0) printf("%s begin\n", prefix);
885
886    int result = 0;
887    result = model->model_->status();
888
889    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
890    return result;
891}
892/* Set problem status */
893COINLIBAPI void COINLINKAGE
894Cbc_setProblemStatus(Cbc_Model * /*model*/, int /*problemStatus*/)
895{
896    const char prefix[] = "Cbc_C_Interface::Cbc_setProblemStatus(): ";
897//  const int  VERBOSE = 1;
898    if (VERBOSE > 0) printf("%s begin\n", prefix);
899
900// cannot find this in Cbc, Osi, or OsiClp
901//tbd  model->model_->setProblemStatus(problemStatus);
902    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
903
904    if (VERBOSE > 0) printf("%s return\n", prefix);
905}
906/* Secondary status of problem - may get extended
907   0 - none
908   1 - primal infeasible because dual limit reached
909   2 - scaled problem optimal - unscaled has primal infeasibilities
910   3 - scaled problem optimal - unscaled has dual infeasibilities
911   4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
912*/
913COINLIBAPI int COINLINKAGE
914Cbc_secondaryStatus(Cbc_Model * model)
915{
916    const char prefix[] = "Cbc_C_Interface::Cbc_secondaryStatus(): ";
917//  const int  VERBOSE = 1;
918    if (VERBOSE > 0) printf("%s begin\n", prefix);
919
920    int result = 0;
921// cannot find this in Cbc, Osi, or OsiClp
922    result = model->model_->secondaryStatus();
923    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
924
925    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
926    return result;
927}
928COINLIBAPI void COINLINKAGE
929Cbc_setSecondaryStatus(Cbc_Model * /*model*/, int /*status*/)
930{
931    const char prefix[] = "Cbc_C_Interface::Cbc_setSecondaryStatus(): ";
932//  const int  VERBOSE = 1;
933    if (VERBOSE > 0) printf("%s begin\n", prefix);
934
935// cannot find this in Cbc, Osi, or OsiClp
936//tbd  model->model_->setSecondaryStatus(status);
937    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
938
939    if (VERBOSE > 0) printf("%s return\n", prefix);
940}
941/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
942COINLIBAPI double COINLINKAGE
943Cbc_optimizationDirection(Cbc_Model * model)
944{
945    const char prefix[] = "Cbc_C_Interface::Cbc_optimizationDirection(): ";
946//  const int  VERBOSE = 1;
947    if (VERBOSE > 0) printf("%s begin\n", prefix);
948
949    double result = 0.0;
950    result = model->model_->getObjSense();
951
952    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
953    return result;
954}
955COINLIBAPI void COINLINKAGE
956Cbc_setOptimizationDirection(Cbc_Model * model, double value)
957{
958    const char prefix[] = "Cbc_C_Interface::Cbc_setOptimizationDirection(): ";
959//  const int  VERBOSE = 1;
960    if (VERBOSE > 0) printf("%s begin, value = %g\n", prefix, value);
961
962    model->model_->setObjSense(value);
963//  model->model_->solver()->setObjSense(value);
964
965    if (VERBOSE > 0) printf("%s return\n", prefix);
966}
967/* Primal row solution */
968COINLIBAPI double * COINLINKAGE
969Cbc_primalRowSolution(Cbc_Model * /*model*/)
970{
971    const char prefix[] = "Cbc_C_Interface::Cbc_primalRowSolution(): ";
972//  const int  VERBOSE = 1;
973    if (VERBOSE > 0) printf("%s begin\n", prefix);
974
975    double * result = NULL;
976
977// cannot find this in Cbc, Osi, or OsiClp
978// may have to make it somehow
979//tbd  return model->model_->primalRowSolution();
980    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
981
982    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
983    return result;
984}
985/* Primal column solution */
986COINLIBAPI double * COINLINKAGE
987Cbc_primalColumnSolution(Cbc_Model * /*model*/)
988{
989    const char prefix[] = "Cbc_C_Interface::Cbc_primalColumnSolution(): ";
990//  const int  VERBOSE = 1;
991    if (VERBOSE > 0) printf("%s begin\n", prefix);
992
993    double * result = NULL;
994// cannot find this in Cbc, Osi, or OsiClp
995// may have to make it somehow
996//  result = model->model_->getColSolution();
997    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
998
999    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1000    return result;
1001}
1002/* Dual row solution */
1003COINLIBAPI double * COINLINKAGE
1004Cbc_dualRowSolution(Cbc_Model * /*model*/)
1005{
1006    const char prefix[] = "Cbc_C_Interface::Cbc_dualRowSolution(): ";
1007//  const int  VERBOSE = 1;
1008    if (VERBOSE > 0) printf("%s begin\n", prefix);
1009
1010    double * result = NULL;
1011// cannot find this in Cbc, Osi, or OsiClp
1012// may have to make it somehow
1013//tbd  return model->model_->dualRowSolution();
1014    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1015
1016    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1017    return NULL;
1018}
1019/* Reduced costs */
1020COINLIBAPI double * COINLINKAGE
1021Cbc_dualColumnSolution(Cbc_Model * /*model*/)
1022{
1023    const char prefix[] = "Cbc_C_Interface::Cbc_dualColumnSolution(): ";
1024//  const int  VERBOSE = 1;
1025    if (VERBOSE > 0) printf("%s begin\n", prefix);
1026
1027    double * result = NULL;
1028// cannot find this in Cbc, Osi, or OsiClp
1029// may have to make it somehow
1030//tbd  return model->model_->dualColumnSolution();
1031    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1032
1033    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1034    return NULL;
1035}
1036/* Row lower */
1037COINLIBAPI double * COINLINKAGE
1038Cbc_rowLower(Cbc_Model * /*model*/)
1039{
1040    const char prefix[] = "Cbc_C_Interface::Cbc_rowLower(): ";
1041//  const int  VERBOSE = 1;
1042    if (VERBOSE > 0) printf("%s begin\n", prefix);
1043
1044    double * result = NULL;
1045// cannot find this in Cbc, Osi, or OsiClp
1046// may have to make it somehow
1047//tbd  return model->model_->rowLower();
1048    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1049
1050    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1051    return NULL;
1052}
1053/* Row upper  */
1054COINLIBAPI double * COINLINKAGE
1055Cbc_rowUpper(Cbc_Model * /*model*/)
1056{
1057    const char prefix[] = "Cbc_C_Interface::Cbc_rowUpper(): ";
1058//  const int  VERBOSE = 1;
1059    if (VERBOSE > 0) printf("%s begin\n", prefix);
1060
1061    double * result = NULL;
1062// cannot find this in Cbc, Osi, or OsiClp
1063// may have to make it somehow
1064//tbd  return model->model_->rowUpper();
1065    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1066
1067    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1068    return NULL;
1069}
1070/* Objective Coefficients */
1071COINLIBAPI double * COINLINKAGE
1072Cbc_objective(Cbc_Model * /*model*/)
1073{
1074    const char prefix[] = "Cbc_C_Interface::Cbc_objective(): ";
1075//  const int  VERBOSE = 1;
1076    if (VERBOSE > 0) printf("%s begin\n", prefix);
1077
1078    double * result = NULL;
1079// cannot find this in Cbc, Osi, or OsiClp
1080// may have to make it somehow
1081//  result = model->model_->objective();
1082    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1083
1084    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1085    return NULL;
1086}
1087/* Column Lower */
1088COINLIBAPI double * COINLINKAGE
1089Cbc_columnLower(Cbc_Model * /*model*/)
1090{
1091    const char prefix[] = "Cbc_C_Interface::Cbc_columnLower(): ";
1092//  const int  VERBOSE = 1;
1093    if (VERBOSE > 0) printf("%s begin\n", prefix);
1094
1095    double * result = NULL;
1096// cannot find this in Cbc, Osi, or OsiClp
1097// may have to make it somehow
1098//tbd  return model->model_->columnLower();
1099    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1100
1101    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1102    return NULL;
1103}
1104/* Column Upper */
1105COINLIBAPI double * COINLINKAGE
1106Cbc_columnUpper(Cbc_Model * /*model*/)
1107{
1108    const char prefix[] = "Cbc_C_Interface::Cbc_columnUpper(): ";
1109//  const int  VERBOSE = 1;
1110    if (VERBOSE > 0) printf("%s begin\n", prefix);
1111
1112    double * result = NULL;
1113// cannot find this in Cbc, Osi, or OsiClp
1114// may have to make it somehow
1115//tbd  return model->model_->columnUpper();
1116    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1117
1118    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1119    return NULL;
1120}
1121/* Number of elements in matrix */
1122COINLIBAPI int COINLINKAGE
1123Cbc_getNumElements(Cbc_Model * model)
1124{
1125    const char prefix[] = "Cbc_C_Interface::Cbc_getNumElements(): ";
1126//  const int  VERBOSE = 1;
1127    if (VERBOSE > 0) printf("%s begin\n", prefix);
1128
1129    int result = 0;
1130    result = model->model_->getNumElements();
1131
1132    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1133    return result;
1134}
1135
1136// Column starts in matrix
1137COINLIBAPI const CoinBigIndex * COINLINKAGE
1138Cbc_getVectorStarts(Cbc_Model * model)
1139{
1140    const CoinPackedMatrix * matrix = NULL;
1141    matrix = model->model_->solver()->getMatrixByCol();
1142    return (matrix == NULL) ? NULL : matrix->getVectorStarts();
1143}
1144// Row indices in matrix
1145COINLIBAPI const int * COINLINKAGE
1146Cbc_getIndices(Cbc_Model * model)
1147{
1148    const char prefix[] = "Cbc_C_Interface::Cbc_getIndices(): ";
1149//  const int  VERBOSE = 1;
1150    if (VERBOSE > 0) printf("%s begin\n", prefix);
1151
1152    const int * result = NULL;
1153    const CoinPackedMatrix * matrix = NULL;
1154    matrix = model->model_->solver()->getMatrixByCol();
1155    result = (matrix == NULL) ? NULL : matrix->getIndices();
1156
1157    if (VERBOSE > 0)
1158        printf("%s return %p\n", prefix, static_cast<const void*>(result));
1159    return result;
1160}
1161
1162// Column vector lengths in matrix
1163COINLIBAPI const int * COINLINKAGE
1164Cbc_getVectorLengths(Cbc_Model * model)
1165{
1166    const char prefix[] = "Cbc_C_Interface::Cbc_getVectorLengths(): ";
1167//  const int  VERBOSE = 1;
1168    if (VERBOSE > 0) printf("%s begin\n", prefix);
1169
1170    const int * result = NULL;
1171    const CoinPackedMatrix * matrix = NULL;
1172    matrix = model->model_->solver()->getMatrixByCol();
1173    result = (matrix == NULL) ? NULL : matrix->getVectorLengths();
1174
1175    if (VERBOSE > 0)
1176        printf("%s return %p\n", prefix, static_cast<const void*>(result));
1177    return result;
1178}
1179
1180// Element values in matrix
1181COINLIBAPI const double * COINLINKAGE
1182Cbc_getElements(Cbc_Model * model)
1183{
1184    const char prefix[] = "Cbc_C_Interface::Cbc_getElements(): ";
1185//  const int  VERBOSE = 1;
1186    if (VERBOSE > 0) printf("%s begin\n", prefix);
1187
1188    const double * result = NULL;
1189    const CoinPackedMatrix * matrix = NULL;
1190    matrix = model->model_->solver()->getMatrixByCol();
1191    result = (matrix == NULL) ? NULL : matrix->getElements();
1192
1193    if (VERBOSE > 0)
1194        printf("%s return %p\n", prefix, static_cast<const void*>(result));
1195    return result;
1196}
1197// ======================================================================
1198
1199/* Objective value */
1200COINLIBAPI double COINLINKAGE
1201Cbc_objectiveValue(Cbc_Model * model)
1202{
1203    const char prefix[] = "Cbc_C_Interface::Cbc_objectiveValue(): ";
1204//  const int  VERBOSE = 1;
1205    if (VERBOSE > 0) printf("%s begin\n", prefix);
1206
1207    double result = 0.0;
1208    result = model->model_->getObjValue();
1209
1210    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1211    return result;
1212}
1213/* Infeasibility/unbounded ray (NULL returned if none/wrong)
1214   Up to user to use delete [] on these arrays.  */
1215COINLIBAPI double * COINLINKAGE
1216Cbc_infeasibilityRay(Cbc_Model * /*model*/)
1217{
1218    const char prefix[] = "Cbc_C_Interface::Cbc_infeasibilityRay(): ";
1219//  const int  VERBOSE = 1;
1220    if (VERBOSE > 0) printf("%s begin\n", prefix);
1221
1222    double * result = NULL;
1223    // lots of rays (probably too many) are available in
1224    // OsiClpSolverInterface::getDualRays()
1225    //
1226//tbd  result = model->model_->infeasibilityRay();
1227    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1228
1229    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1230    return result;
1231}
1232COINLIBAPI double * COINLINKAGE
1233Cbc_unboundedRay(Cbc_Model * /*model*/)
1234{
1235    const char prefix[] = "Cbc_C_Interface::Cbc_unboundedRay(): ";
1236//  const int  VERBOSE = 1;
1237    if (VERBOSE > 0) printf("%s begin\n", prefix);
1238
1239    double * result = NULL;
1240    // lots of rays (probably too many) are available in
1241    // OsiClpSolverInterface::getPrimalRays()
1242    //
1243//tbd  result = model->model_->unboundedRay();
1244    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1245
1246    if (VERBOSE > 0) printf("%s return %p\n", prefix, static_cast<void*>(result));
1247    return result;
1248}
1249/* See if status array exists (partly for OsiClp) */
1250COINLIBAPI int COINLINKAGE
1251Cbc_statusExists(Cbc_Model * /*model*/)
1252{
1253    const char prefix[] = "Cbc_C_Interface::Cbc_statusExists(): ";
1254//  const int  VERBOSE = 1;
1255    if (VERBOSE > 0) printf("%s begin\n", prefix);
1256
1257    int result = 0;
1258//tbd  result = model->model_->statusExists() ? 1 : 0;
1259    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1260
1261    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1262    return result;
1263}
1264/* Return address of status array (char[numberRows+numberColumns]) */
1265COINLIBAPI void  COINLINKAGE
1266Cbc_getBasisStatus(Cbc_Model * /*model*/, int * /*cstat*/, int * /*rstat*/)
1267{
1268    const char prefix[] = "Cbc_C_Interface::Cbc_getBasisStatus(): ";
1269//  const int  VERBOSE = 1;
1270    if (VERBOSE > 0) printf("%s begin\n", prefix);
1271
1272// have to figure this out
1273//tbd  model->model_->solver()->getBasisStatus(cstat, rstat);
1274    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1275
1276    if (VERBOSE > 0) printf("%s return\n", prefix);
1277    return;
1278}
1279/* Copy in status vector */
1280COINLIBAPI void COINLINKAGE
1281Cbc_setBasisStatus(Cbc_Model * /*model*/,  int * /*cstat*/, int * /*rstat*/)
1282{
1283    const char prefix[] = "Cbc_C_Interface::Cbc_setBasisStatus(): ";
1284//  const int  VERBOSE = 1;
1285    if (VERBOSE > 0) printf("%s begin\n", prefix);
1286
1287//  model->model_->solver()->setBasisStatus(cstat, rstat);
1288    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1289
1290    if (VERBOSE > 0) printf("%s return\n", prefix);
1291}
1292
1293/* User pointer for whatever reason */
1294COINLIBAPI void COINLINKAGE
1295Cbc_setUserPointer (Cbc_Model * /*model*/, void * /*pointer*/)
1296{
1297    const char prefix[] = "Cbc_C_Interface::Cbc_setUserPointer(): ";
1298//  const int  VERBOSE = 1;
1299    if (VERBOSE > 0) printf("%s begin\n", prefix);
1300
1301    // not sure what this is for
1302    //
1303//tbd  model->model_->setUserPointer(pointer);
1304    if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);
1305
1306    if (VERBOSE > 0) printf("%s return\n", prefix);
1307}
1308COINLIBAPI void * COINLINKAGE
1309Cbc_getUserPointer (Cbc_Model * /*model*/)
1310{
1311    const char prefix[] = "Cbc_C_Interface::Cbc_getUserPointer(): ";
1312//  const int  VERBOSE = 1;
1313    if (VERBOSE > 0) printf("%s begin\n", prefix);
1314
1315    void * result = NULL;
1316    // not sure what this is for
1317    //
1318//tbd result = model->model_->getUserPointer();
1319    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1320
1321    if (VERBOSE > 0) printf("%s return %p\n", prefix, result);
1322    return result;
1323}
1324/* Pass in Callback function */
1325COINLIBAPI void COINLINKAGE
1326Cbc_registerCallBack(Cbc_Model * model,
1327                     cbc_callback userCallBack)
1328{
1329    const char prefix[] = "Cbc_C_Interface::Cbc_registerCallBack(): ";
1330//  const int  VERBOSE = 1;
1331    if (VERBOSE > 0) printf("%s begin\n", prefix);
1332
1333    // reuse existing log level
1334    int oldLogLevel = model->model_->messageHandler()->logLevel();
1335    // Will be copy of users one
1336    delete model->handler_;
1337    model->handler_ = new Cbc_MessageHandler(*(model->model_->messageHandler()));
1338    model->handler_->setCallBack(userCallBack);
1339    model->handler_->setModel(model);
1340    model->model_->passInMessageHandler(model->handler_);
1341    model->model_->messageHandler()->setLogLevel(oldLogLevel);
1342
1343    if (VERBOSE > 0) printf("%s return\n", prefix);
1344}
1345/* Unset Callback function */
1346COINLIBAPI void COINLINKAGE
1347Cbc_clearCallBack(Cbc_Model * model)
1348{
1349    const char prefix[] = "Cbc_C_Interface::Cbc_clearCallBack(): ";
1350//  const int  VERBOSE = 1;
1351    if (VERBOSE > 0) printf("%s begin\n", prefix);
1352
1353    delete model->handler_;
1354    model->handler_ = NULL;
1355
1356    if (VERBOSE > 0) printf("%s return\n", prefix);
1357}
1358/* Amount of print out:
1359   0 - none
1360   1 - just final
1361   2 - just factorizations
1362   3 - as 2 plus a bit more
1363   4 - verbose
1364   above that 8,16,32 etc just for selective debug
1365*/
1366COINLIBAPI void COINLINKAGE
1367Cbc_setLogLevel(Cbc_Model * model, int value)
1368{
1369    const char prefix[] = "Cbc_C_Interface::Cbc_setLogLevel(): ";
1370//  const int  VERBOSE = 1;
1371    if (VERBOSE > 0) printf("%s begin\n", prefix);
1372    if (VERBOSE > 1) printf("%s value = %i\n", prefix, value);
1373
1374    model->model_->messageHandler()->setLogLevel(value);
1375
1376    if (VERBOSE > 0) printf("%s return\n", prefix);
1377}
1378COINLIBAPI int COINLINKAGE
1379Cbc_logLevel(Cbc_Model * model)
1380{
1381    const char prefix[] = "Cbc_C_Interface::Cbc_logLevel(): ";
1382//  const int  VERBOSE = 1;
1383    if (VERBOSE > 0) printf("%s begin\n", prefix);
1384
1385    int result = 0;
1386    result = model->model_->messageHandler()->logLevel();
1387
1388    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1389    return result;
1390}
1391/* length of names (0 means no names0 */
1392COINLIBAPI int COINLINKAGE
1393Cbc_lengthNames(Cbc_Model * /*model*/)
1394{
1395    const char prefix[] = "Cbc_C_Interface::Cbc_lengthNames(): ";
1396//  const int  VERBOSE = 1;
1397    if (VERBOSE > 0) printf("%s begin\n", prefix);
1398
1399    int result = 0;
1400// cannot find names in Cbc, Osi, or OsiClp
1401//tbd  result = model->model_->lengthNames();
1402    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1403
1404    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1405    return result;
1406}
1407/* Fill in array (at least lengthNames+1 long) with a row name */
1408COINLIBAPI void COINLINKAGE
1409Cbc_rowName(Cbc_Model * /*model*/, int iRow, char * name)
1410{
1411    const char prefix[] = "Cbc_C_Interface::Cbc_rowName(): ";
1412//  const int  VERBOSE = 1;
1413    if (VERBOSE > 0) printf("%s begin\n", prefix);
1414
1415    sprintf(name, "ROW%5i", iRow);
1416// cannot find names in Cbc, Osi, or OsiClp
1417//tbd  std::string rowName=model->model_->rowName(iRow);
1418//tbd  strcpy(name,rowName.c_str());
1419
1420    if (VERBOSE > 0) printf("%s return\n", prefix);
1421}
1422/* Fill in array (at least lengthNames+1 long) with a column name */
1423// cannot find names in Cbc, Osi, or OsiClp
1424COINLIBAPI void COINLINKAGE
1425Cbc_columnName(Cbc_Model * /*model*/, int iColumn, char * name)
1426{
1427    const char prefix[] = "Cbc_C_Interface::Cbc_columnName(): ";
1428//  const int  VERBOSE = 1;
1429    if (VERBOSE > 0) printf("%s begin\n", prefix);
1430
1431    sprintf(name, "COL%5i", iColumn);
1432//tbd  std::string columnName= model->model_->columnName(iColumn);
1433//tbd  strcpy(name,columnName.c_str());
1434
1435    if (VERBOSE > 0) printf("%s return\n", prefix);
1436}
1437
1438/* General branch and bound solve algorithm which can do presolve.
1439   See  CbcSolve.hpp for options
1440*/
1441COINLIBAPI int COINLINKAGE
1442Cbc_initialSolve(Cbc_Model * model)
1443{
1444    const char prefix[] = "Cbc_C_Interface::Cbc_initialSolve(): ";
1445//  const int  VERBOSE = 1;
1446    if (VERBOSE > 0) printf("%s begin\n", prefix);
1447
1448    int result = 0;
1449    model->model_->initialSolve();
1450    result = model->model_->status();
1451
1452    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1453    return result;
1454}
1455/* General solve algorithm which can do presolve.
1456   See  CbcModel.hpp for options
1457*/
1458COINLIBAPI int COINLINKAGE
1459Cbc_branchAndBound(Cbc_Model * model)
1460{
1461    const char prefix[] = "Cbc_C_Interface::Cbc_branchAndBound(): ";
1462//  const int  VERBOSE = 3;
1463    if (VERBOSE > 0) printf("%s begin\n", prefix);
1464
1465    int result = 0;
1466    if (VERBOSE > 2) Cbc_printModel(model, prefix);
1467    try {
1468        model->model_->branchAndBound();
1469        model->model_->solver()->resolve();
1470    } catch (CoinError e) {
1471        printf("%s ERROR: %s::%s, %s\n", prefix,
1472               e.className().c_str(), e.methodName().c_str(), e.message().c_str());
1473    }
1474    result = model->model_->status();
1475
1476    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
1494    return result;
1495}
1496/* Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
1497COINLIBAPI void COINLINKAGE
1498Cbc_scaling(Cbc_Model * model, int mode)
1499{
1500    const char prefix[] = "Cbc_C_Interface::Cbc_scaling(): ";
1501//  const int  VERBOSE = 1;
1502    if (VERBOSE > 0) printf("%s begin\n", prefix);
1503
1504    OsiSolverInterface * solver = model->model_->solver();
1505    bool modeBool = (mode == 0);
1506    solver->setHintParam(OsiDoScale, modeBool);
1507
1508    if (VERBOSE > 0) printf("%s return\n", prefix);
1509}
1510/* Gets scalingFlag */
1511COINLIBAPI int COINLINKAGE
1512Cbc_scalingFlag(Cbc_Model * /*model*/)
1513{
1514    const char prefix[] = "Cbc_C_Interface::Cbc_scalingFlag(): ";
1515//  const int  VERBOSE = 1;
1516    if (VERBOSE > 0) printf("%s begin\n", prefix);
1517
1518    int result = 0;
1519// try to use OsiSolverInterface::getHintParam(OsiDoScale, ???)
1520//tbd  result = model->model_->scalingFlag();
1521    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1522
1523    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1524    return result;
1525}
1526/* Crash - at present just aimed at dual, returns
1527   -2 if dual preferred and crash basis created
1528   -1 if dual preferred and all slack basis preferred
1529   0 if basis going in was not all slack
1530   1 if primal preferred and all slack basis preferred
1531   2 if primal preferred and crash basis created.
1532
1533   if gap between bounds <="gap" variables can be flipped
1534
1535   If "pivot" is
1536   0 No pivoting (so will just be choice of algorithm)
1537   1 Simple pivoting e.g. gub
1538   2 Mini iterations
1539*/
1540COINLIBAPI int COINLINKAGE
1541Cbc_crash(Cbc_Model * /*model*/, double /*gap*/, int /*pivot*/)
1542{
1543    const char prefix[] = "Cbc_C_Interface::Cbc_crash(): ";
1544//  const int  VERBOSE = 1;
1545    if (VERBOSE > 0) printf("%s begin\n", prefix);
1546
1547    int result = 0;
1548// cannot find names in Cbc, Osi, or OsiClp
1549//tbd  result = model->model_->crash(gap,pivot);
1550    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1551
1552    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1553    return result;
1554}
1555/* If problem is primal feasible */
1556COINLIBAPI int COINLINKAGE
1557Cbc_primalFeasible(Cbc_Model * model)
1558{
1559    const char prefix[] = "Cbc_C_Interface::Cbc_primalFeasible(): ";
1560//  const int  VERBOSE = 1;
1561    if (VERBOSE > 0) printf("%s begin\n", prefix);
1562
1563    int result = 0;
1564    OsiSolverInterface * solver = model->model_->solver();
1565    result = solver->isProvenPrimalInfeasible() ? 0 : 1;
1566
1567    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1568    return result;
1569}
1570/* If problem is dual feasible */
1571COINLIBAPI int COINLINKAGE
1572Cbc_dualFeasible(Cbc_Model * model)
1573{
1574    const char prefix[] = "Cbc_C_Interface::Cbc_dualFeasible(): ";
1575//  const int  VERBOSE = 1;
1576    if (VERBOSE > 0) printf("%s begin\n", prefix);
1577
1578    int result = 0;
1579    OsiSolverInterface * solver = model->model_->solver();
1580    result = solver->isProvenDualInfeasible() ? 0 : 1;
1581
1582    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1583    return result;
1584}
1585/* Dual bound */
1586COINLIBAPI double COINLINKAGE
1587Cbc_dualBound(Cbc_Model * /*model*/)
1588{
1589    const char prefix[] = "Cbc_C_Interface::Cbc_dualBound(): ";
1590//  const int  VERBOSE = 1;
1591    if (VERBOSE > 0) printf("%s begin\n", prefix);
1592
1593    double result = 0;
1594// cannot find in Cbc, Osi, or OsiClp
1595//tbd  result = model->model_->dualBound();
1596    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1597
1598    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1599    return result;
1600}
1601COINLIBAPI void COINLINKAGE
1602Cbc_setDualBound(Cbc_Model * /*model*/, double /*value*/)
1603{
1604    const char prefix[] = "Cbc_C_Interface::Cbc_setDualBound(): ";
1605//  const int  VERBOSE = 1;
1606    if (VERBOSE > 0) printf("%s begin\n", prefix);
1607
1608// cannot find names in Cbc, Osi, or OsiClp
1609//tbd  model->model_->setDualBound(value);
1610    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1611
1612    if (VERBOSE > 0) printf("%s return\n", prefix);
1613}
1614/* Infeasibility cost */
1615COINLIBAPI double COINLINKAGE
1616Cbc_infeasibilityCost(Cbc_Model * /*model*/)
1617{
1618    const char prefix[] = "Cbc_C_Interface::Cbc_infeasibilityCost(): ";
1619//  const int  VERBOSE = 1;
1620    if (VERBOSE > 0) printf("%s begin\n", prefix);
1621
1622    double result = 0;
1623// cannot find names in Cbc, Osi, or OsiClp
1624//tbd  result = model->model_->solver()->infeasibilityCost();
1625    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1626
1627    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1628    return result;
1629}
1630COINLIBAPI void COINLINKAGE
1631Cbc_setInfeasibilityCost(Cbc_Model * /*model*/, double /*value*/)
1632{
1633    const char prefix[] = "Cbc_C_Interface::Cbc_setInfeasibilityCost(): ";
1634//  const int  VERBOSE = 1;
1635    if (VERBOSE > 0) printf("%s begin\n", prefix);
1636
1637// cannot find names in Cbc, Osi, or OsiClp
1638//tbd  model->model_->setInfeasibilityCost(value);
1639    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1640
1641    if (VERBOSE > 0) printf("%s return\n", prefix);
1642}
1643/* Perturbation:
1644   50  - switch on perturbation
1645   100 - auto perturb if takes too long (1.0e-6 largest nonzero)
1646   101 - we are perturbed
1647   102 - don't try perturbing again
1648   default is 100
1649   others are for playing
1650*/
1651COINLIBAPI int COINLINKAGE
1652Cbc_perturbation(Cbc_Model * /*model*/)
1653{
1654    const char prefix[] = "Cbc_C_Interface::Cbc_perturbation(): ";
1655//  const int  VERBOSE = 1;
1656    if (VERBOSE > 0) printf("%s begin\n", prefix);
1657
1658    int result = 0;
1659// cannot find names in Cbc, Osi, or OsiClp
1660//tbd  result = model->model_->perturbation();
1661    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1662
1663    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1664    return result;
1665}
1666COINLIBAPI void COINLINKAGE
1667Cbc_setPerturbation(Cbc_Model * /*model*/, int /*value*/)
1668{
1669    const char prefix[] = "Cbc_C_Interface::Cbc_setPerturbation(): ";
1670//  const int  VERBOSE = 1;
1671    if (VERBOSE > 0) printf("%s begin\n", prefix);
1672
1673// cannot find names in Cbc, Osi, or OsiClp
1674//tbd  model->model_->setPerturbation(value);
1675    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1676
1677    if (VERBOSE > 0) printf("%s return\n", prefix);
1678}
1679/* Current (or last) algorithm */
1680COINLIBAPI int COINLINKAGE
1681Cbc_algorithm(Cbc_Model * /*model*/)
1682{
1683    const char prefix[] = "Cbc_C_Interface::Cbc_setPerturbation(): ";
1684//  const int  VERBOSE = 1;
1685    if (VERBOSE > 0) printf("%s begin\n", prefix);
1686
1687    int result = 0;
1688// cannot find names in Cbc, Osi, or OsiClp
1689//tbd  result = model->model_->algorithm();
1690    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1691
1692    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1693    return result;
1694}
1695/* Set algorithm */
1696COINLIBAPI void COINLINKAGE
1697Cbc_setAlgorithm(Cbc_Model * /*model*/, int /*value*/)
1698{
1699    const char prefix[] = "Cbc_C_Interface::Cbc_setAlgorithm(): ";
1700//  const int  VERBOSE = 1;
1701    if (VERBOSE > 0) printf("%s begin\n", prefix);
1702
1703// cannot find names in Cbc, Osi, or OsiClp
1704//tbd  model->model_->setAlgorithm(value);
1705    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1706
1707    if (VERBOSE > 0) printf("%s return\n", prefix);
1708}
1709/* Sum of dual infeasibilities */
1710COINLIBAPI double COINLINKAGE
1711Cbc_sumDualInfeasibilities(Cbc_Model * /*model*/)
1712{
1713    const char prefix[] = "Cbc_C_Interface::Cbc_sumDualInfeasibilities(): ";
1714//  const int  VERBOSE = 1;
1715    if (VERBOSE > 0) printf("%s begin\n", prefix);
1716
1717    double result = 0;
1718// cannot find names in Cbc, Osi, or OsiClp
1719//tbd  result = model->model_->sumDualInfeasibilities();
1720    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1721
1722    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1723    return result;
1724}
1725/* Number of dual infeasibilities */
1726COINLIBAPI int COINLINKAGE
1727Cbc_numberDualInfeasibilities(Cbc_Model * /*model*/)
1728{
1729    const char prefix[] = "Cbc_C_Interface::Cbc_numberDualInfeasibilities(): ";
1730//  const int  VERBOSE = 1;
1731    if (VERBOSE > 0) printf("%s begin\n", prefix);
1732
1733    int result = 0;
1734// cannot find names in Cbc, Osi, or OsiClp
1735//tbd  result = model->model_->numberDualInfeasibilities();
1736    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1737
1738    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1739    return result;
1740}
1741/* Sum of primal infeasibilities */
1742COINLIBAPI double COINLINKAGE
1743Cbc_sumPrimalInfeasibilities(Cbc_Model * /*model*/)
1744{
1745    const char prefix[] = "Cbc_C_Interface::Cbc_sumPrimalInfeasibilities(): ";
1746//  const int  VERBOSE = 1;
1747    if (VERBOSE > 0) printf("%s begin\n", prefix);
1748
1749    double result = 0;
1750// cannot find names in Cbc, Osi, or OsiClp
1751//tbd result = model->model_->sumPrimalInfeasibilities();
1752    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1753
1754    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1755    return result;
1756}
1757/* Number of primal infeasibilities */
1758COINLIBAPI int COINLINKAGE
1759Cbc_numberPrimalInfeasibilities(Cbc_Model * /*model*/)
1760{
1761    const char prefix[] = "Cbc_C_Interface::Cbc_numberPrimalInfeasibilities(): ";
1762//  const int  VERBOSE = 1;
1763    if (VERBOSE > 0) printf("%s begin\n", prefix);
1764
1765    int result = 0;
1766//tbd  result = model->model_->getContinuousInfeasibilities();
1767    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1768
1769    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1770    return result;
1771}
1772/* Save model to file, returns 0 if success.  This is designed for
1773   use outside algorithms so does not save iterating arrays etc.
1774   It does not save any messaging information.
1775   Does not save scaling values.
1776   It does not know about all types of virtual functions.
1777*/
1778COINLIBAPI int COINLINKAGE
1779Cbc_saveModel(Cbc_Model * /*model*/, const char * /*fileName*/)
1780{
1781    const char prefix[] = "Cbc_C_Interface::Cbc_saveModel(): ";
1782//  const int  VERBOSE = 1;
1783    if (VERBOSE > 0) printf("%s begin\n", prefix);
1784
1785    int result = 0;
1786// there is a writeMPS method in Osi
1787//tbd  result = model->model_->saveModel(fileName);
1788    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1789
1790    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1791    return result;
1792}
1793/* Restore model from file, returns 0 if success,
1794   deletes current model */
1795COINLIBAPI int COINLINKAGE
1796Cbc_restoreModel(Cbc_Model * /*model*/, const char * /*fileName*/)
1797{
1798    const char prefix[] = "Cbc_C_Interface::Cbc_restoreModel(): ";
1799//  const int  VERBOSE = 1;
1800    if (VERBOSE > 0) printf("%s begin\n", prefix);
1801
1802    int result = 0;
1803// there is a readMPS method in Osi
1804//tbd  result = model->model_->restoreModel(fileName);
1805    if (VERBOSE > 0) printf("%s WARNING:  NOT IMPLEMENTED\n", prefix);
1806
1807    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1808    return result;
1809}
1810
1811/** Call this to really test if a valid solution can be feasible
1812    Solution is number columns in size.
1813    If fixVariables true then bounds of continuous solver updated.
1814    Returns objective value (worse than cutoff if not feasible)
1815*/
1816COINLIBAPI void COINLINKAGE
1817Cbc_checkSolution(Cbc_Model * /*model*/)
1818{
1819    const char prefix[] = "Cbc_C_Interface::Cbc_checkSolution(): ";
1820//  const int  VERBOSE = 1;
1821    if (VERBOSE > 0) printf("%s begin\n", prefix);
1822
1823    // see CbcModel::checkSolution(double cutoff, const double * solution,
1824    //         bool fixVariables);
1825//  model->model_->checkSolution();
1826
1827    if (VERBOSE > 0) printf("%s return\n", prefix);
1828    return;
1829}
1830/* Number of rows */
1831COINLIBAPI int COINLINKAGE
1832Cbc_getNumRows(Cbc_Model * model)
1833{
1834    const char prefix[] = "Cbc_C_Interface::Cbc_getNumRows(): ";
1835//  const int  VERBOSE = 1;
1836    if (VERBOSE > 0) printf("%s begin\n", prefix);
1837
1838    int result = 0;
1839    result = model->model_->getNumRows();
1840
1841    if (VERBOSE > 0) printf("%s return %d\n", prefix, result);
1842    return result;
1843}
1844/* Number of columns */
1845COINLIBAPI int COINLINKAGE
1846Cbc_getNumCols(Cbc_Model * model)
1847{
1848    const char prefix[] = "Cbc_C_Interface::Cbc_getNumCols(): ";
1849//  const int  VERBOSE = 1;
1850    if (VERBOSE > 0) printf("%s begin\n", prefix);
1851
1852    int result = 0;
1853    result = model->model_->getNumCols();
1854
1855    if (VERBOSE > 0) printf("%s return %d\n", prefix, result);
1856    return result;
1857}
1858/* Number of iterations */
1859COINLIBAPI int COINLINKAGE
1860Cbc_getIterationCount(Cbc_Model * model)
1861{
1862    const char prefix[] = "Cbc_C_Interface::Cbc_getIterationCount(): ";
1863//  const int  VERBOSE = 1;
1864    if (VERBOSE > 0) printf("%s begin\n", prefix);
1865
1866    int result = 0;
1867    result = model->model_->getIterationCount();
1868
1869    if (VERBOSE > 0) printf("%s return %d\n", prefix, result);
1870    return result;
1871}
1872/* Are there a numerical difficulties? */
1873COINLIBAPI int COINLINKAGE
1874Cbc_isAbandoned(Cbc_Model * model)
1875{
1876    const char prefix[] = "Cbc_C_Interface::Cbc_isAbandoned(): ";
1877//  const int  VERBOSE = 1;
1878    if (VERBOSE > 0) printf("%s begin\n", prefix);
1879
1880    int result = 0;
1881    result = model->model_->isAbandoned() ? 1 : 0;
1882
1883    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1884    return result;
1885}
1886/* Is optimality proven? */
1887COINLIBAPI int COINLINKAGE
1888Cbc_isProvenOptimal(Cbc_Model * model)
1889{
1890    const char prefix[] = "Cbc_C_Interface::Cbc_isProvenOptimal(): ";
1891//  const int  VERBOSE = 1;
1892    if (VERBOSE > 0) printf("%s begin\n", prefix);
1893
1894    int result = 0;
1895    result = model->model_->isProvenOptimal() ? 1 : 0;
1896
1897    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1898    return result;
1899}
1900/* Is primal infeasiblity proven? */
1901COINLIBAPI int COINLINKAGE
1902Cbc_isProvenPrimalInfeasible(Cbc_Model * model)
1903{
1904    const char prefix[] = "Cbc_C_Interface::Cbc_isProvenPrimalInfeasible(): ";
1905//  const int  VERBOSE = 1;
1906    if (VERBOSE > 0) printf("%s begin\n", prefix);
1907
1908    int result = 0;
1909    OsiSolverInterface * solver = model->model_->solver();
1910    result = solver->isProvenPrimalInfeasible() ? 1 : 0;
1911
1912    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1913    return result;
1914}
1915/* Is dual infeasiblity proven? */
1916COINLIBAPI int COINLINKAGE
1917Cbc_isProvenDualInfeasible(Cbc_Model * model)
1918{
1919    const char prefix[] = "Cbc_C_Interface::Cbc_isProvenDualInfeasible(): ";
1920//  const int  VERBOSE = 1;
1921    if (VERBOSE > 0) printf("%s begin\n", prefix);
1922
1923    int result = 0;
1924    OsiSolverInterface * solver = model->model_->solver();
1925    result = solver->isProvenDualInfeasible() ? 1 : 0;
1926
1927    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1928    return result;
1929}
1930/* Is the given primal objective limit reached? */
1931COINLIBAPI int COINLINKAGE
1932Cbc_isPrimalObjectiveLimitReached(Cbc_Model * model)
1933{
1934    const char prefix[] = "Cbc_C_Interface::Cbc_isPrimalObjectiveLimitReached(): ";
1935//  const int  VERBOSE = 1;
1936    if (VERBOSE > 0) printf("%s begin\n", prefix);
1937
1938    int result = 0;
1939    OsiSolverInterface * solver = model->model_->solver();
1940    result = solver->isPrimalObjectiveLimitReached() ? 1 : 0;
1941
1942    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1943    return result;
1944}
1945/* Is the given dual objective limit reached? */
1946COINLIBAPI int COINLINKAGE
1947Cbc_isDualObjectiveLimitReached(Cbc_Model * model)
1948{
1949    const char prefix[] = "Cbc_C_Interface::Cbc_isDualObjectiveLimitReached(): ";
1950//  const int  VERBOSE = 1;
1951    if (VERBOSE > 0) printf("%s begin\n", prefix);
1952
1953    int result = 0;
1954    OsiSolverInterface * solver = model->model_->solver();
1955    result = solver->isDualObjectiveLimitReached() ? 1 : 0;
1956
1957    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1958    return result;
1959}
1960/* Iteration limit reached? */
1961COINLIBAPI int COINLINKAGE
1962Cbc_isIterationLimitReached(Cbc_Model * model)
1963{
1964    const char prefix[] = "Cbc_C_Interface::Cbc_isIterationLimitReached(): ";
1965//  const int  VERBOSE = 1;
1966    if (VERBOSE > 0) printf("%s begin\n", prefix);
1967
1968    int result = 0;
1969    OsiSolverInterface * solver = model->model_->solver();
1970    result = solver->isIterationLimitReached() ? 1 : 0;
1971
1972    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
1973    return result;
1974}
1975/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
1976COINLIBAPI double COINLINKAGE
1977Cbc_getObjSense(Cbc_Model * model)
1978{
1979    const char prefix[] = "Cbc_C_Interface::Cbc_getObjSense(): ";
1980//  const int  VERBOSE = 1;
1981    if (VERBOSE > 0) printf("%s begin\n", prefix);
1982
1983    double result = 0;
1984    result = model->model_->getObjSense();
1985
1986    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
1987    return result;
1988}
1989/* Primal row solution */
1990COINLIBAPI const double * COINLINKAGE
1991Cbc_getRowActivity(Cbc_Model * model)
1992{
1993    const char prefix[] = "Cbc_C_Interface::Cbc_getRowActivity(): ";
1994//  const int  VERBOSE = 1;
1995    if (VERBOSE > 0) printf("%s begin\n", prefix);
1996
1997    const double * result = NULL;
1998    result = model->model_->getRowActivity();
1999
2000    if (VERBOSE > 0)
2001        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2002    return result;
2003}
2004/* Primal column solution */
2005COINLIBAPI const double * COINLINKAGE
2006Cbc_getColSolution(Cbc_Model * model)
2007{
2008    const char prefix[] = "Cbc_C_Interface::Cbc_getColSolution(): ";
2009//  const int  VERBOSE = 1;
2010    if (VERBOSE > 0) printf("%s begin\n", prefix);
2011
2012    const double * result = NULL;
2013    result = model->model_->getColSolution();
2014
2015    if (VERBOSE > 0)
2016        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2017    return result;
2018}
2019COINLIBAPI void COINLINKAGE
2020Cbc_setColSolution(Cbc_Model * model, const double * input)
2021{
2022    const char prefix[] = "Cbc_C_Interface::Cbc_setColSolution(): ";
2023//  const int  VERBOSE = 1;
2024    if (VERBOSE > 0) printf("%s begin\n", prefix);
2025
2026    OsiSolverInterface * solver = model->model_->solver();
2027    solver->setColSolution(input);
2028
2029    if (VERBOSE > 0) printf("%s return\n", prefix);
2030    return;
2031}
2032/* Dual row solution */
2033COINLIBAPI const double * COINLINKAGE
2034Cbc_getRowPrice(Cbc_Model * model)
2035{
2036    const char prefix[] = "Cbc_C_Interface::Cbc_getRowPrice(): ";
2037//  const int  VERBOSE = 1;
2038    if (VERBOSE > 0) printf("%s begin\n", prefix);
2039
2040    const double * result = NULL;
2041    result = model->model_->getRowPrice();
2042
2043    if (VERBOSE > 0)
2044        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2045    return result;
2046}
2047/* Reduced costs */
2048COINLIBAPI const double * COINLINKAGE
2049Cbc_getReducedCost(Cbc_Model * model)
2050{
2051    const char prefix[] = "Cbc_C_Interface::Cbc_getReducedCost(): ";
2052//  const int  VERBOSE = 1;
2053    if (VERBOSE > 0) printf("%s begin\n", prefix);
2054
2055    const double * result = NULL;
2056    result = model->model_->getReducedCost();
2057
2058    if (VERBOSE > 0)
2059        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2060    return result;
2061}
2062/* Row lower */
2063COINLIBAPI const double * COINLINKAGE
2064Cbc_getRowLower(Cbc_Model * model)
2065{
2066    const char prefix[] = "Cbc_C_Interface::Cbc_getRowLower(): ";
2067//  const int  VERBOSE = 1;
2068    if (VERBOSE > 0) printf("%s begin\n", prefix);
2069
2070    const double * result = NULL;
2071    result = model->model_->getRowLower();
2072
2073    if (VERBOSE > 0)
2074        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2075    return result;
2076}
2077/* Row upper  */
2078COINLIBAPI const double * COINLINKAGE
2079Cbc_getRowUpper(Cbc_Model * model)
2080{
2081    const char prefix[] = "Cbc_C_Interface::Cbc_getRowUpper(): ";
2082//  const int  VERBOSE = 1;
2083    if (VERBOSE > 0) printf("%s begin\n", prefix);
2084
2085    const double * result = NULL;
2086    result = model->model_->getRowUpper();
2087
2088    if (VERBOSE > 0)
2089        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2090    return result;
2091}
2092/* Objective Coefficients */
2093COINLIBAPI const double * COINLINKAGE
2094Cbc_getObjCoefficients(Cbc_Model * model)
2095{
2096    const char prefix[] = "Cbc_C_Interface::Cbc_getObjCoefficients(): ";
2097//  const int  VERBOSE = 1;
2098    if (VERBOSE > 0) printf("%s begin\n", prefix);
2099
2100    const double * result = NULL;
2101    result = model->model_->getObjCoefficients();
2102
2103    if (VERBOSE > 0)
2104        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2105    return result;
2106}
2107/* Column Lower */
2108COINLIBAPI const double * COINLINKAGE
2109Cbc_getColLower(Cbc_Model * model)
2110{
2111    const char prefix[] = "Cbc_C_Interface::Cbc_getColLower(): ";
2112//  const int  VERBOSE = 1;
2113    if (VERBOSE > 0) printf("%s begin\n", prefix);
2114
2115    const double * result = NULL;
2116    result = model->model_->getColLower();
2117
2118    if (VERBOSE > 0)
2119        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2120    return result;
2121}
2122/* Column Upper */
2123COINLIBAPI const double * COINLINKAGE
2124Cbc_getColUpper(Cbc_Model * model)
2125{
2126    const char prefix[] = "Cbc_C_Interface::Cbc_getColUpper(): ";
2127//  const int  VERBOSE = 1;
2128    if (VERBOSE > 0) printf("%s begin\n", prefix);
2129
2130    const double * result = NULL;
2131    result = model->model_->getColUpper();
2132
2133    if (VERBOSE > 0)
2134        printf("%s return %p\n", prefix, static_cast<const void*>(result));
2135    return result;
2136}
2137/* Objective value */
2138COINLIBAPI double COINLINKAGE
2139Cbc_getObjValue(Cbc_Model * model)
2140{
2141    const char prefix[] = "Cbc_C_Interface::Cbc_getObjValue(): ";
2142//  const int  VERBOSE = 1;
2143    if (VERBOSE > 0) printf("%s begin\n", prefix);
2144
2145    double result = 0;
2146    result = model->model_->getObjValue();
2147
2148    if (VERBOSE > 0)
2149        printf("%s return %g\n", prefix, result);
2150    return result;
2151}
2152/* Print model */
2153COINLIBAPI void COINLINKAGE
2154Cbc_printModel(Cbc_Model * model, const char * argPrefix)
2155{
2156    const char prefix[] = "Cbc_C_Interface::Cbc_printModel(): ";
2157    const int  VERBOSE = 4;
2158    if (VERBOSE > 0) printf("%s begin\n", prefix);
2159
2160    CbcModel *cbc_model = model->model_;
2161    int numrows    = cbc_model->getNumRows();
2162    int numcols    = cbc_model->getNumCols();
2163    int numelem    = cbc_model->getNumElements();
2164    const CoinPackedMatrix * matrix = cbc_model->solver()->getMatrixByCol();
2165    const CoinBigIndex     * start  = matrix->getVectorStarts();
2166    const int              * index  = matrix->getIndices();
2167    const double           * value  = matrix->getElements();
2168    const double           * collb  = cbc_model->getColLower();
2169    const double           * colub  = cbc_model->getColUpper();
2170    const double           * obj    = cbc_model->getObjCoefficients();
2171    const double           * rowlb  = cbc_model->getRowLower();
2172    const double           * rowub  = cbc_model->getRowUpper();
2173
2174    printf("%s numcols = %i, numrows = %i, numelem = %i\n",
2175           argPrefix, numcols, numrows, numelem);
2176    printf("%s model = %p, start = %p, index = %p, value = %p\n",
2177           argPrefix, static_cast<void*>(model), static_cast<const void*>(start),
2178           static_cast<const void*>(index), static_cast<const void*>(value));
2179    matrix->dumpMatrix(NULL);
2180    {
2181        int i;
2182        for (i = 0; i <= numcols; i++)
2183            printf("%s start[%i] = %i\n", argPrefix, i, start[i]);
2184        for (i = 0; i < numelem; i++)
2185            printf("%s index[%i] = %i, value[%i] = %g\n",
2186                   argPrefix, i, index[i], i, value[i]);
2187    }
2188
2189    printf("%s collb = %p, colub = %p, obj = %p, rowlb = %p, rowub = %p\n",
2190           argPrefix, static_cast<const void*>(collb),
2191           static_cast<const void*>(colub), static_cast<const void*>(obj),
2192           static_cast<const void*>(rowlb), static_cast<const void*>(rowub));
2193    printf("%s optimization direction = %g\n", argPrefix, Cbc_optimizationDirection(model));
2194    printf("  (1 - minimize, -1 - maximize, 0 - ignore)\n");
2195    {
2196        int i;
2197        for (i = 0; i < numcols; i++)
2198            printf("%s collb[%i] = %g, colub[%i] = %g, obj[%i] = %g\n",
2199                   argPrefix, i, collb[i], i, colub[i], i, obj[i]);
2200        for (i = 0; i < numrows; i++)
2201            printf("%s rowlb[%i] = %g, rowub[%i] = %g\n",
2202                   argPrefix, i, rowlb[i], i, rowub[i]);
2203    }
2204
2205    if (VERBOSE > 0) printf("%s return\n", prefix);
2206}  // Cbc_printModel()
2207
2208COINLIBAPI int COINLINKAGE
2209Cbc_isInteger(Cbc_Model * model, int i)
2210{
2211    const char prefix[] = "Cbc_C_Interface::Cbc_isInteger(): ";
2212//  const int  VERBOSE = 1;
2213    if (VERBOSE > 0) printf("%s begin\n", prefix);
2214
2215    bool result = false;
2216    result = model->model_->isInteger(i);
2217
2218    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
2219    return (result) ? 1 : 0;
2220}
2221
2222COINLIBAPI double COINLINKAGE
2223Cbc_cpuTime(Cbc_Model * /*model*/)
2224{
2225    const char prefix[] = "Cbc_C_Interface::Cbc_cpuTime(): ";
2226//  const int  VERBOSE = 1;
2227    if (VERBOSE > 0) printf("%s begin\n", prefix);
2228
2229    double result = 0;
2230    result = CoinCpuTime() ;
2231
2232    if (VERBOSE > 0) printf("%s return %g\n", prefix, result);
2233    return result;
2234}
2235/** Number of nodes explored in B&B tree */
2236COINLIBAPI int COINLINKAGE
2237Cbc_getNodeCount(Cbc_Model * model)
2238{
2239    const char prefix[] = "Cbc_C_Interface::Cbc_getNodeCount(): ";
2240//  const int  VERBOSE = 1;
2241    if (VERBOSE > 0) printf("%s begin\n", prefix);
2242
2243    int result = 0;
2244    result = model->model_->getNodeCount() ;
2245
2246    if (VERBOSE > 0) printf("%s return %i\n", prefix, result);
2247    return result;
2248}
2249/** Return a copy of this model */
2250COINLIBAPI Cbc_Model * COINLINKAGE
2251Cbc_clone(Cbc_Model * model)
2252{
2253    const char prefix[] = "Cbc_C_Interface::Cbc_clone(): ";
2254//  const int  VERBOSE = 1;
2255    if (VERBOSE > 0) printf("%s begin\n", prefix);
2256
2257    Cbc_Model * result = new Cbc_Model;
2258    result->model_     = new CbcModel(*(model->model_));
2259    result->solver_    = dynamic_cast< OsiClpSolverInterface*> (result->model_->solver());
2260    result->handler_   = NULL;
2261
2262    if (VERBOSE > 0) printf("%s return\n", prefix);
2263    return model;
2264}
2265/** Set this the variable to be continuous */
2266COINLIBAPI Cbc_Model * COINLINKAGE
2267Cbc_setContinuous(Cbc_Model * model, int iColumn)
2268{
2269    const char prefix[] = "Cbc_C_Interface::Cbc_setContinuous(): ";
2270//  const int  VERBOSE = 1;
2271    if (VERBOSE > 0) printf("%s begin\n", prefix);
2272
2273    model->model_->solver()->setContinuous(iColumn);
2274
2275    if (VERBOSE > 0) printf("%s return\n", prefix);
2276    return model;
2277}
2278/* Add an SOS constraint to the model */
2279COINLIBAPI void  COINLINKAGE
2280Cbc_addSOS_Dense(Cbc_Model * model, int numObjects, const int * len,
2281                 const int * const* which, const double * weights, const int type)
2282{
2283    const char prefix[] = "Cbc_C_Interface::Cbc_addSOS_Dense(): ";
2284//  const int  VERBOSE = 2;
2285    if (VERBOSE > 0) printf("%sbegin\n", prefix);
2286
2287    assert(1 > 0);// this is probably broken
2288    int i, j;
2289    // I think this is a different model due to overriding = operator
2290    CbcModel m = *(model->model_);
2291
2292    CbcObject ** objects = new CbcObject * [numObjects];
2293
2294    if (VERBOSE > 1) printf("%s numObjects = %i\n", prefix, numObjects);
2295    for (i = 0; i < numObjects; i++) {
2296        if (VERBOSE > 1) {
2297            printf("%s len[%i] = %i, identifier = %i, type = %i\n",
2298                   prefix, i, len[i], i, type);
2299            fflush(stdout);
2300            for (j = 0; j < len[i]; j++) {
2301                if (VERBOSE > 2 || j == 0 || j == (len[i] - 1)) {
2302                    printf("%s which[%i][%i] = %d, weights[%i] = %g\n",
2303                           prefix, i, j, which[i][j], j, weights[j]);
2304                    fflush(stdout);
2305                }
2306            }
2307        }
2308
2309        // Make a CbcSOS and assign it to objects
2310        if (VERBOSE > 1) printf("%s len[%i] = %i\n", prefix, i, len[i]);
2311        if (VERBOSE > 1) printf("%s new CbcSOS()\n", prefix);
2312        // ***
2313        objects[i] = new CbcSOS(model->model_, (int)(len[i]),
2314                                (const int*)which[i], (const double*)weights, (int)i, (int)type);
2315        // ***
2316        if (objects[i] == NULL) {
2317            printf("%s ERROR: objects[%i] == NULL\n", prefix, i);
2318            fflush(stdout);
2319            assert(objects[i] != NULL);
2320        }
2321    }
2322    if (VERBOSE > 1) printf("%s calling addObjects()\n", prefix);
2323    fflush(stdout);
2324    model->model_->addObjects(numObjects, objects);
2325    if (VERBOSE > 1) printf("%s finished addObjects()\n", prefix);
2326
2327    for (i = 0; i < numObjects; i++) delete objects[i];
2328    delete [] objects;
2329
2330    if (VERBOSE > 0) printf("%sreturn\n", prefix);
2331    return;
2332}
2333/** Add SOS constraints to the model using row-order matrix */
2334COINLIBAPI void  COINLINKAGE
2335Cbc_addSOS_Sparse(Cbc_Model * model, const int * rowStarts,
2336                  const int * rowIndices, const double * weights, const int type)
2337{
2338    const char prefix[] = "Cbc_C_Interface::Cbc_addSOS_Sparse(): ";
2339//  const int  VERBOSE = 1;
2340    if (VERBOSE > 0) printf("%sbegin\n", prefix);
2341
2342    int numRows = Cbc_numberRows(model);
2343    if (VERBOSE > 0) printf("%s numRows = %i\n", prefix, numRows);
2344
2345    // The passed sparse matrix must have the same number of rows as the model
2346    assert(numRows == Cbc_numberRows(model));
2347
2348    int row, i;
2349    const int *colIndex;
2350    const double *colWeight;
2351
2352    // loop on rows and count number of objects according to numWeights>0
2353    int numObjects = 0;
2354    for (row = 0; row < numRows; row++) {
2355        if (VERBOSE > 2) {
2356            printf("%s row = %i\n", prefix, row);
2357            printf("%s rowStarts[%i] = %i\n", prefix, row, rowStarts[row]);
2358            printf("%s rowStarts[%i+1] = %i\n", prefix, row, rowStarts[row+1]);
2359            fflush(stdout);
2360        }
2361        const int numWeights = rowStarts[row+1] - rowStarts[row];
2362        if (VERBOSE > 2) printf("%s  numWeights = %i\n", prefix, numWeights);
2363        if (numWeights > 0) numObjects++;
2364    }
2365
2366    // make objects
2367    CbcObject ** objects = new CbcObject * [numObjects];
2368//  if (VERBOSE>1) printf("%s numObjects = %i, objects = %X\n",prefix,numObjects,objects);
2369
2370    // loop on rows and make an object when numWeights>0
2371    int objNum = 0;
2372    for (row = 0; row < numRows; row++) {
2373        if (VERBOSE > 2) {
2374            printf("%s row = %i\n", prefix, row);
2375            printf("%s rowStarts[%i] = %i\n", prefix, row, rowStarts[row]);
2376            printf("%s rowStarts[%i+1] = %i\n", prefix, row, rowStarts[row+1]);
2377        }
2378        const int numWeights = rowStarts[row+1] - rowStarts[row];
2379        if (VERBOSE > 2) printf("%s  numWeights = %i\n", prefix, numWeights);
2380        colIndex    = rowIndices + rowStarts[row];
2381        colWeight   = weights + rowStarts[row];
2382        if (numWeights > 0) {
2383            // Make a CbcSOS and assign it to objects
2384            if (VERBOSE > 3) {
2385                for (i = 0; i < numWeights; i++) {
2386                    printf("%s  colIndex [%i] = %i\n", prefix, i, colIndex[i]);
2387                    printf("%s  colWeight[%i] = %f\n", prefix, i, colWeight[i]);
2388                }
2389                fflush(stdout);
2390            }
2391            objects[objNum] = new CbcSOS(model->model_, (int)(numWeights),
2392                                         (const int*)colIndex, (const double*)colWeight, (int)objNum, (int)type);
2393//      if (VERBOSE>2) printf("%s objects[%i] = %X\n",prefix,objNum,objects[objNum]);
2394            if (objects[objNum] == NULL) {
2395                printf("%s ERROR: objects[%i] == NULL\n", prefix, objNum);
2396                fflush(stdout);
2397                assert(objects[objNum] != NULL);
2398            }
2399            objNum++;
2400        }
2401    }
2402    if (VERBOSE > 2) {
2403        printf("%s calling addObjects()\n", prefix);
2404        /*
2405            printf("%s numObjects = %i, objects = %X\n",prefix,numObjects,objects);
2406            for (row=0; row<numObjects; row++)
2407              printf("%s  objects[%i] = %X\n",prefix,row,objects[row]);
2408        */
2409    }
2410    fflush(stdout);
2411    model->model_->addObjects(numObjects, objects);
2412    if (VERBOSE > 1) printf("%s finished addObjects()\n", prefix);
2413
2414    for (objNum = 0; objNum < numObjects; objNum++) delete objects[objNum];
2415    delete [] objects;
2416
2417    if (VERBOSE > 0) printf("%sreturn\n", prefix);
2418    return;
2419}
2420
2421/** Delete all object information */
2422COINLIBAPI void  COINLINKAGE
2423Cbc_deleteObjects(Cbc_Model * model)
2424{
2425    const char prefix[] = "Cbc_C_Interface::Cbc_deleteObjects(): ";
2426//  const int  VERBOSE = 2;
2427    if (VERBOSE > 0) printf("%s begin\n", prefix);
2428
2429    model->model_->deleteObjects();
2430
2431    if (VERBOSE > 0) printf("%s return\n", prefix);
2432    return;
2433}
2434
2435/** Print the solution */
2436COINLIBAPI void  COINLINKAGE
2437Cbc_printSolution(Cbc_Model * model)
2438{
2439    {
2440        //
2441        //  Now to print out row solution.  The methods used return const
2442        //  pointers - which is of course much more virtuous.
2443        //
2444        //  This version just does non-zero columns
2445        //
2446
2447        // * Rows
2448
2449        int numberRows = Cbc_getNumRows(model);
2450        int iRow;
2451
2452
2453        const double * rowPrimal = Cbc_getRowActivity(model);
2454        // * Alternatively getReducedCost(model)
2455        const double * rowDual = Cbc_getRowPrice(model);
2456        // * Alternatively getColLower(model)
2457        const double * rowLower = Cbc_getRowLower(model);
2458        // * Alternatively getColUpper(model)
2459        const double * rowUpper = Cbc_getRowUpper(model);
2460        printf("--------------------------------------\n");
2461
2462        // * If we have not kept names (parameter to readMps) this will be 0
2463        //    assert(Cbc_lengthNames(model));
2464
2465        printf("                       Primal          Dual         Lower         Upper\n");
2466        for (iRow = 0; iRow < numberRows; iRow++) {
2467            double value;
2468            value = rowPrimal[iRow];
2469            if (value > 1.0e-8 || value < -1.0e-8) {
2470                char name[20];
2471                //              Cbc_columnName(model,iColumn,name);
2472                sprintf(name, "ROW%5i", iRow);
2473                printf("%6d %8s", iRow, name);
2474                printf(" %13g", rowPrimal[iRow]);
2475                printf(" %13g", rowDual[iRow]);
2476                printf(" %13g", rowLower[iRow]);
2477                printf(" %13g", rowUpper[iRow]);
2478                printf("\n");
2479            }
2480        }
2481        printf("--------------------------------------\n");
2482    }
2483    {
2484        //
2485        //  Now to print out column solution.  The methods used return const
2486        //  pointers - which is of course much more virtuous.
2487        //
2488        //  This version just does non-zero columns
2489        //
2490        //
2491
2492        // * Columns
2493
2494        int numberColumns = Cbc_numberColumns(model);
2495        int iColumn;
2496
2497
2498        // * Alternatively getColSolution(model)
2499        const double * columnPrimal = Cbc_getColSolution(model);
2500        // * Alternatively getReducedCost(model)
2501        const double * columnDual = Cbc_getReducedCost(model);
2502        // * Alternatively getColLower(model)
2503        const double * columnLower = Cbc_getColLower(model);
2504        // * Alternatively getColUpper(model)
2505        const double * columnUpper = Cbc_getColUpper(model);
2506        // * Alternatively getObjCoefficients(model)
2507        const double * columnObjective = Cbc_getObjCoefficients(model);
2508
2509        const char * isInteger = Cbc_integerInformation(model);
2510
2511        printf("--------------------------------------\n");
2512
2513        // * If we have not kept names (parameter to readMps) this will be 0
2514//    assert(Cbc_lengthNames(model));
2515
2516        printf("                       Primal          Dual         Lower         Upper          Cost     isInteger\n");
2517        for (iColumn = 0; iColumn < numberColumns; iColumn++) {
2518            double value;
2519            value = columnPrimal[iColumn];
2520            if (value > 1.0e-8 || value < -1.0e-8) {
2521                char name[20];
2522//              Cbc_columnName(model,iColumn,name);
2523                sprintf(name, "COL%5i", iColumn);
2524                printf("%6d %8s", iColumn, name);
2525                printf(" %13g", columnPrimal[iColumn]);
2526                printf(" %13g", columnDual[iColumn]);
2527                printf(" %13g", columnLower[iColumn]);
2528                printf(" %13g", columnUpper[iColumn]);
2529                printf(" %13g", columnObjective[iColumn]);
2530                printf(" %13i", isInteger[iColumn]);
2531                printf("\n");
2532            }
2533        }
2534        printf("--------------------------------------\n");
2535    }
2536    if (0) Cbc_printModel(model, "cbc::main(): ");
2537    return;
2538}
2539/** Dual initial solve */
2540COINLIBAPI int COINLINKAGE
2541Cbc_initialDualSolve(Cbc_Model * /*model*/)
2542{
2543    return 0;
2544}
2545/** Primal initial solve */
2546COINLIBAPI int COINLINKAGE
2547Cbc_initialPrimalSolve(Cbc_Model * /*model*/)
2548{
2549    return 0;
2550}
2551/** Dual algorithm - see ClpSimplexDual.hpp for method */
2552COINLIBAPI int COINLINKAGE
2553Cbc_dual(Cbc_Model * /*model*/, int /*ifValuesPass*/)
2554{
2555    return 0;
2556}
2557/** Primal algorithm - see ClpSimplexPrimal.hpp for method */
2558COINLIBAPI int COINLINKAGE
2559Cbc_primal(Cbc_Model * /*model*/, int /*ifValuesPass*/)
2560{
2561    return 0;
2562}
2563#if defined(__MWERKS__)
2564#pragma export off
2565#endif
2566
Note: See TracBrowser for help on using the repository browser.