source: branches/BSP/trunk/Clp/src/Clp_C_Interface.cpp @ 1079

Last change on this file since 1079 was 1079, checked in by stefan, 12 years ago

avoid warning that const-qualifier will be ignored in return argument by taking const-qualifier out

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