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

Last change on this file since 1525 was 1525, checked in by mjs, 10 years ago

Formatted .cpp, .hpp, .c, .h files with "astyle -A4 -p". This matches the formatting used in the grand CBC reorganization.

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