source: branches/devel/Clp/src/ClpModel.hpp @ 989

Last change on this file since 989 was 989, checked in by forrest, 13 years ago

this may be a mistake

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