source: trunk/Clp/src/Clp_C_Interface.cpp @ 1304

Last change on this file since 1304 was 1231, checked in by ladanyi, 12 years ago

switch from strdup to CoinStrdup? (same as changeset 1230 in stable/1.8)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.7 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4
5
6
7#include "CoinPragma.hpp"
8
9#include <cmath>
10#include <cstring>
11
12#include "CoinHelperFunctions.hpp"
13#include "ClpSimplex.hpp"
14#include "ClpInterior.hpp"
15#include <cfloat>
16// Get C stuff but with extern C
17#define CLP_EXTERN_C
18#include "Coin_C_defines.h"
19
20/// To allow call backs
21class CMessageHandler : public CoinMessageHandler {
22 
23public:
24  /**@name Overrides */
25  //@{
26  virtual int print();
27  //@}
28  /**@name set and get */
29  //@{
30  /// Model
31  const Clp_Simplex * model() const;
32  void setModel(Clp_Simplex * model);
33  /// Call back
34  void setCallBack(clp_callback callback);
35  //@}
36
37  /**@name Constructors, destructor */
38  //@{
39  /** Default constructor. */
40  CMessageHandler();
41  /// Constructor with pointer to model
42  CMessageHandler(Clp_Simplex * model,
43                           FILE * userPointer=NULL);
44  /** Destructor */
45  virtual ~CMessageHandler();
46  //@}
47
48  /**@name Copy method */
49  //@{
50  /** The copy constructor. */
51  CMessageHandler(const CMessageHandler&);
52  /** The copy constructor from an CoinSimplexMessageHandler. */
53  CMessageHandler(const CoinMessageHandler&);
54 
55  CMessageHandler& operator=(const CMessageHandler&);
56  /// Clone
57  virtual CoinMessageHandler * clone() const ;
58  //@}
59   
60   
61protected:
62  /**@name Data members
63     The data members are protected to allow access for derived classes. */
64  //@{
65  /// Pointer back to model
66  Clp_Simplex * model_;
67  /// call back
68  clp_callback callback_;
69  //@}
70};
71
72
73//-------------------------------------------------------------------
74// Default Constructor
75//-------------------------------------------------------------------
76CMessageHandler::CMessageHandler () 
77  : CoinMessageHandler(),
78    model_(NULL),
79    callback_(NULL)
80{
81}
82
83//-------------------------------------------------------------------
84// Copy constructor
85//-------------------------------------------------------------------
86CMessageHandler::CMessageHandler (const CMessageHandler & rhs) 
87: CoinMessageHandler(rhs),
88    model_(rhs.model_),
89    callback_(rhs.callback_)
90{ 
91}
92
93CMessageHandler::CMessageHandler (const CoinMessageHandler & rhs) 
94  : CoinMessageHandler(),
95    model_(NULL),
96    callback_(NULL)
97{ 
98}
99
100// Constructor with pointer to model
101CMessageHandler::CMessageHandler(Clp_Simplex * model,
102               FILE * userPointer)
103  : CoinMessageHandler(),
104    model_(model),
105    callback_(NULL)
106{
107}
108
109//-------------------------------------------------------------------
110// Destructor
111//-------------------------------------------------------------------
112CMessageHandler::~CMessageHandler ()
113{
114}
115
116//----------------------------------------------------------------
117// Assignment operator
118//-------------------------------------------------------------------
119CMessageHandler &
120CMessageHandler::operator=(const CMessageHandler& rhs)
121{
122  if (this != &rhs) {
123    CoinMessageHandler::operator=(rhs);
124    model_ = rhs.model_;
125    callback_ = rhs.callback_;
126  }
127  return *this;
128}
129//-------------------------------------------------------------------
130// Clone
131//-------------------------------------------------------------------
132CoinMessageHandler * CMessageHandler::clone() const
133{
134  return new CMessageHandler(*this);
135}
136
137int 
138CMessageHandler::print()
139{
140  if (callback_) {
141    int messageNumber = currentMessage().externalNumber();
142    if (currentSource()!="Clp")
143      messageNumber += 1000000;
144    int i;
145    int nDouble=numberDoubleFields();
146    assert (nDouble<=10);
147    double vDouble[10];
148    for (i=0;i<nDouble;i++)
149      vDouble[i]=doubleValue(i);
150    int nInt=numberIntFields();
151    assert (nInt<=10);
152    int vInt[10];
153    for (i=0;i<nInt;i++)
154      vInt[i]=intValue(i);
155    int nString=numberStringFields();
156    assert (nString<=10);
157    char * vString[10];
158    for (i=0;i<nString;i++) {
159      std::string value = stringValue(i);
160      vString[i]=CoinStrdup(value.c_str());
161    }
162    callback_(model_,messageNumber,
163              nDouble,vDouble,
164              nInt,vInt,
165              nString,vString);
166    for (i=0;i<nString;i++) 
167      free(vString[i]);
168   
169  }
170  return CoinMessageHandler::print();
171}
172const Clp_Simplex *
173CMessageHandler::model() const
174{
175  return model_;
176}
177void 
178CMessageHandler::setModel(Clp_Simplex * model)
179{
180  model_ = model;
181}
182// Call back
183void 
184CMessageHandler::setCallBack(clp_callback callback)
185{
186  callback_ = callback;
187}
188
189#include "Clp_C_Interface.h"
190#include <string>
191#include <stdio.h>
192#include <iostream>
193
194#if defined(__MWERKS__)
195#pragma export on
196#endif
197/* Default constructor */
198COINLIBAPI Clp_Simplex *  COINLINKAGE
199Clp_newModel()
200{
201  Clp_Simplex * model = new Clp_Simplex;
202  model->model_ = new ClpSimplex();
203  model->handler_=NULL;
204  return model;
205}
206/* Destructor */
207COINLIBAPI void COINLINKAGE
208Clp_deleteModel(Clp_Simplex * model)
209{
210  delete model->model_;
211  delete model->handler_;
212  delete model;
213}
214
215/* Loads a problem (the constraints on the
216    rows are given by lower and upper bounds). If a pointer is NULL then the
217    following values are the default:
218    <ul>
219    <li> <code>colub</code>: all columns have upper bound infinity
220    <li> <code>collb</code>: all columns have lower bound 0
221    <li> <code>rowub</code>: all rows have upper bound infinity
222    <li> <code>rowlb</code>: all rows have lower bound -infinity
223    <li> <code>obj</code>: all variables have 0 objective coefficient
224    </ul>
225*/
226/* Just like the other loadProblem() method except that the matrix is
227   given in a standard column major ordered format (without gaps). */
228COINLIBAPI void COINLINKAGE
229Clp_loadProblem (Clp_Simplex * model,  const int numcols, const int numrows,
230                 const CoinBigIndex * start, const int* index,
231                 const double* value,
232                 const double* collb, const double* colub,   
233                 const double* obj,
234                 const double* rowlb, const double* rowub)
235{
236  const char prefix[] = "Clp_c_Interface::Clp_loadProblem(): ";
237  const int  verbose = 0;
238  if (verbose > 1) {
239    printf("%s numcols = %i, numrows = %i\n", 
240      prefix, numcols, numrows);
241    printf("%s model = %p, start = %p, index = %p, value = %p\n",
242      prefix, (void*)model, (void*)start, (void*)index, (void*)value);
243    printf("%s collb = %p, colub = %p, obj = %p, rowlb = %p, rowub = %p\n",
244      prefix, (void*)collb, (void*)colub, (void*)obj, (void*)rowlb, (void*)rowub);
245  }
246  model->model_->loadProblem(numcols,numrows,start,index,value,
247                             collb,colub,obj,rowlb,rowub);
248}
249/* read quadratic part of the objective (the matrix part) */
250COINLIBAPI void COINLINKAGE
251Clp_loadQuadraticObjective(Clp_Simplex * model, 
252                           const int numberColumns, 
253                           const CoinBigIndex * start,
254                           const int * column, 
255                           const double * element)
256{
257
258   model->model_->loadQuadraticObjective(numberColumns, 
259                                         start, column, element);
260
261}
262/* Read an mps file from the given filename */
263COINLIBAPI int COINLINKAGE
264Clp_readMps(Clp_Simplex * model,const char *filename,
265            int keepNames,
266            int ignoreErrors)
267{
268  return model->model_->readMps(filename,keepNames!=0,ignoreErrors!=0);
269}
270/* Copy in integer informations */
271COINLIBAPI void COINLINKAGE
272Clp_copyInIntegerInformation(Clp_Simplex * model,const char * information)
273{
274  model->model_->copyInIntegerInformation(information);
275}
276/* Drop integer informations */
277COINLIBAPI void COINLINKAGE
278Clp_deleteIntegerInformation(Clp_Simplex * model)
279{
280  model->model_->deleteIntegerInformation();
281}
282/* Resizes rim part of model  */
283COINLIBAPI void COINLINKAGE
284Clp_resize (Clp_Simplex * model, int newNumberRows, int newNumberColumns)
285{
286  model->model_->resize(newNumberRows,newNumberColumns);
287}
288/* Deletes rows */
289COINLIBAPI void COINLINKAGE
290Clp_deleteRows(Clp_Simplex * model, int number, const int * which)
291{
292  model->model_->deleteRows(number,which);
293}
294/* Add rows */
295COINLIBAPI void COINLINKAGE
296Clp_addRows(Clp_Simplex * model, int number, const double * rowLower, 
297               const double * rowUpper,
298               const int * rowStarts, const int * columns,
299               const double * elements)
300{
301  model->model_->addRows(number,rowLower,rowUpper,rowStarts,columns,elements);
302}
303
304/* Deletes columns */
305COINLIBAPI void COINLINKAGE
306Clp_deleteColumns(Clp_Simplex * model, int number, const int * which)
307{
308  model->model_->deleteColumns(number,which);
309}
310/* Add columns */
311COINLIBAPI void COINLINKAGE
312Clp_addColumns(Clp_Simplex * model, int number, const double * columnLower, 
313                  const double * columnUpper,
314                  const double * objective,
315                  const int * columnStarts, const int * rows,
316                  const double * elements)
317{
318  model->model_->addColumns(number,columnLower,columnUpper,objective,
319                            columnStarts,rows,elements);
320}
321/* Change row lower bounds */
322COINLIBAPI void COINLINKAGE
323Clp_chgRowLower(Clp_Simplex * model, const double * rowLower) 
324{
325  model->model_->chgRowLower(rowLower);
326}
327/* Change row upper bounds */
328COINLIBAPI void COINLINKAGE
329Clp_chgRowUpper(Clp_Simplex * model, const double * rowUpper) 
330{
331  model->model_->chgRowUpper(rowUpper);
332}
333/* Change column lower bounds */
334COINLIBAPI void COINLINKAGE
335Clp_chgColumnLower(Clp_Simplex * model, const double * columnLower) 
336{
337  model->model_->chgColumnLower(columnLower);
338}
339/* Change column upper bounds */
340COINLIBAPI void COINLINKAGE
341Clp_chgColumnUpper(Clp_Simplex * model, const double * columnUpper) 
342{
343  model->model_->chgColumnUpper(columnUpper);
344}
345/* Change objective coefficients */
346COINLIBAPI void COINLINKAGE
347Clp_chgObjCoefficients(Clp_Simplex * model, const double * objIn) 
348{
349  model->model_->chgObjCoefficients(objIn);
350}
351/* Drops names - makes lengthnames 0 and names empty */
352COINLIBAPI void COINLINKAGE
353Clp_dropNames(Clp_Simplex * model)
354{
355  model->model_->dropNames();
356}
357/* Copies in names */
358COINLIBAPI void COINLINKAGE
359Clp_copyNames(Clp_Simplex * model, const char * const * rowNamesIn,
360              const char * const * columnNamesIn)
361{
362  int iRow;
363  std::vector<std::string> rowNames;
364  int numberRows = model->model_->numberRows();
365  rowNames.reserve(numberRows);
366  for (iRow=0;iRow<numberRows;iRow++) {
367    rowNames.push_back(rowNamesIn[iRow]);
368  }
369 
370  int iColumn;
371  std::vector<std::string> columnNames;
372  int numberColumns = model->model_->numberColumns();
373  columnNames.reserve(numberColumns);
374  for (iColumn=0;iColumn<numberColumns;iColumn++) {
375    columnNames.push_back(columnNamesIn[iColumn]);
376  }
377  model->model_->copyNames(rowNames,columnNames);
378}
379
380/* Number of rows */
381COINLIBAPI int COINLINKAGE
382Clp_numberRows(Clp_Simplex * model)
383{
384  return model->model_->numberRows();
385}
386/* Number of columns */
387COINLIBAPI int COINLINKAGE
388Clp_numberColumns(Clp_Simplex * model)
389{
390  return model->model_->numberColumns();
391}
392/* Primal tolerance to use */
393COINLIBAPI double COINLINKAGE
394Clp_primalTolerance(Clp_Simplex * model)
395{
396  return model->model_->primalTolerance();
397}
398COINLIBAPI void COINLINKAGE
399Clp_setPrimalTolerance(Clp_Simplex * model,  double value) 
400{
401  model->model_->setPrimalTolerance(value);
402}
403/* Dual tolerance to use */
404COINLIBAPI double COINLINKAGE
405Clp_dualTolerance(Clp_Simplex * model)
406{
407  return model->model_->dualTolerance();
408}
409COINLIBAPI void COINLINKAGE
410Clp_setDualTolerance(Clp_Simplex * model,  double value) 
411{
412  model->model_->setDualTolerance(value);
413}
414/* Dual objective limit */
415COINLIBAPI double COINLINKAGE
416Clp_dualObjectiveLimit(Clp_Simplex * model)
417{
418  return model->model_->dualObjectiveLimit();
419}
420COINLIBAPI void COINLINKAGE
421Clp_setDualObjectiveLimit(Clp_Simplex * model, double value)
422{
423  model->model_->setDualObjectiveLimit(value);
424}
425/* Objective offset */
426COINLIBAPI double COINLINKAGE
427Clp_objectiveOffset(Clp_Simplex * model)
428{
429  return model->model_->objectiveOffset();
430}
431COINLIBAPI void COINLINKAGE
432Clp_setObjectiveOffset(Clp_Simplex * model, double value)
433{
434  model->model_->setObjectiveOffset(value);
435}
436/* Fills in array with problem name  */
437COINLIBAPI void COINLINKAGE
438Clp_problemName(Clp_Simplex * model, int maxNumberCharacters, char * array)
439{
440  std::string name = model->model_->problemName();
441  maxNumberCharacters = CoinMin(maxNumberCharacters,(int)strlen(name.c_str()));
442  strncpy(array,name.c_str(),maxNumberCharacters-1);
443  array[maxNumberCharacters-1]='\0';
444}
445/* Sets problem name.  Must have \0 at end.  */
446COINLIBAPI int COINLINKAGE
447Clp_setProblemName(Clp_Simplex * model, int maxNumberCharacters, char * array)
448{
449  return model->model_->setStrParam(ClpProbName, array);
450}
451/* Number of iterations */
452COINLIBAPI int COINLINKAGE
453Clp_numberIterations(Clp_Simplex * model)
454{
455  return model->model_->numberIterations();
456}
457COINLIBAPI void COINLINKAGE
458Clp_setNumberIterations(Clp_Simplex * model, int numberIterations)
459{
460  model->model_->setNumberIterations(numberIterations);
461}
462/* Maximum number of iterations */
463COINLIBAPI int maximumIterations(Clp_Simplex * model)
464{
465  return model->model_->maximumIterations();
466}
467COINLIBAPI void COINLINKAGE
468Clp_setMaximumIterations(Clp_Simplex * model, int value)
469{
470  model->model_->setMaximumIterations(value);
471}
472/* Maximum time in seconds (from when set called) */
473COINLIBAPI double COINLINKAGE
474Clp_maximumSeconds(Clp_Simplex * model)
475{
476  return model->model_->maximumSeconds();
477}
478COINLIBAPI void COINLINKAGE
479Clp_setMaximumSeconds(Clp_Simplex * model, double value)
480{
481  model->model_->setMaximumSeconds(value);
482}
483/* Returns true if hit maximum iteratio`ns (or time) */
484COINLIBAPI int COINLINKAGE
485Clp_hitMaximumIterations(Clp_Simplex * model)
486{
487  return model->model_->hitMaximumIterations() ? 1 : 0;
488}
489/* Status of problem:
490   0 - optimal
491   1 - primal infeasible
492   2 - dual infeasible
493   3 - stopped on iterations etc
494   4 - stopped due to errors
495*/
496COINLIBAPI int COINLINKAGE
497Clp_status(Clp_Simplex * model)
498{
499  return model->model_->status();
500}
501/* Set problem status */
502COINLIBAPI void COINLINKAGE
503Clp_setProblemStatus(Clp_Simplex * model, int problemStatus)
504{
505  model->model_->setProblemStatus(problemStatus);
506}
507/* Secondary status of problem - may get extended
508   0 - none
509   1 - primal infeasible because dual limit reached
510   2 - scaled problem optimal - unscaled has primal infeasibilities
511   3 - scaled problem optimal - unscaled has dual infeasibilities
512   4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
513*/
514COINLIBAPI int COINLINKAGE
515Clp_secondaryStatus(Clp_Simplex * model)
516{
517  return model->model_->secondaryStatus();
518}
519COINLIBAPI void COINLINKAGE
520Clp_setSecondaryStatus(Clp_Simplex * model, int status)
521{
522  model->model_->setSecondaryStatus(status);
523}
524/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
525COINLIBAPI double COINLINKAGE
526Clp_optimizationDirection(Clp_Simplex * model)
527{
528  return model->model_->optimizationDirection();
529}
530COINLIBAPI void COINLINKAGE
531Clp_setOptimizationDirection(Clp_Simplex * model, double value)
532{
533  model->model_->setOptimizationDirection(value);
534}
535/* Primal row solution */
536COINLIBAPI double * COINLINKAGE
537Clp_primalRowSolution(Clp_Simplex * model)
538{
539  return model->model_->primalRowSolution();
540}
541/* Primal column solution */
542COINLIBAPI double * COINLINKAGE
543Clp_primalColumnSolution(Clp_Simplex * model)
544{
545  return model->model_->primalColumnSolution();
546}
547/* Dual row solution */
548COINLIBAPI double * COINLINKAGE
549Clp_dualRowSolution(Clp_Simplex * model)
550{
551  return model->model_->dualRowSolution();
552}
553/* Reduced costs */
554COINLIBAPI double * COINLINKAGE
555Clp_dualColumnSolution(Clp_Simplex * model)
556{
557  return model->model_->dualColumnSolution();
558}
559/* Row lower */
560COINLIBAPI double* COINLINKAGE
561Clp_rowLower(Clp_Simplex * model)
562{
563  return model->model_->rowLower();
564}
565/* Row upper  */
566COINLIBAPI double* COINLINKAGE
567Clp_rowUpper(Clp_Simplex * model)
568{
569  return model->model_->rowUpper();
570}
571/* Objective */
572COINLIBAPI double * COINLINKAGE
573Clp_objective(Clp_Simplex * model)
574{
575  return model->model_->objective();
576}
577/* Column Lower */
578COINLIBAPI double * COINLINKAGE
579Clp_columnLower(Clp_Simplex * model)
580{
581  return model->model_->columnLower();
582}
583/* Column Upper */
584COINLIBAPI double * COINLINKAGE
585Clp_columnUpper(Clp_Simplex * model)
586{
587  return model->model_->columnUpper();
588}
589/* Number of elements in matrix */
590COINLIBAPI int COINLINKAGE
591Clp_getNumElements(Clp_Simplex * model)
592{
593  return model->model_->getNumElements();
594}
595// Column starts in matrix
596COINLIBAPI const CoinBigIndex * COINLINKAGE Clp_getVectorStarts(Clp_Simplex * model)
597{
598  CoinPackedMatrix * matrix;
599  matrix = model->model_->matrix();
600  return (matrix == NULL) ? NULL : matrix->getVectorStarts();
601}
602
603// Row indices in matrix
604COINLIBAPI const int * COINLINKAGE Clp_getIndices(Clp_Simplex * model)
605{
606  CoinPackedMatrix * matrix = model->model_->matrix();
607  return (matrix == NULL) ? NULL : matrix->getIndices();
608} 
609
610// Column vector lengths in matrix
611COINLIBAPI const int * COINLINKAGE Clp_getVectorLengths(Clp_Simplex * model)
612{
613  CoinPackedMatrix * matrix = model->model_->matrix();
614  return (matrix == NULL) ? NULL : matrix->getVectorLengths();
615} 
616 
617// Element values in matrix
618COINLIBAPI const double * COINLINKAGE Clp_getElements(Clp_Simplex * model)
619{
620  CoinPackedMatrix * matrix = model->model_->matrix();
621  return (matrix == NULL) ? NULL : matrix->getElements();
622}
623/* Objective value */
624COINLIBAPI double COINLINKAGE
625Clp_objectiveValue(Clp_Simplex * model)
626{
627  return model->model_->objectiveValue();
628}
629/* Integer information */
630COINLIBAPI char * COINLINKAGE
631Clp_integerInformation(Clp_Simplex * model)
632{
633  return model->model_->integerInformation();
634}
635/* Infeasibility/unbounded ray (NULL returned if none/wrong)
636   Up to user to use delete [] on these arrays.  */
637COINLIBAPI double * COINLINKAGE
638Clp_infeasibilityRay(Clp_Simplex * model)
639{
640  return model->model_->infeasibilityRay();
641}
642COINLIBAPI double * COINLINKAGE
643Clp_unboundedRay(Clp_Simplex * model)
644{
645  return model->model_->unboundedRay();
646}
647/* See if status array exists (partly for OsiClp) */
648COINLIBAPI int COINLINKAGE
649Clp_statusExists(Clp_Simplex * model)
650{
651  return model->model_->statusExists() ? 1 : 0;
652}
653/* Return address of status array (char[numberRows+numberColumns]) */
654COINLIBAPI unsigned char *  COINLINKAGE
655Clp_statusArray(Clp_Simplex * model)
656{
657  return model->model_->statusArray();
658}
659/* Copy in status vector */
660COINLIBAPI void COINLINKAGE
661Clp_copyinStatus(Clp_Simplex * model, const unsigned char * statusArray)
662{
663  model->model_->copyinStatus(statusArray);
664}
665
666/* User pointer for whatever reason */
667COINLIBAPI void COINLINKAGE
668Clp_setUserPointer (Clp_Simplex * model, void * pointer)
669{
670  model->model_->setUserPointer(pointer);
671}
672COINLIBAPI void * COINLINKAGE
673Clp_getUserPointer (Clp_Simplex * model)
674{
675  return model->model_->getUserPointer();
676}
677/* Pass in Callback function */
678COINLIBAPI void COINLINKAGE
679Clp_registerCallBack(Clp_Simplex * model, 
680                     clp_callback userCallBack)
681{
682  // Will be copy of users one
683  delete model->handler_;
684  model->handler_ = new CMessageHandler(*(model->model_->messageHandler()));
685  model->handler_->setCallBack(userCallBack);
686  model->handler_->setModel(model);
687  model->model_->passInMessageHandler(model->handler_);
688}
689/* Unset Callback function */
690COINLIBAPI void COINLINKAGE
691Clp_clearCallBack(Clp_Simplex * model)
692{
693  delete model->handler_;
694  model->handler_=NULL;
695}
696/* Amount of print out:
697   0 - none
698   1 - just final
699   2 - just factorizations
700   3 - as 2 plus a bit more
701   4 - verbose
702   above that 8,16,32 etc just for selective debug
703*/
704COINLIBAPI void COINLINKAGE
705Clp_setLogLevel(Clp_Simplex * model, int value)
706{
707  model->model_->setLogLevel(value);
708}
709COINLIBAPI int COINLINKAGE
710Clp_logLevel(Clp_Simplex * model)
711{
712  return model->model_->logLevel();
713}
714/* length of names (0 means no names0 */
715COINLIBAPI int COINLINKAGE
716Clp_lengthNames(Clp_Simplex * model)
717{
718  return model->model_->lengthNames();
719}
720/* Fill in array (at least lengthNames+1 long) with a row name */
721COINLIBAPI void COINLINKAGE
722Clp_rowName(Clp_Simplex * model, int iRow, char * name)
723{
724  std::string rowName=model->model_->rowName(iRow);
725  strcpy(name,rowName.c_str());
726}
727/* Fill in array (at least lengthNames+1 long) with a column name */
728COINLIBAPI void COINLINKAGE
729Clp_columnName(Clp_Simplex * model, int iColumn, char * name)
730{
731  std::string columnName= model->model_->columnName(iColumn);
732  strcpy(name,columnName.c_str());
733}
734
735/* General solve algorithm which can do presolve.
736   See  ClpSolve.hpp for options
737*/
738COINLIBAPI int COINLINKAGE
739Clp_initialSolve(Clp_Simplex * model)
740{
741  return model->model_->initialSolve();
742}
743/* Barrier initial solve */
744COINLIBAPI int COINLINKAGE
745Clp_initialBarrierSolve(Clp_Simplex * model0)
746{
747   ClpSimplex *model = model0->model_;
748
749   return model->initialBarrierSolve();
750   
751}
752/* Barrier initial solve */
753COINLIBAPI int COINLINKAGE
754Clp_initialBarrierNoCrossSolve(Clp_Simplex * model0)
755{
756   ClpSimplex *model = model0->model_;
757
758   return model->initialBarrierNoCrossSolve();
759   
760}
761/* Dual initial solve */
762COINLIBAPI int COINLINKAGE
763Clp_initialDualSolve(Clp_Simplex * model)
764{
765  return model->model_->initialDualSolve();
766}
767/* Primal initial solve */
768COINLIBAPI int COINLINKAGE
769Clp_initialPrimalSolve(Clp_Simplex * model)
770{
771  return model->model_->initialPrimalSolve();
772}
773/* Dual algorithm - see ClpSimplexDual.hpp for method */
774COINLIBAPI int COINLINKAGE
775Clp_dual(Clp_Simplex * model, int ifValuesPass)
776{
777  return model->model_->dual(ifValuesPass);
778}
779/* Primal algorithm - see ClpSimplexPrimal.hpp for method */
780COINLIBAPI int COINLINKAGE
781Clp_primal(Clp_Simplex * model, int ifValuesPass)
782{
783  return model->model_->primal(ifValuesPass);
784}
785/* Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
786COINLIBAPI void COINLINKAGE
787Clp_scaling(Clp_Simplex * model, int mode)
788{
789  model->model_->scaling(mode);
790}
791/* Gets scalingFlag */
792COINLIBAPI int COINLINKAGE
793Clp_scalingFlag(Clp_Simplex * model)
794{
795  return model->model_->scalingFlag();
796}
797/* Crash - at present just aimed at dual, returns
798   -2 if dual preferred and crash basis created
799   -1 if dual preferred and all slack basis preferred
800   0 if basis going in was not all slack
801   1 if primal preferred and all slack basis preferred
802   2 if primal preferred and crash basis created.
803   
804   if gap between bounds <="gap" variables can be flipped
805   
806   If "pivot" is
807   0 No pivoting (so will just be choice of algorithm)
808   1 Simple pivoting e.g. gub
809   2 Mini iterations
810*/
811COINLIBAPI int COINLINKAGE
812Clp_crash(Clp_Simplex * model, double gap,int pivot)
813{
814  return model->model_->crash(gap,pivot);
815}
816/* If problem is primal feasible */
817COINLIBAPI int COINLINKAGE
818Clp_primalFeasible(Clp_Simplex * model)
819{
820  return model->model_->primalFeasible() ? 1 : 0;
821}
822/* If problem is dual feasible */
823COINLIBAPI int COINLINKAGE
824Clp_dualFeasible(Clp_Simplex * model)
825{
826  return model->model_->dualFeasible() ? 1 : 0;
827}
828/* Dual bound */
829COINLIBAPI double COINLINKAGE
830Clp_dualBound(Clp_Simplex * model)
831{
832  return model->model_->dualBound();
833}
834COINLIBAPI void COINLINKAGE
835Clp_setDualBound(Clp_Simplex * model, double value)
836{
837  model->model_->setDualBound(value);
838}
839/* Infeasibility cost */
840COINLIBAPI double COINLINKAGE
841Clp_infeasibilityCost(Clp_Simplex * model)
842{
843  return model->model_->infeasibilityCost();
844}
845COINLIBAPI void COINLINKAGE
846Clp_setInfeasibilityCost(Clp_Simplex * model, double value)
847{
848  model->model_->setInfeasibilityCost(value);
849}
850/* Perturbation:
851   50  - switch on perturbation
852   100 - auto perturb if takes too long (1.0e-6 largest nonzero)
853   101 - we are perturbed
854   102 - don't try perturbing again
855   default is 100
856   others are for playing
857*/
858COINLIBAPI int COINLINKAGE
859Clp_perturbation(Clp_Simplex * model)
860{
861  return model->model_->perturbation();
862}
863COINLIBAPI void COINLINKAGE
864Clp_setPerturbation(Clp_Simplex * model, int value)
865{
866  model->model_->setPerturbation(value);
867}
868/* Current (or last) algorithm */
869COINLIBAPI int COINLINKAGE
870Clp_algorithm(Clp_Simplex * model)
871{
872  return model->model_->algorithm();
873}
874/* Set algorithm */
875COINLIBAPI void COINLINKAGE
876Clp_setAlgorithm(Clp_Simplex * model, int value)
877{
878  model->model_->setAlgorithm(value);
879}
880/* Sum of dual infeasibilities */
881COINLIBAPI double COINLINKAGE
882Clp_sumDualInfeasibilities(Clp_Simplex * model)
883{
884  return model->model_->sumDualInfeasibilities();
885}
886/* Number of dual infeasibilities */
887COINLIBAPI int COINLINKAGE
888Clp_numberDualInfeasibilities(Clp_Simplex * model)
889{
890  return model->model_->numberDualInfeasibilities();
891}
892/* Sum of primal infeasibilities */
893COINLIBAPI double COINLINKAGE
894Clp_sumPrimalInfeasibilities(Clp_Simplex * model)
895{
896  return model->model_->sumPrimalInfeasibilities();
897}
898/* Number of primal infeasibilities */
899COINLIBAPI int COINLINKAGE
900Clp_numberPrimalInfeasibilities(Clp_Simplex * model)
901{
902  return model->model_->numberPrimalInfeasibilities();
903}
904/* Save model to file, returns 0 if success.  This is designed for
905   use outside algorithms so does not save iterating arrays etc.
906   It does not save any messaging information.
907   Does not save scaling values.
908   It does not know about all types of virtual functions.
909*/
910COINLIBAPI int COINLINKAGE
911Clp_saveModel(Clp_Simplex * model, const char * fileName)
912{
913  return model->model_->saveModel(fileName);
914}
915/* Restore model from file, returns 0 if success,
916   deletes current model */
917COINLIBAPI int COINLINKAGE
918Clp_restoreModel(Clp_Simplex * model, const char * fileName)
919{
920  return model->model_->restoreModel(fileName);
921}
922 
923/* Just check solution (for external use) - sets sum of
924   infeasibilities etc */
925COINLIBAPI void COINLINKAGE
926Clp_checkSolution(Clp_Simplex * model)
927{
928  model->model_->checkSolution();
929}
930/* Number of rows */
931COINLIBAPI int COINLINKAGE
932Clp_getNumRows(Clp_Simplex * model)
933{
934  return model->model_->getNumRows();
935}
936/* Number of columns */
937COINLIBAPI int COINLINKAGE
938Clp_getNumCols(Clp_Simplex * model)
939{
940  return model->model_->getNumCols();
941}
942/* Number of iterations */
943COINLIBAPI int COINLINKAGE
944Clp_getIterationCount(Clp_Simplex * model)
945{
946  return model->model_->getIterationCount();
947}
948/* Are there a numerical difficulties? */
949COINLIBAPI int COINLINKAGE
950Clp_isAbandoned(Clp_Simplex * model)
951{
952  return model->model_->isAbandoned() ? 1 : 0;
953}
954/* Is optimality proven? */
955COINLIBAPI int COINLINKAGE
956Clp_isProvenOptimal(Clp_Simplex * model)
957{
958  return model->model_->isProvenOptimal() ? 1 : 0;
959}
960/* Is primal infeasiblity proven? */
961COINLIBAPI int COINLINKAGE
962Clp_isProvenPrimalInfeasible(Clp_Simplex * model)
963{
964  return model->model_->isProvenPrimalInfeasible() ? 1 : 0;
965}
966/* Is dual infeasiblity proven? */
967COINLIBAPI int COINLINKAGE
968Clp_isProvenDualInfeasible(Clp_Simplex * model)
969{
970  return model->model_->isProvenDualInfeasible() ? 1 : 0;
971}
972/* Is the given primal objective limit reached? */
973COINLIBAPI int COINLINKAGE
974Clp_isPrimalObjectiveLimitReached(Clp_Simplex * model) 
975{
976  return model->model_->isPrimalObjectiveLimitReached() ? 1 : 0;
977}
978/* Is the given dual objective limit reached? */
979COINLIBAPI int COINLINKAGE
980Clp_isDualObjectiveLimitReached(Clp_Simplex * model) 
981{
982  return model->model_->isDualObjectiveLimitReached() ? 1 : 0;
983}
984/* Iteration limit reached? */
985COINLIBAPI int COINLINKAGE
986Clp_isIterationLimitReached(Clp_Simplex * model)
987{
988  return model->model_->isIterationLimitReached() ? 1 : 0;
989}
990/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
991COINLIBAPI double COINLINKAGE
992Clp_getObjSense(Clp_Simplex * model)
993{
994  return model->model_->getObjSense();
995}
996/* Primal row solution */
997COINLIBAPI const double * COINLINKAGE
998Clp_getRowActivity(Clp_Simplex * model)
999{
1000  return model->model_->getRowActivity();
1001}
1002/* Primal column solution */
1003COINLIBAPI const double * COINLINKAGE
1004Clp_getColSolution(Clp_Simplex * model)
1005{
1006  return model->model_->getColSolution();
1007}
1008COINLIBAPI void COINLINKAGE
1009Clp_setColSolution(Clp_Simplex * model, const double * input)
1010{
1011  model->model_->setColSolution(input);
1012}
1013/* Dual row solution */
1014COINLIBAPI const double * COINLINKAGE
1015Clp_getRowPrice(Clp_Simplex * model)
1016{
1017  return model->model_->getRowPrice();
1018}
1019/* Reduced costs */
1020COINLIBAPI const double * COINLINKAGE
1021Clp_getReducedCost(Clp_Simplex * model)
1022{
1023  return model->model_->getReducedCost();
1024}
1025/* Row lower */
1026COINLIBAPI const double* COINLINKAGE
1027Clp_getRowLower(Clp_Simplex * model)
1028{
1029  return model->model_->getRowLower();
1030}
1031/* Row upper  */
1032COINLIBAPI const double* COINLINKAGE
1033Clp_getRowUpper(Clp_Simplex * model)
1034{
1035  return model->model_->getRowUpper();
1036}
1037/* Objective */
1038COINLIBAPI const double * COINLINKAGE
1039Clp_getObjCoefficients(Clp_Simplex * model)
1040{
1041  return model->model_->getObjCoefficients();
1042}
1043/* Column Lower */
1044COINLIBAPI const double * COINLINKAGE
1045Clp_getColLower(Clp_Simplex * model)
1046{
1047  return model->model_->getColLower();
1048}
1049/* Column Upper */
1050COINLIBAPI const double * COINLINKAGE
1051Clp_getColUpper(Clp_Simplex * model)
1052{
1053  return model->model_->getColUpper();
1054}
1055/* Objective value */
1056COINLIBAPI double COINLINKAGE
1057Clp_getObjValue(Clp_Simplex * model)
1058{
1059  return model->model_->getObjValue();
1060}
1061/* Get variable basis info */
1062COINLIBAPI int COINLINKAGE
1063Clp_getColumnStatus(Clp_Simplex * model,int sequence)
1064{
1065  return (int) model->model_->getColumnStatus(sequence);
1066}
1067/* Get row basis info */
1068COINLIBAPI int COINLINKAGE
1069Clp_getRowStatus(Clp_Simplex * model,int sequence)
1070{
1071  return (int) model->model_->getRowStatus(sequence);
1072}
1073/* Set variable basis info */
1074COINLIBAPI void COINLINKAGE
1075Clp_setColumnStatus(Clp_Simplex * model,int sequence, int value)
1076{
1077  if (value>=0&&value<=5) {
1078    model->model_->setColumnStatus(sequence,(ClpSimplex::Status) value );
1079    if (value==3||value==5)
1080      model->model_->primalColumnSolution()[sequence]=
1081        model->model_->columnLower()[sequence];
1082    else if (value==2)
1083      model->model_->primalColumnSolution()[sequence]=
1084        model->model_->columnUpper()[sequence];
1085  }
1086}
1087/* Set row basis info */
1088COINLIBAPI void COINLINKAGE
1089Clp_setRowStatus(Clp_Simplex * model,int sequence, int value)
1090{
1091  if (value>=0&&value<=5) {
1092    model->model_->setRowStatus(sequence,(ClpSimplex::Status) value );
1093    if (value==3||value==5)
1094      model->model_->primalRowSolution()[sequence]=
1095        model->model_->rowLower()[sequence];
1096    else if (value==2)
1097      model->model_->primalRowSolution()[sequence]=
1098        model->model_->rowUpper()[sequence];
1099  }
1100}
1101/* Small element value - elements less than this set to zero,
1102   default is 1.0e-20 */
1103COINLIBAPI double COINLINKAGE
1104Clp_getSmallElementValue(Clp_Simplex * model)
1105{
1106  return model->model_->getSmallElementValue();
1107}
1108COINLIBAPI void COINLINKAGE
1109Clp_setSmallElementValue(Clp_Simplex * model,double value)
1110{
1111  model->model_->setSmallElementValue(value);
1112}
1113/* Print model */
1114COINLIBAPI void COINLINKAGE
1115Clp_printModel(Clp_Simplex * model, const char * prefix)
1116{
1117  ClpSimplex *clp_simplex = model->model_;
1118  int numrows    = clp_simplex->numberRows();
1119  int numcols    = clp_simplex->numberColumns();
1120  int numelem    = clp_simplex->getNumElements();
1121  const CoinBigIndex *start = clp_simplex->matrix()->getVectorStarts();
1122  const int *index     = clp_simplex->matrix()->getIndices();
1123  const double *value  = clp_simplex->matrix()->getElements();
1124  const double *collb  = model->model_->columnLower();
1125  const double *colub  = model->model_->columnUpper();
1126  const double *obj    = model->model_->objective();
1127  const double *rowlb  = model->model_->rowLower();
1128  const double *rowub  = model->model_->rowUpper();
1129  printf("%s numcols = %i, numrows = %i, numelem = %i\n", 
1130    prefix, numcols, numrows, numelem);
1131  printf("%s model = %p, start = %p, index = %p, value = %p\n",
1132    prefix, (void*)model, (void*)start, (void*)index, (void*)value);
1133  clp_simplex->matrix()->dumpMatrix(NULL);
1134  {
1135    int i;
1136    for (i=0; i<=numcols; i++) 
1137      printf("%s start[%i] = %i\n", prefix, i, start[i]);
1138    for (i=0; i< numelem; i++)
1139      printf("%s index[%i] = %i, value[%i] = %g\n",
1140        prefix, i, index[i], i, value[i]);
1141  }
1142 
1143  printf("%s collb = %p, colub = %p, obj = %p, rowlb = %p, rowub = %p\n",
1144    prefix, (void*)collb, (void*)colub, (void*)obj, (void*)rowlb, (void*)rowub);
1145  printf("%s optimization direction = %g\n",prefix, Clp_optimizationDirection(model));
1146  printf("  (1 - minimize, -1 - maximize, 0 - ignore)\n");
1147  {
1148    int i;
1149    for (i=0; i<numcols; i++) 
1150      printf("%s collb[%i] = %g, colub[%i] = %g, obj[%i] = %g\n",
1151        prefix, i, collb[i], i, colub[i], i, obj[i]);
1152    for (i=0; i< numrows; i++)
1153      printf("%s rowlb[%i] = %g, rowub[%i] = %g\n",
1154        prefix, i, rowlb[i], i, rowub[i]);
1155  }
1156}
1157#if defined(__MWERKS__)
1158#pragma export off
1159#endif
1160
Note: See TracBrowser for help on using the repository browser.