source: branches/ClpForOsi2/Clp/src/Clp_C_Interface.cpp @ 1759

Last change on this file since 1759 was 1759, checked in by lou, 9 years ago

Add a Clp_model routine to return the underlying ClpSimplex? object.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 34.9 KB
Line 
1// $Id: Clp_C_Interface.cpp 1759 2011-06-29 17:57:53Z lou $
2// Copyright (C) 2003, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
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/* Underlying model */
384COINLIBAPI void* COINLINKAGE
385Clp_model(Clp_Simplex * model)
386{
387  return model->model_ ;
388}
389/* Number of rows */
390COINLIBAPI int COINLINKAGE
391Clp_numberRows(Clp_Simplex * model)
392{
393     return model->model_->numberRows();
394}
395/* Number of columns */
396COINLIBAPI int COINLINKAGE
397Clp_numberColumns(Clp_Simplex * model)
398{
399     return model->model_->numberColumns();
400}
401/* Primal tolerance to use */
402COINLIBAPI double COINLINKAGE
403Clp_primalTolerance(Clp_Simplex * model)
404{
405     return model->model_->primalTolerance();
406}
407COINLIBAPI void COINLINKAGE
408Clp_setPrimalTolerance(Clp_Simplex * model,  double value)
409{
410     model->model_->setPrimalTolerance(value);
411}
412/* Dual tolerance to use */
413COINLIBAPI double COINLINKAGE
414Clp_dualTolerance(Clp_Simplex * model)
415{
416     return model->model_->dualTolerance();
417}
418COINLIBAPI void COINLINKAGE
419Clp_setDualTolerance(Clp_Simplex * model,  double value)
420{
421     model->model_->setDualTolerance(value);
422}
423/* Dual objective limit */
424COINLIBAPI double COINLINKAGE
425Clp_dualObjectiveLimit(Clp_Simplex * model)
426{
427     return model->model_->dualObjectiveLimit();
428}
429COINLIBAPI void COINLINKAGE
430Clp_setDualObjectiveLimit(Clp_Simplex * model, double value)
431{
432     model->model_->setDualObjectiveLimit(value);
433}
434/* Objective offset */
435COINLIBAPI double COINLINKAGE
436Clp_objectiveOffset(Clp_Simplex * model)
437{
438     return model->model_->objectiveOffset();
439}
440COINLIBAPI void COINLINKAGE
441Clp_setObjectiveOffset(Clp_Simplex * model, double value)
442{
443     model->model_->setObjectiveOffset(value);
444}
445/* Fills in array with problem name  */
446COINLIBAPI void COINLINKAGE
447Clp_problemName(Clp_Simplex * model, int maxNumberCharacters, char * array)
448{
449     std::string name = model->model_->problemName();
450     maxNumberCharacters = CoinMin(maxNumberCharacters,
451                                   ((int) strlen(name.c_str()))+1) ;
452     strncpy(array, name.c_str(), maxNumberCharacters - 1);
453     array[maxNumberCharacters-1] = '\0';
454}
455/* Sets problem name.  Must have \0 at end.  */
456COINLIBAPI int COINLINKAGE
457Clp_setProblemName(Clp_Simplex * model, int /*maxNumberCharacters*/, char * array)
458{
459     return model->model_->setStrParam(ClpProbName, array);
460}
461/* Number of iterations */
462COINLIBAPI int COINLINKAGE
463Clp_numberIterations(Clp_Simplex * model)
464{
465     return model->model_->numberIterations();
466}
467COINLIBAPI void COINLINKAGE
468Clp_setNumberIterations(Clp_Simplex * model, int numberIterations)
469{
470     model->model_->setNumberIterations(numberIterations);
471}
472/* Maximum number of iterations */
473COINLIBAPI int maximumIterations(Clp_Simplex * model)
474{
475     return model->model_->maximumIterations();
476}
477COINLIBAPI void COINLINKAGE
478Clp_setMaximumIterations(Clp_Simplex * model, int value)
479{
480     model->model_->setMaximumIterations(value);
481}
482/* Maximum time in seconds (from when set called) */
483COINLIBAPI double COINLINKAGE
484Clp_maximumSeconds(Clp_Simplex * model)
485{
486     return model->model_->maximumSeconds();
487}
488COINLIBAPI void COINLINKAGE
489Clp_setMaximumSeconds(Clp_Simplex * model, double value)
490{
491     model->model_->setMaximumSeconds(value);
492}
493/* Returns true if hit maximum iteratio`ns (or time) */
494COINLIBAPI int COINLINKAGE
495Clp_hitMaximumIterations(Clp_Simplex * model)
496{
497     return model->model_->hitMaximumIterations() ? 1 : 0;
498}
499/* Status of problem:
500   0 - optimal
501   1 - primal infeasible
502   2 - dual infeasible
503   3 - stopped on iterations etc
504   4 - stopped due to errors
505*/
506COINLIBAPI int COINLINKAGE
507Clp_status(Clp_Simplex * model)
508{
509     return model->model_->status();
510}
511/* Set problem status */
512COINLIBAPI void COINLINKAGE
513Clp_setProblemStatus(Clp_Simplex * model, int problemStatus)
514{
515     model->model_->setProblemStatus(problemStatus);
516}
517/* Secondary status of problem - may get extended
518   0 - none
519   1 - primal infeasible because dual limit reached
520   2 - scaled problem optimal - unscaled has primal infeasibilities
521   3 - scaled problem optimal - unscaled has dual infeasibilities
522   4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
523*/
524COINLIBAPI int COINLINKAGE
525Clp_secondaryStatus(Clp_Simplex * model)
526{
527     return model->model_->secondaryStatus();
528}
529COINLIBAPI void COINLINKAGE
530Clp_setSecondaryStatus(Clp_Simplex * model, int status)
531{
532     model->model_->setSecondaryStatus(status);
533}
534/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
535COINLIBAPI double COINLINKAGE
536Clp_optimizationDirection(Clp_Simplex * model)
537{
538     return model->model_->optimizationDirection();
539}
540COINLIBAPI void COINLINKAGE
541Clp_setOptimizationDirection(Clp_Simplex * model, double value)
542{
543     model->model_->setOptimizationDirection(value);
544}
545/* Primal row solution */
546COINLIBAPI double * COINLINKAGE
547Clp_primalRowSolution(Clp_Simplex * model)
548{
549     return model->model_->primalRowSolution();
550}
551/* Primal column solution */
552COINLIBAPI double * COINLINKAGE
553Clp_primalColumnSolution(Clp_Simplex * model)
554{
555     return model->model_->primalColumnSolution();
556}
557/* Dual row solution */
558COINLIBAPI double * COINLINKAGE
559Clp_dualRowSolution(Clp_Simplex * model)
560{
561     return model->model_->dualRowSolution();
562}
563/* Reduced costs */
564COINLIBAPI double * COINLINKAGE
565Clp_dualColumnSolution(Clp_Simplex * model)
566{
567     return model->model_->dualColumnSolution();
568}
569/* Row lower */
570COINLIBAPI double* COINLINKAGE
571Clp_rowLower(Clp_Simplex * model)
572{
573     return model->model_->rowLower();
574}
575/* Row upper  */
576COINLIBAPI double* COINLINKAGE
577Clp_rowUpper(Clp_Simplex * model)
578{
579     return model->model_->rowUpper();
580}
581/* Objective */
582COINLIBAPI double * COINLINKAGE
583Clp_objective(Clp_Simplex * model)
584{
585     return model->model_->objective();
586}
587/* Column Lower */
588COINLIBAPI double * COINLINKAGE
589Clp_columnLower(Clp_Simplex * model)
590{
591     return model->model_->columnLower();
592}
593/* Column Upper */
594COINLIBAPI double * COINLINKAGE
595Clp_columnUpper(Clp_Simplex * model)
596{
597     return model->model_->columnUpper();
598}
599/* Number of elements in matrix */
600COINLIBAPI int COINLINKAGE
601Clp_getNumElements(Clp_Simplex * model)
602{
603     return model->model_->getNumElements();
604}
605// Column starts in matrix
606COINLIBAPI const CoinBigIndex * COINLINKAGE Clp_getVectorStarts(Clp_Simplex * model)
607{
608     CoinPackedMatrix * matrix;
609     matrix = model->model_->matrix();
610     return (matrix == NULL) ? NULL : matrix->getVectorStarts();
611}
612
613// Row indices in matrix
614COINLIBAPI const int * COINLINKAGE Clp_getIndices(Clp_Simplex * model)
615{
616     CoinPackedMatrix * matrix = model->model_->matrix();
617     return (matrix == NULL) ? NULL : matrix->getIndices();
618}
619
620// Column vector lengths in matrix
621COINLIBAPI const int * COINLINKAGE Clp_getVectorLengths(Clp_Simplex * model)
622{
623     CoinPackedMatrix * matrix = model->model_->matrix();
624     return (matrix == NULL) ? NULL : matrix->getVectorLengths();
625}
626
627// Element values in matrix
628COINLIBAPI const double * COINLINKAGE Clp_getElements(Clp_Simplex * model)
629{
630     CoinPackedMatrix * matrix = model->model_->matrix();
631     return (matrix == NULL) ? NULL : matrix->getElements();
632}
633/* Objective value */
634COINLIBAPI double COINLINKAGE
635Clp_objectiveValue(Clp_Simplex * model)
636{
637     return model->model_->objectiveValue();
638}
639/* Integer information */
640COINLIBAPI char * COINLINKAGE
641Clp_integerInformation(Clp_Simplex * model)
642{
643     return model->model_->integerInformation();
644}
645/* Infeasibility/unbounded ray (NULL returned if none/wrong)
646   Up to user to use delete [] on these arrays.  */
647COINLIBAPI double * COINLINKAGE
648Clp_infeasibilityRay(Clp_Simplex * model)
649{
650     return model->model_->infeasibilityRay();
651}
652COINLIBAPI double * COINLINKAGE
653Clp_unboundedRay(Clp_Simplex * model)
654{
655     return model->model_->unboundedRay();
656}
657/* See if status array exists (partly for OsiClp) */
658COINLIBAPI int COINLINKAGE
659Clp_statusExists(Clp_Simplex * model)
660{
661     return model->model_->statusExists() ? 1 : 0;
662}
663/* Return address of status array (char[numberRows+numberColumns]) */
664COINLIBAPI unsigned char *  COINLINKAGE
665Clp_statusArray(Clp_Simplex * model)
666{
667     return model->model_->statusArray();
668}
669/* Copy in status vector */
670COINLIBAPI void COINLINKAGE
671Clp_copyinStatus(Clp_Simplex * model, const unsigned char * statusArray)
672{
673     model->model_->copyinStatus(statusArray);
674}
675
676/* User pointer for whatever reason */
677COINLIBAPI void COINLINKAGE
678Clp_setUserPointer (Clp_Simplex * model, void * pointer)
679{
680     model->model_->setUserPointer(pointer);
681}
682COINLIBAPI void * COINLINKAGE
683Clp_getUserPointer (Clp_Simplex * model)
684{
685     return model->model_->getUserPointer();
686}
687/* Pass in Callback function */
688COINLIBAPI void COINLINKAGE
689Clp_registerCallBack(Clp_Simplex * model,
690                     clp_callback userCallBack)
691{
692     // Will be copy of users one
693     delete model->handler_;
694     model->handler_ = new CMessageHandler(*(model->model_->messageHandler()));
695     model->handler_->setCallBack(userCallBack);
696     model->handler_->setModel(model);
697     model->model_->passInMessageHandler(model->handler_);
698}
699/* Unset Callback function */
700COINLIBAPI void COINLINKAGE
701Clp_clearCallBack(Clp_Simplex * model)
702{
703     delete model->handler_;
704     model->handler_ = NULL;
705}
706/* Amount of print out:
707   0 - none
708   1 - just final
709   2 - just factorizations
710   3 - as 2 plus a bit more
711   4 - verbose
712   above that 8,16,32 etc just for selective debug
713*/
714COINLIBAPI void COINLINKAGE
715Clp_setLogLevel(Clp_Simplex * model, int value)
716{
717     model->model_->setLogLevel(value);
718}
719COINLIBAPI int COINLINKAGE
720Clp_logLevel(Clp_Simplex * model)
721{
722     return model->model_->logLevel();
723}
724/* length of names (0 means no names0 */
725COINLIBAPI int COINLINKAGE
726Clp_lengthNames(Clp_Simplex * model)
727{
728     return model->model_->lengthNames();
729}
730/* Fill in array (at least lengthNames+1 long) with a row name */
731COINLIBAPI void COINLINKAGE
732Clp_rowName(Clp_Simplex * model, int iRow, char * name)
733{
734     std::string rowName = model->model_->rowName(iRow);
735     strcpy(name, rowName.c_str());
736}
737/* Fill in array (at least lengthNames+1 long) with a column name */
738COINLIBAPI void COINLINKAGE
739Clp_columnName(Clp_Simplex * model, int iColumn, char * name)
740{
741     std::string columnName = model->model_->columnName(iColumn);
742     strcpy(name, columnName.c_str());
743}
744
745/* General solve algorithm which can do presolve.
746   See  ClpSolve.hpp for options
747*/
748COINLIBAPI int COINLINKAGE
749Clp_initialSolve(Clp_Simplex * model)
750{
751     return model->model_->initialSolve();
752}
753/* Barrier initial solve */
754COINLIBAPI int COINLINKAGE
755Clp_initialBarrierSolve(Clp_Simplex * model0)
756{
757     ClpSimplex *model = model0->model_;
758
759     return model->initialBarrierSolve();
760
761}
762/* Barrier initial solve */
763COINLIBAPI int COINLINKAGE
764Clp_initialBarrierNoCrossSolve(Clp_Simplex * model0)
765{
766     ClpSimplex *model = model0->model_;
767
768     return model->initialBarrierNoCrossSolve();
769
770}
771/* Dual initial solve */
772COINLIBAPI int COINLINKAGE
773Clp_initialDualSolve(Clp_Simplex * model)
774{
775     return model->model_->initialDualSolve();
776}
777/* Primal initial solve */
778COINLIBAPI int COINLINKAGE
779Clp_initialPrimalSolve(Clp_Simplex * model)
780{
781     return model->model_->initialPrimalSolve();
782}
783/* Dual algorithm - see ClpSimplexDual.hpp for method */
784COINLIBAPI int COINLINKAGE
785Clp_dual(Clp_Simplex * model, int ifValuesPass)
786{
787     return model->model_->dual(ifValuesPass);
788}
789/* Primal algorithm - see ClpSimplexPrimal.hpp for method */
790COINLIBAPI int COINLINKAGE
791Clp_primal(Clp_Simplex * model, int ifValuesPass)
792{
793     return model->model_->primal(ifValuesPass);
794}
795/* Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
796COINLIBAPI void COINLINKAGE
797Clp_scaling(Clp_Simplex * model, int mode)
798{
799     model->model_->scaling(mode);
800}
801/* Gets scalingFlag */
802COINLIBAPI int COINLINKAGE
803Clp_scalingFlag(Clp_Simplex * model)
804{
805     return model->model_->scalingFlag();
806}
807/* Crash - at present just aimed at dual, returns
808   -2 if dual preferred and crash basis created
809   -1 if dual preferred and all slack basis preferred
810   0 if basis going in was not all slack
811   1 if primal preferred and all slack basis preferred
812   2 if primal preferred and crash basis created.
813
814   if gap between bounds <="gap" variables can be flipped
815
816   If "pivot" is
817   0 No pivoting (so will just be choice of algorithm)
818   1 Simple pivoting e.g. gub
819   2 Mini iterations
820*/
821COINLIBAPI int COINLINKAGE
822Clp_crash(Clp_Simplex * model, double gap, int pivot)
823{
824     return model->model_->crash(gap, pivot);
825}
826/* If problem is primal feasible */
827COINLIBAPI int COINLINKAGE
828Clp_primalFeasible(Clp_Simplex * model)
829{
830     return model->model_->primalFeasible() ? 1 : 0;
831}
832/* If problem is dual feasible */
833COINLIBAPI int COINLINKAGE
834Clp_dualFeasible(Clp_Simplex * model)
835{
836     return model->model_->dualFeasible() ? 1 : 0;
837}
838/* Dual bound */
839COINLIBAPI double COINLINKAGE
840Clp_dualBound(Clp_Simplex * model)
841{
842     return model->model_->dualBound();
843}
844COINLIBAPI void COINLINKAGE
845Clp_setDualBound(Clp_Simplex * model, double value)
846{
847     model->model_->setDualBound(value);
848}
849/* Infeasibility cost */
850COINLIBAPI double COINLINKAGE
851Clp_infeasibilityCost(Clp_Simplex * model)
852{
853     return model->model_->infeasibilityCost();
854}
855COINLIBAPI void COINLINKAGE
856Clp_setInfeasibilityCost(Clp_Simplex * model, double value)
857{
858     model->model_->setInfeasibilityCost(value);
859}
860/* Perturbation:
861   50  - switch on perturbation
862   100 - auto perturb if takes too long (1.0e-6 largest nonzero)
863   101 - we are perturbed
864   102 - don't try perturbing again
865   default is 100
866   others are for playing
867*/
868COINLIBAPI int COINLINKAGE
869Clp_perturbation(Clp_Simplex * model)
870{
871     return model->model_->perturbation();
872}
873COINLIBAPI void COINLINKAGE
874Clp_setPerturbation(Clp_Simplex * model, int value)
875{
876     model->model_->setPerturbation(value);
877}
878/* Current (or last) algorithm */
879COINLIBAPI int COINLINKAGE
880Clp_algorithm(Clp_Simplex * model)
881{
882     return model->model_->algorithm();
883}
884/* Set algorithm */
885COINLIBAPI void COINLINKAGE
886Clp_setAlgorithm(Clp_Simplex * model, int value)
887{
888     model->model_->setAlgorithm(value);
889}
890/* Sum of dual infeasibilities */
891COINLIBAPI double COINLINKAGE
892Clp_sumDualInfeasibilities(Clp_Simplex * model)
893{
894     return model->model_->sumDualInfeasibilities();
895}
896/* Number of dual infeasibilities */
897COINLIBAPI int COINLINKAGE
898Clp_numberDualInfeasibilities(Clp_Simplex * model)
899{
900     return model->model_->numberDualInfeasibilities();
901}
902/* Sum of primal infeasibilities */
903COINLIBAPI double COINLINKAGE
904Clp_sumPrimalInfeasibilities(Clp_Simplex * model)
905{
906     return model->model_->sumPrimalInfeasibilities();
907}
908/* Number of primal infeasibilities */
909COINLIBAPI int COINLINKAGE
910Clp_numberPrimalInfeasibilities(Clp_Simplex * model)
911{
912     return model->model_->numberPrimalInfeasibilities();
913}
914/* Save model to file, returns 0 if success.  This is designed for
915   use outside algorithms so does not save iterating arrays etc.
916   It does not save any messaging information.
917   Does not save scaling values.
918   It does not know about all types of virtual functions.
919*/
920COINLIBAPI int COINLINKAGE
921Clp_saveModel(Clp_Simplex * model, const char * fileName)
922{
923     return model->model_->saveModel(fileName);
924}
925/* Restore model from file, returns 0 if success,
926   deletes current model */
927COINLIBAPI int COINLINKAGE
928Clp_restoreModel(Clp_Simplex * model, const char * fileName)
929{
930     return model->model_->restoreModel(fileName);
931}
932
933/* Just check solution (for external use) - sets sum of
934   infeasibilities etc */
935COINLIBAPI void COINLINKAGE
936Clp_checkSolution(Clp_Simplex * model)
937{
938     model->model_->checkSolution();
939}
940/* Number of rows */
941COINLIBAPI int COINLINKAGE
942Clp_getNumRows(Clp_Simplex * model)
943{
944     return model->model_->getNumRows();
945}
946/* Number of columns */
947COINLIBAPI int COINLINKAGE
948Clp_getNumCols(Clp_Simplex * model)
949{
950     return model->model_->getNumCols();
951}
952/* Number of iterations */
953COINLIBAPI int COINLINKAGE
954Clp_getIterationCount(Clp_Simplex * model)
955{
956     return model->model_->getIterationCount();
957}
958/* Are there a numerical difficulties? */
959COINLIBAPI int COINLINKAGE
960Clp_isAbandoned(Clp_Simplex * model)
961{
962     return model->model_->isAbandoned() ? 1 : 0;
963}
964/* Is optimality proven? */
965COINLIBAPI int COINLINKAGE
966Clp_isProvenOptimal(Clp_Simplex * model)
967{
968     return model->model_->isProvenOptimal() ? 1 : 0;
969}
970/* Is primal infeasiblity proven? */
971COINLIBAPI int COINLINKAGE
972Clp_isProvenPrimalInfeasible(Clp_Simplex * model)
973{
974     return model->model_->isProvenPrimalInfeasible() ? 1 : 0;
975}
976/* Is dual infeasiblity proven? */
977COINLIBAPI int COINLINKAGE
978Clp_isProvenDualInfeasible(Clp_Simplex * model)
979{
980     return model->model_->isProvenDualInfeasible() ? 1 : 0;
981}
982/* Is the given primal objective limit reached? */
983COINLIBAPI int COINLINKAGE
984Clp_isPrimalObjectiveLimitReached(Clp_Simplex * model)
985{
986     return model->model_->isPrimalObjectiveLimitReached() ? 1 : 0;
987}
988/* Is the given dual objective limit reached? */
989COINLIBAPI int COINLINKAGE
990Clp_isDualObjectiveLimitReached(Clp_Simplex * model)
991{
992     return model->model_->isDualObjectiveLimitReached() ? 1 : 0;
993}
994/* Iteration limit reached? */
995COINLIBAPI int COINLINKAGE
996Clp_isIterationLimitReached(Clp_Simplex * model)
997{
998     return model->model_->isIterationLimitReached() ? 1 : 0;
999}
1000/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
1001COINLIBAPI double COINLINKAGE
1002Clp_getObjSense(Clp_Simplex * model)
1003{
1004     return model->model_->getObjSense();
1005}
1006/* Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
1007COINLIBAPI void COINLINKAGE
1008Clp_setObjSense(Clp_Simplex * model, double objsen)
1009{
1010     model->model_->setOptimizationDirection(objsen);
1011}
1012/* Primal row solution */
1013COINLIBAPI const double * COINLINKAGE
1014Clp_getRowActivity(Clp_Simplex * model)
1015{
1016     return model->model_->getRowActivity();
1017}
1018/* Primal column solution */
1019COINLIBAPI const double * COINLINKAGE
1020Clp_getColSolution(Clp_Simplex * model)
1021{
1022     return model->model_->getColSolution();
1023}
1024COINLIBAPI void COINLINKAGE
1025Clp_setColSolution(Clp_Simplex * model, const double * input)
1026{
1027     model->model_->setColSolution(input);
1028}
1029/* Dual row solution */
1030COINLIBAPI const double * COINLINKAGE
1031Clp_getRowPrice(Clp_Simplex * model)
1032{
1033     return model->model_->getRowPrice();
1034}
1035/* Reduced costs */
1036COINLIBAPI const double * COINLINKAGE
1037Clp_getReducedCost(Clp_Simplex * model)
1038{
1039     return model->model_->getReducedCost();
1040}
1041/* Row lower */
1042COINLIBAPI const double* COINLINKAGE
1043Clp_getRowLower(Clp_Simplex * model)
1044{
1045     return model->model_->getRowLower();
1046}
1047/* Row upper  */
1048COINLIBAPI const double* COINLINKAGE
1049Clp_getRowUpper(Clp_Simplex * model)
1050{
1051     return model->model_->getRowUpper();
1052}
1053/* Objective */
1054COINLIBAPI const double * COINLINKAGE
1055Clp_getObjCoefficients(Clp_Simplex * model)
1056{
1057     return model->model_->getObjCoefficients();
1058}
1059/* Column Lower */
1060COINLIBAPI const double * COINLINKAGE
1061Clp_getColLower(Clp_Simplex * model)
1062{
1063     return model->model_->getColLower();
1064}
1065/* Column Upper */
1066COINLIBAPI const double * COINLINKAGE
1067Clp_getColUpper(Clp_Simplex * model)
1068{
1069     return model->model_->getColUpper();
1070}
1071/* Objective value */
1072COINLIBAPI double COINLINKAGE
1073Clp_getObjValue(Clp_Simplex * model)
1074{
1075     return model->model_->getObjValue();
1076}
1077/* Get variable basis info */
1078COINLIBAPI int COINLINKAGE
1079Clp_getColumnStatus(Clp_Simplex * model, int sequence)
1080{
1081     return (int) model->model_->getColumnStatus(sequence);
1082}
1083/* Get row basis info */
1084COINLIBAPI int COINLINKAGE
1085Clp_getRowStatus(Clp_Simplex * model, int sequence)
1086{
1087     return (int) model->model_->getRowStatus(sequence);
1088}
1089/* Set variable basis info */
1090COINLIBAPI void COINLINKAGE
1091Clp_setColumnStatus(Clp_Simplex * model, int sequence, int value)
1092{
1093     if (value >= 0 && value <= 5) {
1094          model->model_->setColumnStatus(sequence, (ClpSimplex::Status) value );
1095          if (value == 3 || value == 5)
1096               model->model_->primalColumnSolution()[sequence] =
1097                    model->model_->columnLower()[sequence];
1098          else if (value == 2)
1099               model->model_->primalColumnSolution()[sequence] =
1100                    model->model_->columnUpper()[sequence];
1101     }
1102}
1103/* Set row basis info */
1104COINLIBAPI void COINLINKAGE
1105Clp_setRowStatus(Clp_Simplex * model, int sequence, int value)
1106{
1107     if (value >= 0 && value <= 5) {
1108          model->model_->setRowStatus(sequence, (ClpSimplex::Status) value );
1109          if (value == 3 || value == 5)
1110               model->model_->primalRowSolution()[sequence] =
1111                    model->model_->rowLower()[sequence];
1112          else if (value == 2)
1113               model->model_->primalRowSolution()[sequence] =
1114                    model->model_->rowUpper()[sequence];
1115     }
1116}
1117/* Small element value - elements less than this set to zero,
1118   default is 1.0e-20 */
1119COINLIBAPI double COINLINKAGE
1120Clp_getSmallElementValue(Clp_Simplex * model)
1121{
1122     return model->model_->getSmallElementValue();
1123}
1124COINLIBAPI void COINLINKAGE
1125Clp_setSmallElementValue(Clp_Simplex * model, double value)
1126{
1127     model->model_->setSmallElementValue(value);
1128}
1129/* Print model */
1130COINLIBAPI void COINLINKAGE
1131Clp_printModel(Clp_Simplex * model, const char * prefix)
1132{
1133     ClpSimplex *clp_simplex = model->model_;
1134     int numrows    = clp_simplex->numberRows();
1135     int numcols    = clp_simplex->numberColumns();
1136     int numelem    = clp_simplex->getNumElements();
1137     const CoinBigIndex *start = clp_simplex->matrix()->getVectorStarts();
1138     const int *index     = clp_simplex->matrix()->getIndices();
1139     const double *value  = clp_simplex->matrix()->getElements();
1140     const double *collb  = model->model_->columnLower();
1141     const double *colub  = model->model_->columnUpper();
1142     const double *obj    = model->model_->objective();
1143     const double *rowlb  = model->model_->rowLower();
1144     const double *rowub  = model->model_->rowUpper();
1145     printf("%s numcols = %i, numrows = %i, numelem = %i\n",
1146            prefix, numcols, numrows, numelem);
1147     printf("%s model = %p, start = %p, index = %p, value = %p\n",
1148            prefix, reinterpret_cast<const void *>(model), reinterpret_cast<const void *>(start), reinterpret_cast<const void *>(index), reinterpret_cast<const void *>(value));
1149     clp_simplex->matrix()->dumpMatrix(NULL);
1150     {
1151          int i;
1152          for (i = 0; i <= numcols; i++)
1153               printf("%s start[%i] = %i\n", prefix, i, start[i]);
1154          for (i = 0; i < numelem; i++)
1155               printf("%s index[%i] = %i, value[%i] = %g\n",
1156                      prefix, i, index[i], i, value[i]);
1157     }
1158
1159     printf("%s collb = %p, colub = %p, obj = %p, rowlb = %p, rowub = %p\n",
1160            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));
1161     printf("%s optimization direction = %g\n", prefix, Clp_optimizationDirection(model));
1162     printf("  (1 - minimize, -1 - maximize, 0 - ignore)\n");
1163     {
1164          int i;
1165          for (i = 0; i < numcols; i++)
1166               printf("%s collb[%i] = %g, colub[%i] = %g, obj[%i] = %g\n",
1167                      prefix, i, collb[i], i, colub[i], i, obj[i]);
1168          for (i = 0; i < numrows; i++)
1169               printf("%s rowlb[%i] = %g, rowub[%i] = %g\n",
1170                      prefix, i, rowlb[i], i, rowub[i]);
1171     }
1172}
1173
1174#ifndef SLIM_CLP
1175/** Solve the problem with the idiot code */
1176/* tryhard values:
1177   tryhard & 7:
1178      0: NOT lightweight, 105 iterations within a pass (when mu stays fixed)
1179      1: lightweight, but focus more on optimality (mu is high)
1180         (23 iters in a pass)
1181      2: lightweight, but focus more on feasibility (11 iters in a pass)
1182      3: lightweight, but focus more on feasibility (23 iters in a pass, so it
1183         goes closer to opt than option 2)
1184   tryhard >> 3:
1185      number of passes, the larger the number the closer it gets to optimality
1186*/
1187COINLIBAPI void COINLINKAGE
1188Clp_idiot(Clp_Simplex * model, int tryhard)
1189{
1190     ClpSimplex *clp = model->model_;
1191     Idiot info(*clp);
1192     int numberpass = tryhard >> 3;
1193     int lightweight = tryhard & 7;
1194     info.setLightweight(lightweight);
1195     info.crash(numberpass, clp->messageHandler(), clp->messagesPointer(), false);
1196}
1197#endif
1198
1199#if defined(__MWERKS__)
1200#pragma export off
1201#endif
1202
Note: See TracBrowser for help on using the repository browser.