source: trunk/Clp/src/ClpModel.hpp @ 754

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

first version

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.6 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpModel_H
4#define ClpModel_H
5
6#include <iostream>
7#include <cassert>
8#include <cmath>
9#include <vector>
10#include <string>
11//#ifndef COIN_USE_CLP
12//#define COIN_USE_CLP
13//#endif
14#include "ClpMatrixBase.hpp"
15#include "CoinMessageHandler.hpp"
16#include "ClpParameters.hpp"
17#include "ClpObjective.hpp"
18class ClpEventHandler;
19
20// Plus infinity
21#ifndef COIN_DBL_MAX
22#define COIN_DBL_MAX DBL_MAX
23#endif
24
25/** This is the base class for Linear and quadratic Models
26    This knows nothing about the algorithm, but it seems to
27    have a reasonable amount of information
28
29    I would welcome suggestions for what should be in this and
30    how it relates to OsiSolverInterface.  Some methods look
31    very similar.
32
33*/
34class CoinBuild;
35class CoinModel;
36class ClpModel {
37
38public:
39
40  /**@name Constructors and destructor
41     Note - copy methods copy ALL data so can chew up memory
42     until other copy is freed
43   */
44  //@{
45    /// Default constructor
46    ClpModel (  );
47
48  /** Copy constructor. May scale depending on mode
49      -1 leave mode as is
50      0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later)
51  */
52    ClpModel(const ClpModel & rhs, int scalingMode=-1);
53    /// Assignment operator. This copies the data
54    ClpModel & operator=(const ClpModel & rhs);
55  /** Subproblem constructor.  A subset of whole model is created from the
56      row and column lists given.  The new order is given by list order and
57      duplicates are allowed.  Name and integer information can be dropped
58  */
59    ClpModel (const ClpModel * wholeModel,
60      int numberRows, const int * whichRows,
61      int numberColumns, const int * whichColumns,
62              bool dropNames=true, bool dropIntegers=true);
63    /// Destructor
64    ~ClpModel (  );
65  //@}
66
67  /**@name Load model - loads some stuff and initializes others */
68  //@{
69    /** Loads a problem (the constraints on the
70        rows are given by lower and upper bounds). If a pointer is 0 then the
71        following values are the default:
72        <ul>
73          <li> <code>colub</code>: all columns have upper bound infinity
74          <li> <code>collb</code>: all columns have lower bound 0
75          <li> <code>rowub</code>: all rows have upper bound infinity
76          <li> <code>rowlb</code>: all rows have lower bound -infinity
77          <li> <code>obj</code>: all variables have 0 objective coefficient
78        </ul>
79    */
80  void loadProblem (  const ClpMatrixBase& matrix,
81                     const double* collb, const double* colub,   
82                     const double* obj,
83                     const double* rowlb, const double* rowub,
84                      const double * rowObjective=NULL);
85  void loadProblem (  const CoinPackedMatrix& matrix,
86                     const double* collb, const double* colub,   
87                     const double* obj,
88                     const double* rowlb, const double* rowub,
89                      const double * rowObjective=NULL);
90
91  /** Just like the other loadProblem() method except that the matrix is
92        given in a standard column major ordered format (without gaps). */
93  void loadProblem (  const int numcols, const int numrows,
94                     const CoinBigIndex* start, const int* index,
95                     const double* value,
96                     const double* collb, const double* colub,   
97                     const double* obj,
98                      const double* rowlb, const double* rowub,
99                      const double * rowObjective=NULL);
100  /** This loads a model from a coinModel object - returns number of errors.
101
102      modelObject not const as may be changed as part of process
103      If tryPlusMinusOne then will try adding as +-1 matrix
104  */
105  int loadProblem (  CoinModel & modelObject,bool tryPlusMinusOne=false);
106  /// This one is for after presolve to save memory
107  void loadProblem (  const int numcols, const int numrows,
108                     const CoinBigIndex* start, const int* index,
109                      const double* value,const int * length,
110                     const double* collb, const double* colub,   
111                     const double* obj,
112                      const double* rowlb, const double* rowub,
113                      const double * rowObjective=NULL);
114  /** Load up quadratic objective.  This is stored as a CoinPackedMatrix */
115  void loadQuadraticObjective(const int numberColumns, 
116                              const CoinBigIndex * start,
117                              const int * column, const double * element);
118  void loadQuadraticObjective (  const CoinPackedMatrix& matrix);
119  /// Get rid of quadratic objective
120  void deleteQuadraticObjective();
121  /// This just loads up a row objective
122  void setRowObjective(const double * rowObjective);
123  /// Read an mps file from the given filename
124  int readMps(const char *filename,
125              bool keepNames=false,
126              bool ignoreErrors = false);
127  /// Read GMPL files from the given filenames
128  int readGMPL(const char *filename,const char * dataName,
129               bool keepNames=false);
130  /// Copy in integer informations
131  void copyInIntegerInformation(const char * information);
132  /// Drop integer informations
133  void deleteIntegerInformation();
134  /** Set the index-th variable to be a continuous variable */
135  void setContinuous(int index);
136  /** Set the index-th variable to be an integer variable */
137  void setInteger(int index);
138  /** Return true if the index-th variable is an integer variable */
139  bool isInteger(int index) const;
140  /// Resizes rim part of model
141  void resize (int newNumberRows, int newNumberColumns);
142  /// Deletes rows
143  void deleteRows(int number, const int * which);
144  /// Add one row
145  void addRow(int numberInRow, const int * columns,
146               const double * elements, double rowLower=-COIN_DBL_MAX, 
147              double rowUpper=COIN_DBL_MAX);
148  /// Add rows
149  void addRows(int number, const double * rowLower, 
150               const double * rowUpper,
151               const CoinBigIndex * rowStarts, const int * columns,
152               const double * elements);
153  /// Add rows
154  void addRows(int number, const double * rowLower, 
155               const double * rowUpper,
156               const CoinBigIndex * rowStarts, const int * rowLengths,
157               const int * columns,
158               const double * elements);
159#ifndef CLP_NO_VECTOR
160  void addRows(int number, const double * rowLower, 
161               const double * rowUpper,
162               const CoinPackedVectorBase * const * rows);
163#endif
164  /** Add rows from a build object.
165      If tryPlusMinusOne then will try adding as +-1 matrix
166      if no matrix exists.
167      Returns number of errors e.g. duplicates
168  */
169  int addRows(const CoinBuild & buildObject,bool tryPlusMinusOne=false,
170               bool checkDuplicates=true);
171  /** Add rows from a model object.  returns
172      -1 if object in bad state (i.e. has column information)
173      otherwise number of errors.
174
175      modelObject non const as can be regularized as part of build
176      If tryPlusMinusOne then will try adding as +-1 matrix
177      if no matrix exists.
178  */
179  int addRows(CoinModel & modelObject,bool tryPlusMinusOne=false,
180              bool checkDuplicates=true);
181
182  /// Deletes columns
183  void deleteColumns(int number, const int * which);
184  /// Add one column
185  void addColumn(int numberInColumn,
186                 const int * rows,
187                 const double * elements,
188                 double columnLower=0.0, 
189                 double  columnUpper=COIN_DBL_MAX,
190                 double  objective=0.0);
191  /// Add columns
192  void addColumns(int number, const double * columnLower, 
193                  const double * columnUpper,
194                  const double * objective,
195                  const CoinBigIndex * columnStarts, const int * rows,
196                  const double * elements);
197  void addColumns(int number, const double * columnLower, 
198                  const double * columnUpper,
199                  const double * objective,
200                  const CoinBigIndex * columnStarts, const int * columnLengths,
201                  const int * rows,
202                  const double * elements);
203#ifndef CLP_NO_VECTOR
204  void addColumns(int number, const double * columnLower, 
205               const double * columnUpper,
206                  const double * objective,
207               const CoinPackedVectorBase * const * columns);
208#endif
209  /** Add columns from a build object
210      If tryPlusMinusOne then will try adding as +-1 matrix
211      if no matrix exists.
212      Returns number of errors e.g. duplicates
213  */
214  int addColumns(const CoinBuild & buildObject,bool tryPlusMinusOne=false,
215                  bool checkDuplicates=true);
216  /** Add columns from a model object.  returns
217      -1 if object in bad state (i.e. has row information)
218      otherwise number of errors
219      modelObject non const as can be regularized as part of build
220      If tryPlusMinusOne then will try adding as +-1 matrix
221      if no matrix exists.
222  */
223  int addColumns(CoinModel & modelObject,bool tryPlusMinusOne=false,
224                 bool checkDuplicates=true);
225  /// Modify one element of a matrix
226  inline void modifyCoefficient(int row, int column, double newElement,
227                           bool keepZero=false)
228        {matrix_->modifyCoefficient(row,column,newElement,keepZero);}
229  /** Change row lower bounds */
230  void chgRowLower(const double * rowLower);
231  /** Change row upper bounds */
232  void chgRowUpper(const double * rowUpper);
233  /** Change column lower bounds */
234  void chgColumnLower(const double * columnLower);
235  /** Change column upper bounds */
236  void chgColumnUpper(const double * columnUpper);
237  /** Change objective coefficients */
238  void chgObjCoefficients(const double * objIn); 
239  /** Borrow model.  This is so we don't have to copy large amounts
240      of data around.  It assumes a derived class wants to overwrite
241      an empty model with a real one - while it does an algorithm */
242  void borrowModel(ClpModel & otherModel);
243  /** Return model - nulls all arrays so can be deleted safely
244      also updates any scalars */
245  void returnModel(ClpModel & otherModel);
246
247  /// Create empty ClpPackedMatrix
248  void createEmptyMatrix();
249#ifndef CLP_NO_STD
250  /// Drops names - makes lengthnames 0 and names empty
251  void dropNames();
252  /// Copies in names
253  void copyNames(std::vector<std::string> & rowNames,
254                 std::vector<std::string> & columnNames);
255  /// Copies in Row names - modifies names first .. last-1
256  void copyRowNames(const std::vector<std::string> & rowNames,int first, int last);
257  /// Copies in Column names - modifies names first .. last-1
258  void copyColumnNames(const std::vector<std::string> & columnNames, int first, int last);
259  /// Copies in Row names - modifies names first .. last-1
260  void copyRowNames(const char * const * rowNames,int first, int last);
261  /// Copies in Column names - modifies names first .. last-1
262  void copyColumnNames(const char * const * columnNames, int first, int last);
263  /// Set name of row
264  void setRowName(int rowIndex, std::string & name) ;
265  /// Set name of col
266  void setColumnName(int colIndex, std::string & name) ;
267#endif
268
269    /** Write the problem in MPS format to the specified file.
270
271        Row and column names may be null.
272        formatType is
273        <ul>
274          <li> 0 - normal
275          <li> 1 - extra accuracy
276          <li> 2 - IEEE hex (later)
277        </ul>
278
279        Returns non-zero on I/O error
280    */
281    int writeMps(const char *filename, 
282                  int formatType=0,int numberAcross=2,
283                 double objSense=0.0) const ;
284  //@}
285  /**@name gets and sets */
286  //@{
287   /// Number of rows
288   inline int numberRows() const {
289      return numberRows_;
290   }
291   inline int getNumRows() const {
292      return numberRows_;
293   }
294   /// Number of columns
295   inline int getNumCols() const {
296      return numberColumns_;
297   }
298   inline int numberColumns() const {
299      return numberColumns_;
300   }
301   /// Primal tolerance to use
302   inline double primalTolerance() const {
303      return dblParam_[ClpPrimalTolerance];
304   }
305   void setPrimalTolerance( double value) ;
306   /// Dual tolerance to use
307   inline double dualTolerance() const  { return dblParam_[ClpDualTolerance]; }
308   void setDualTolerance( double value) ;
309  /// Primal objective limit
310  inline double primalObjectiveLimit() const { return dblParam_[ClpPrimalObjectiveLimit];}
311  void setPrimalObjectiveLimit(double value);
312  /// Dual objective limit
313  inline double dualObjectiveLimit() const { return dblParam_[ClpDualObjectiveLimit];}
314  void setDualObjectiveLimit(double value);
315  /// Objective offset
316  inline double objectiveOffset() const { return dblParam_[ClpObjOffset];}
317  void setObjectiveOffset(double value);
318#ifndef CLP_NO_STD
319  inline std::string problemName() const { return strParam_[ClpProbName]; };
320#endif
321   /// Number of iterations
322   inline int numberIterations() const  { return numberIterations_; }
323   inline int getIterationCount() const { return numberIterations_; }
324  inline void setNumberIterations(int numberIterations)
325  { numberIterations_ = numberIterations;};
326  /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/
327  inline int solveType() const
328  { return solveType_;};
329  inline void setSolveType(int type)
330  { solveType_=type;};
331   /// Maximum number of iterations
332   inline int maximumIterations() const { return intParam_[ClpMaxNumIteration]; }
333   void setMaximumIterations(int value);
334  /// Maximum time in seconds (from when set called)
335   inline double maximumSeconds() const { return dblParam_[ClpMaxSeconds]; }
336   void setMaximumSeconds(double value);
337  /// Returns true if hit maximum iterations (or time)
338  bool hitMaximumIterations() const;
339   /** Status of problem:
340       -1 - unknown e.g. before solve or if postSolve says not optimal
341       0 - optimal
342       1 - primal infeasible
343       2 - dual infeasible
344       3 - stopped on iterations or time
345       4 - stopped due to errors
346       5 - stopped by event handler (virtual int ClpEventHandler::event())
347   */
348   inline int status() const            { return problemStatus_; }
349   inline int problemStatus() const            { return problemStatus_; }
350  /// Set problem status
351  inline void setProblemStatus(int problemStatus)
352  { problemStatus_ = problemStatus;};
353   /** Secondary status of problem - may get extended
354       0 - none
355       1 - primal infeasible because dual limit reached OR probably primal
356       infeasible but can't prove it (main status 4)
357       2 - scaled problem optimal - unscaled problem has primal infeasibilities
358       3 - scaled problem optimal - unscaled problem has dual infeasibilities
359       4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
360       5 - giving up in primal with flagged variables
361       6 - failed due to empty problem check
362       7 - postSolve says not optimal
363       100 up - translation of enum from ClpEventHandler
364   */
365   inline int secondaryStatus() const            { return secondaryStatus_; }
366  inline void setSecondaryStatus(int status)
367  { secondaryStatus_ = status;};
368   /// Are there a numerical difficulties?
369   inline bool isAbandoned() const             { return problemStatus_==4; }
370   /// Is optimality proven?
371   inline bool isProvenOptimal() const         { return problemStatus_==0; }
372   /// Is primal infeasiblity proven?
373   inline bool isProvenPrimalInfeasible() const { return problemStatus_==1; }
374   /// Is dual infeasiblity proven?
375   inline bool isProvenDualInfeasible() const  { return problemStatus_==2; }
376   /// Is the given primal objective limit reached?
377   bool isPrimalObjectiveLimitReached() const ;
378   /// Is the given dual objective limit reached?
379   bool isDualObjectiveLimitReached() const ;
380   /// Iteration limit reached?
381   inline bool isIterationLimitReached() const { return problemStatus_==3; }
382   /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
383   inline double optimizationDirection() const {
384      return  optimizationDirection_;
385   }
386   inline double getObjSense() const    { return optimizationDirection_; }
387   void setOptimizationDirection(double value);
388   /// Primal row solution
389   inline double * primalRowSolution() const    { return rowActivity_; }
390   inline const double * getRowActivity() const { return rowActivity_; }
391   /// Primal column solution
392   inline double * primalColumnSolution() const { return columnActivity_; }
393   inline const double * getColSolution() const { return columnActivity_; }
394   inline void setColSolution(const double * input)
395   { memcpy(columnActivity_,input,numberColumns_*sizeof(double));};
396   /// Dual row solution
397   inline double * dualRowSolution() const      { return dual_; }
398   inline const double * getRowPrice() const    { return dual_; }
399   /// Reduced costs
400   inline double * dualColumnSolution() const   { return reducedCost_; }
401   inline const double * getReducedCost() const { return reducedCost_; }
402   /// Row lower
403   inline double* rowLower() const              { return rowLower_; }
404   inline const double* getRowLower() const     { return rowLower_; }
405   /// Row upper
406   inline double* rowUpper() const              { return rowUpper_; }
407   inline const double* getRowUpper() const     { return rowUpper_; }
408    //-------------------------------------------------------------------------
409    /**@name Changing bounds on variables and constraints */
410    //@{
411       /** Set an objective function coefficient */
412       void setObjectiveCoefficient( int elementIndex, double elementValue );
413       /** Set an objective function coefficient */
414       inline void setObjCoeff( int elementIndex, double elementValue )
415       { setObjectiveCoefficient( elementIndex, elementValue);};
416
417      /** Set a single column lower bound<br>
418          Use -DBL_MAX for -infinity. */
419       void setColumnLower( int elementIndex, double elementValue );
420     
421      /** Set a single column upper bound<br>
422          Use DBL_MAX for infinity. */
423       void setColumnUpper( int elementIndex, double elementValue );
424
425      /** Set a single column lower and upper bound */
426      void setColumnBounds( int elementIndex,
427        double lower, double upper );
428
429      /** Set the bounds on a number of columns simultaneously<br>
430          The default implementation just invokes setColLower() and
431          setColUpper() over and over again.
432          @param indexFirst,indexLast pointers to the beginning and after the
433                 end of the array of the indices of the variables whose
434                 <em>either</em> bound changes
435          @param boundList the new lower/upper bound pairs for the variables
436      */
437      void setColumnSetBounds(const int* indexFirst,
438                                   const int* indexLast,
439                                   const double* boundList);
440     
441      /** Set a single column lower bound<br>
442          Use -DBL_MAX for -infinity. */
443       inline void setColLower( int elementIndex, double elementValue )
444       { setColumnLower(elementIndex, elementValue);};
445      /** Set a single column upper bound<br>
446          Use DBL_MAX for infinity. */
447       inline void setColUpper( int elementIndex, double elementValue )
448       { setColumnUpper(elementIndex, elementValue);};
449
450      /** Set a single column lower and upper bound */
451      inline void setColBounds( int elementIndex,
452        double lower, double upper )
453       { setColumnBounds(elementIndex, lower, upper);};
454
455      /** Set the bounds on a number of columns simultaneously<br>
456          @param indexFirst,indexLast pointers to the beginning and after the
457                 end of the array of the indices of the variables whose
458                 <em>either</em> bound changes
459          @param boundList the new lower/upper bound pairs for the variables
460      */
461      inline void setColSetBounds(const int* indexFirst,
462                                   const int* indexLast,
463                                   const double* boundList)
464      { setColumnSetBounds(indexFirst, indexLast, boundList);};
465     
466      /** Set a single row lower bound<br>
467          Use -DBL_MAX for -infinity. */
468      void setRowLower( int elementIndex, double elementValue );
469     
470      /** Set a single row upper bound<br>
471          Use DBL_MAX for infinity. */
472      void setRowUpper( int elementIndex, double elementValue ) ;
473   
474      /** Set a single row lower and upper bound */
475      void setRowBounds( int elementIndex,
476                                 double lower, double upper ) ;
477   
478      /** Set the bounds on a number of rows simultaneously<br>
479          @param indexFirst,indexLast pointers to the beginning and after the
480                 end of the array of the indices of the constraints whose
481                 <em>either</em> bound changes
482          @param boundList the new lower/upper bound pairs for the constraints
483      */
484      void setRowSetBounds(const int* indexFirst,
485                                   const int* indexLast,
486                                   const double* boundList);
487   
488    //@}
489   /// Scaling
490   inline const double * rowScale() const {return rowScale_;};
491   inline const double * columnScale() const {return columnScale_;};
492   inline void setRowScale(double * scale) { delete [] (double *) rowScale_; rowScale_ = scale;};
493   inline void setColumnScale(double * scale) { delete [] (double *) columnScale_; columnScale_ = scale;};
494  /// Scaling of objective
495  inline double objectiveScale() const 
496          { return objectiveScale_;} ;
497  inline void setObjectiveScale(double value)
498          { objectiveScale_ = value;} ;
499  /// Scaling of rhs and bounds
500  inline double rhsScale() const 
501          { return rhsScale_;} ;
502  inline void setRhsScale(double value)
503          { rhsScale_ = value;} ;
504   /// Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later)
505   void scaling(int mode=1);
506  /** If we constructed a "really" scaled model then this reverses the operation.
507      Quantities may not be exactly as they were before due to rounding errors */
508  void unscale();
509   /// Gets scalingFlag
510   inline int scalingFlag() const {return scalingFlag_;};
511   /// Objective
512   inline double * objective() const           
513  {
514    if (objective_) {
515      double offset; 
516      return objective_->gradient(NULL,NULL,offset,false);
517    } else {
518      return NULL;
519    }
520  }
521   inline double * objective(const double * solution, double & offset,bool refresh=true) const           
522  {
523    offset=0.0;
524    if (objective_) {
525      return objective_->gradient(NULL,solution,offset,refresh);
526    } else {
527      return NULL;
528    }
529  }
530   inline const double * getObjCoefficients() const 
531  { 
532    if (objective_) {
533      double offset; 
534      return objective_->gradient(NULL,NULL,offset,false);
535    } else {
536      return NULL;
537    }
538  }
539   /// Row Objective
540   inline double * rowObjective() const         { return rowObjective_; }
541   inline const double * getRowObjCoefficients() const {
542      return rowObjective_;
543   }
544   /// Column Lower
545   inline double * columnLower() const          { return columnLower_; }
546   inline const double * getColLower() const    { return columnLower_; }
547   /// Column Upper
548   inline double * columnUpper() const          { return columnUpper_; }
549   inline const double * getColUpper() const    { return columnUpper_; }
550   /// Matrix (if not ClpPackedmatrix be careful about memory leak
551   inline CoinPackedMatrix * matrix() const {
552     if ( matrix_ == NULL ) return NULL;
553     else return matrix_->getPackedMatrix();
554   }
555   /// Number of elements in matrix
556   inline int getNumElements() const 
557     { return matrix_->getNumElements();};
558   /** Small element value - elements less than this set to zero,
559      default is 1.0e-20 */
560   inline double getSmallElementValue() const
561  { return smallElement_;}; 
562  inline void setSmallElementValue(double value)
563  { smallElement_=value;}; 
564   /// Row Matrix
565   inline ClpMatrixBase * rowCopy() const       { return rowCopy_; }
566   /// Clp Matrix
567   inline ClpMatrixBase * clpMatrix() const     { return matrix_; }
568  /** Replace Clp Matrix (current is not deleted unless told to
569      and new is used)
570      So up to user to delete current.  This was used where
571      matrices were being rotated.
572  */
573   void replaceMatrix(ClpMatrixBase * matrix,bool deleteCurrent=false);
574   /// Objective value
575   inline double objectiveValue() const {
576      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
577   }
578  inline void setObjectiveValue(double value) {
579    objectiveValue_ = (value+ dblParam_[ClpObjOffset])/optimizationDirection_;
580   }
581   inline double getObjValue() const {
582      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
583   }
584   /// Integer information
585   inline char * integerInformation() const     { return integerType_; }
586   /** Infeasibility/unbounded ray (NULL returned if none/wrong)
587       Up to user to use delete [] on these arrays.  */
588   double * infeasibilityRay() const;
589   double * unboundedRay() const;
590  /// See if status (i.e. basis) array exists (partly for OsiClp)
591  inline bool statusExists() const
592  { return (status_!=NULL);};
593  /// Return address of status (i.e. basis) array (char[numberRows+numberColumns])
594  inline unsigned char *  statusArray() const
595  { return status_;};
596  /** Return copy of status (i.e. basis) array (char[numberRows+numberColumns]),
597      use delete [] */
598  unsigned char *  statusCopy() const;
599  /// Copy in status (basis) vector
600  void copyinStatus(const unsigned char * statusArray);
601
602  /// User pointer for whatever reason
603  inline void setUserPointer (void * pointer)
604  { userPointer_=pointer;};
605  inline void * getUserPointer () const
606  { return userPointer_;};
607  /// What has changed in model (only for masochistic users)
608  inline int whatsChanged() const 
609          { return whatsChanged_;} ;
610  inline void setWhatsChanged(int value)
611          { whatsChanged_ = value;} ;
612  /// Number of threads (not really being used)
613  inline int numberThreads() const 
614          { return numberThreads_;} ;
615  inline void setNumberThreads(int value)
616          { numberThreads_ = value;} ;
617  //@}
618  /**@name Message handling */
619  //@{
620   /// Pass in Message handler (not deleted at end)
621   void passInMessageHandler(CoinMessageHandler * handler);
622  /// Pass in Message handler (not deleted at end) and return current
623  CoinMessageHandler * pushMessageHandler(CoinMessageHandler * handler,
624                                          bool & oldDefault);
625  /// back to previous message handler
626  void popMessageHandler(CoinMessageHandler * oldHandler,bool oldDefault);
627   /// Set language
628   void newLanguage(CoinMessages::Language language);
629   inline void setLanguage(CoinMessages::Language language) { newLanguage(language); }
630   /// Return handler
631   inline CoinMessageHandler * messageHandler() const       { return handler_; }
632   /// Return messages
633   inline CoinMessages messages() const                     { return messages_; }
634   /// Return pointer to messages
635   inline CoinMessages * messagesPointer()                  { return & messages_; }
636   /// Return Coin messages
637   inline CoinMessages coinMessages() const                  { return coinMessages_; }
638   /// Return pointer to Coin messages
639   inline CoinMessages * coinMessagesPointer()                  { return & coinMessages_; }
640  /** Amount of print out:
641      0 - none
642      1 - just final
643      2 - just factorizations
644      3 - as 2 plus a bit more
645      4 - verbose
646      above that 8,16,32 etc just for selective debug
647  */
648   inline void setLogLevel(int value)    { handler_->setLogLevel(value); }
649   inline int logLevel() const           { return handler_->logLevel(); }
650   /// Pass in Event handler (cloned and deleted at end)
651   void passInEventHandler(const ClpEventHandler * eventHandler);
652   /// Event handler
653   inline ClpEventHandler * eventHandler() const
654  { return eventHandler_;};
655   /// length of names (0 means no names0
656   inline int lengthNames() const { return lengthNames_; }
657#ifndef CLP_NO_STD
658   /// length of names (0 means no names0
659   inline void setLengthNames(int value) { lengthNames_=value; }
660   /// Row names
661   inline const std::vector<std::string> * rowNames() const {
662      return &rowNames_;
663   }
664   inline const std::string& rowName(int iRow) const {
665      return rowNames_[iRow];
666   }
667   /// Return name or Rnnnnnnn
668   std::string getRowName(int iRow) const;
669   /// Column names
670   inline const std::vector<std::string> * columnNames() const {
671      return &columnNames_;
672   }
673   inline const std::string& columnName(int iColumn) const {
674      return columnNames_[iColumn];
675   }
676   /// Return name or Cnnnnnnn
677   std::string getColumnName(int iColumn) const;
678#endif
679  /// Objective methods
680  inline ClpObjective * objectiveAsObject() const
681  { return objective_;};
682  void setObjective(ClpObjective * objective);
683  inline void setObjectivePointer(ClpObjective * objective)
684  { objective_ = objective;};
685  /** Solve a problem with no elements - return status and
686      dual and primal infeasibilites */
687  int emptyProblem(int * infeasNumber=NULL, double * infeasSum=NULL,bool printMessage=true);
688 
689  //@}
690
691  /**@name Matrix times vector methods
692     They can be faster if scalar is +- 1
693     These are covers so user need not worry about scaling
694     Also for simplex I am not using basic/non-basic split */
695  //@{
696    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
697        @pre <code>x</code> must be of size <code>numColumns()</code>
698        @pre <code>y</code> must be of size <code>numRows()</code> */
699   void times(double scalar,
700                       const double * x, double * y) const;
701    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
702        @pre <code>x</code> must be of size <code>numRows()</code>
703        @pre <code>y</code> must be of size <code>numColumns()</code> */
704    void transposeTimes(double scalar,
705                                const double * x, double * y) const ;
706  //@}
707
708
709  //---------------------------------------------------------------------------
710  /**@name Parameter set/get methods
711
712     The set methods return true if the parameter was set to the given value,
713     false otherwise. There can be various reasons for failure: the given
714     parameter is not applicable for the solver (e.g., refactorization
715     frequency for the volume algorithm), the parameter is not yet implemented
716     for the solver or simply the value of the parameter is out of the range
717     the solver accepts. If a parameter setting call returns false check the
718     details of your solver.
719
720     The get methods return true if the given parameter is applicable for the
721     solver and is implemented. In this case the value of the parameter is
722     returned in the second argument. Otherwise they return false.
723
724     ** once it has been decided where solver sits this may be redone
725  */
726  //@{
727    /// Set an integer parameter
728    bool setIntParam(ClpIntParam key, int value) ;
729    /// Set an double parameter
730    bool setDblParam(ClpDblParam key, double value) ;
731#ifndef CLP_NO_STD
732    /// Set an string parameter
733    bool setStrParam(ClpStrParam key, const std::string & value);
734#endif
735    // Get an integer parameter
736    inline bool getIntParam(ClpIntParam key, int& value) const {
737      if (key!=ClpLastIntParam) {
738        value = intParam_[key];
739        return true;
740      } else {
741        return false;
742      }
743    }
744    // Get an double parameter
745    inline bool getDblParam(ClpDblParam key, double& value) const {
746      if (key!=ClpLastDblParam) {
747        value = dblParam_[key];
748        return true;
749      } else {
750        return false;
751      }
752    }
753#ifndef CLP_NO_STD
754    // Get a string parameter
755    inline bool getStrParam(ClpStrParam key, std::string& value) const {
756      if (key!=ClpLastStrParam) {
757        value = strParam_[key];
758        return true;
759      } else {
760        return false;
761      }
762    }
763#endif
764  //@}
765
766  /**@name private or protected methods */
767  //@{
768protected:
769  /// Does most of deletion
770  void gutsOfDelete();
771  /** Does most of copying
772      If trueCopy false then just points to arrays */
773  void gutsOfCopy(const ClpModel & rhs, bool trueCopy=true);
774  /// gets lower and upper bounds on rows
775  void getRowBound(int iRow, double& lower, double& upper) const;
776  /// puts in format I like - 4 array matrix - may make row copy
777  void gutsOfLoadModel ( int numberRows, int numberColumns,
778                     const double* collb, const double* colub,   
779                     const double* obj,
780                     const double* rowlb, const double* rowub,
781                      const double * rowObjective=NULL);
782  /// Does much of scaling
783  void gutsOfScaling();
784   /// Objective value - always minimize
785   inline double rawObjectiveValue() const {
786      return objectiveValue_;
787   }
788  /// Create row names as char **
789  const char * const * const rowNamesAsChar() const;
790  /// Create column names as char **
791  const char * const * const columnNamesAsChar() const;
792  /// Delete char * version of names
793  void deleteNamesAsChar(const char * const * const names,int number) const;
794  //@}
795
796
797////////////////// data //////////////////
798protected:
799
800  /**@name data */
801  //@{
802  /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
803  double optimizationDirection_;
804  /// Array of double parameters
805  double dblParam_[ClpLastDblParam];
806  /// Objective value
807  double objectiveValue_;
808  /// Small element value
809  double smallElement_;
810  /// Scaling of objective
811  double objectiveScale_;
812  /// Scaling of rhs and bounds
813  double rhsScale_;
814  /// Number of rows
815  int numberRows_;
816  /// Number of columns
817  int numberColumns_;
818  /// Row activities
819  double * rowActivity_;
820  /// Column activities
821  double * columnActivity_;
822  /// Duals
823  double * dual_;
824  /// Reduced costs
825  double * reducedCost_;
826  /// Row lower
827  double* rowLower_;
828  /// Row upper
829  double* rowUpper_;
830  /// Objective
831  ClpObjective * objective_;
832  /// Row Objective (? sign)  - may be NULL
833  double * rowObjective_;
834  /// Column Lower
835  double * columnLower_;
836  /// Column Upper
837  double * columnUpper_;
838  /// Packed matrix
839  ClpMatrixBase * matrix_;
840  /// Row copy if wanted
841  ClpMatrixBase * rowCopy_;
842  /// Infeasible/unbounded ray
843  double * ray_;
844  /// Row scale factors for matrix
845  double * rowScale_;
846  /// Column scale factors
847  double * columnScale_;
848  /// Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic
849  int scalingFlag_;
850  /** Status (i.e. basis) Region.  I know that not all algorithms need a status
851      array, but it made sense for things like crossover and put
852      all permanent stuff in one place.  No assumption is made
853      about what is in status array (although it might be good to reserve
854      bottom 3 bits (i.e. 0-7 numeric) for classic status).  This
855      is number of columns + number of rows long (in that order).
856  */
857  unsigned char * status_;
858  /// Integer information
859  char * integerType_;
860  /// User pointer for whatever reason
861  void * userPointer_;
862  /// Array of integer parameters
863  int intParam_[ClpLastIntParam];
864  /// Number of iterations
865  int numberIterations_;
866  /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/
867  int solveType_;
868  /** Whats changed since last solve.  This is a work in progress
869      It is designed so careful people can make go faster.
870      It is only used when startFinishOptions used in dual or primal.
871      Bit 1 - number of rows/columns has not changed (so work arrays valid)
872          2 - matrix has not changed
873          4 - if matrix has changed only by adding rows
874          8 - if matrix has changed only by adding columns
875         16 - row lbs not changed
876         32 - row ubs not changed
877         64 - column objective not changed
878        128 - column lbs not changed
879        256 - column ubs not changed
880        512 - basis not changed (up to user to set this to 0)
881              top bits may be used internally
882  */
883  unsigned int whatsChanged_;
884  /// Status of problem
885  int problemStatus_;
886  /// Secondary status of problem
887  int secondaryStatus_;
888  /// length of names (0 means no names)
889  int lengthNames_;
890  /// Number of threads (not very operational)
891  int numberThreads_;
892  /// Message handler
893  CoinMessageHandler * handler_;
894  /// Flag to say if default handler (so delete)
895  bool defaultHandler_;
896  /// Event handler
897  ClpEventHandler * eventHandler_;
898#ifndef CLP_NO_STD
899  /// Row names
900  std::vector<std::string> rowNames_;
901  /// Column names
902  std::vector<std::string> columnNames_;
903#endif
904  /// Messages
905  CoinMessages messages_;
906  /// Coin messages
907  CoinMessages coinMessages_;
908#ifndef CLP_NO_STD
909  /// Array of string parameters
910  std::string strParam_[ClpLastStrParam];
911#endif
912  //@}
913};
914/** This is a tiny class where data can be saved round calls.
915 */
916class ClpDataSave {
917
918public:
919  /**@name Constructors and destructor
920   */
921  //@{
922    /// Default constructor
923    ClpDataSave (  );
924
925    /// Copy constructor.
926    ClpDataSave(const ClpDataSave &);
927    /// Assignment operator. This copies the data
928    ClpDataSave & operator=(const ClpDataSave & rhs);
929    /// Destructor
930    ~ClpDataSave (  );
931
932  //@}
933
934////////////////// data //////////////////
935public:
936
937  /**@name data - with same names as in other classes*/
938  //@{
939  double dualBound_;
940  double infeasibilityCost_;
941  double pivotTolerance_;
942  double acceptablePivot_;
943  double objectiveScale_;
944  int sparseThreshold_;
945  int perturbation_;
946  int forceFactorization_;
947  int scalingFlag_;
948  //@}
949};
950
951#endif
Note: See TracBrowser for help on using the repository browser.