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

Last change on this file since 862 was 767, checked in by jpfasano, 12 years ago

Fix to assert failure occurring when running cbcCSosDllSample. Fix from Bob Entriken.

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