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

Last change on this file since 754 was 754, checked in by andreasw, 13 years ago

first version

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