source: branches/BSP/trunk/Clp/src/ClpModel.hpp @ 1069

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

for secondary status on time

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.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 "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  /** Really clean up matrix (if ClpPackedMatrix).
252      a) eliminate all duplicate AND small elements in matrix
253      b) remove all gaps and set extraGap_ and extraMajor_ to 0.0
254      c) reallocate arrays and make max lengths equal to lengths
255      d) orders elements
256      returns number of elements eliminated or -1 if not ClpPackedMatrix
257  */
258  int cleanMatrix(double threshold=1.0e-20);
259#ifndef CLP_NO_STD
260  /// Drops names - makes lengthnames 0 and names empty
261  void dropNames();
262  /// Copies in names
263  void copyNames(std::vector<std::string> & rowNames,
264                 std::vector<std::string> & columnNames);
265  /// Copies in Row names - modifies names first .. last-1
266  void copyRowNames(const std::vector<std::string> & rowNames,int first, int last);
267  /// Copies in Column names - modifies names first .. last-1
268  void copyColumnNames(const std::vector<std::string> & columnNames, int first, int last);
269  /// Copies in Row names - modifies names first .. last-1
270  void copyRowNames(const char * const * rowNames,int first, int last);
271  /// Copies in Column names - modifies names first .. last-1
272  void copyColumnNames(const char * const * columnNames, int first, int last);
273  /// Set name of row
274  void setRowName(int rowIndex, std::string & name) ;
275  /// Set name of col
276  void setColumnName(int colIndex, std::string & name) ;
277#endif
278  /** This creates a coinModel object
279  */
280  CoinModel * createCoinModel() const;
281
282    /** Write the problem in MPS format to the specified file.
283
284        Row and column names may be null.
285        formatType is
286        <ul>
287          <li> 0 - normal
288          <li> 1 - extra accuracy
289          <li> 2 - IEEE hex (later)
290        </ul>
291
292        Returns non-zero on I/O error
293    */
294    int writeMps(const char *filename, 
295                  int formatType=0,int numberAcross=2,
296                 double objSense=0.0) const ;
297  //@}
298  /**@name gets and sets */
299  //@{
300   /// Number of rows
301   inline int numberRows() const {
302      return numberRows_;
303   }
304   inline int getNumRows() const {
305      return numberRows_;
306   }
307   /// Number of columns
308   inline int getNumCols() const {
309      return numberColumns_;
310   }
311   inline int numberColumns() const {
312      return numberColumns_;
313   }
314   /// Primal tolerance to use
315   inline double primalTolerance() const {
316      return dblParam_[ClpPrimalTolerance];
317   }
318   void setPrimalTolerance( double value) ;
319   /// Dual tolerance to use
320   inline double dualTolerance() const  { return dblParam_[ClpDualTolerance]; }
321   void setDualTolerance( double value) ;
322  /// Primal objective limit
323  inline double primalObjectiveLimit() const { return dblParam_[ClpPrimalObjectiveLimit];}
324  void setPrimalObjectiveLimit(double value);
325  /// Dual objective limit
326  inline double dualObjectiveLimit() const { return dblParam_[ClpDualObjectiveLimit];}
327  void setDualObjectiveLimit(double value);
328  /// Objective offset
329  inline double objectiveOffset() const { return dblParam_[ClpObjOffset];}
330  void setObjectiveOffset(double value);
331#ifndef CLP_NO_STD
332  inline std::string problemName() const { return strParam_[ClpProbName]; }
333#endif
334   /// Number of iterations
335   inline int numberIterations() const  { return numberIterations_; }
336   inline int getIterationCount() const { return numberIterations_; }
337  inline void setNumberIterations(int numberIterations)
338  { numberIterations_ = numberIterations;}
339  /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/
340  inline int solveType() const
341  { return solveType_;}
342  inline void setSolveType(int type)
343  { solveType_=type;}
344   /// Maximum number of iterations
345   inline int maximumIterations() const { return intParam_[ClpMaxNumIteration]; }
346   void setMaximumIterations(int value);
347  /// Maximum time in seconds (from when set called)
348   inline double maximumSeconds() const { return dblParam_[ClpMaxSeconds]; }
349   void setMaximumSeconds(double value);
350  /// Returns true if hit maximum iterations (or time)
351  bool hitMaximumIterations() const;
352   /** Status of problem:
353       -1 - unknown e.g. before solve or if postSolve says not optimal
354       0 - optimal
355       1 - primal infeasible
356       2 - dual infeasible
357       3 - stopped on iterations or time
358       4 - stopped due to errors
359       5 - stopped by event handler (virtual int ClpEventHandler::event())
360   */
361   inline int status() const            { return problemStatus_; }
362   inline int problemStatus() const            { return problemStatus_; }
363  /// Set problem status
364  inline void setProblemStatus(int problemStatus)
365  { problemStatus_ = problemStatus;}
366   /** Secondary status of problem - may get extended
367       0 - none
368       1 - primal infeasible because dual limit reached OR probably primal
369       infeasible but can't prove it (main status 4)
370       2 - scaled problem optimal - unscaled problem has primal infeasibilities
371       3 - scaled problem optimal - unscaled problem has dual infeasibilities
372       4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
373       5 - giving up in primal with flagged variables
374       6 - failed due to empty problem check
375       7 - postSolve says not optimal
376       8 - failed due to bad element check
377       9 - status was 3 and stopped on time
378       100 up - translation of enum from ClpEventHandler
379   */
380   inline int secondaryStatus() const            { return secondaryStatus_; }
381  inline void setSecondaryStatus(int status)
382  { secondaryStatus_ = status;}
383   /// Are there a numerical difficulties?
384   inline bool isAbandoned() const             { return problemStatus_==4; }
385   /// Is optimality proven?
386   inline bool isProvenOptimal() const         { return problemStatus_==0; }
387   /// Is primal infeasiblity proven?
388   inline bool isProvenPrimalInfeasible() const { return problemStatus_==1; }
389   /// Is dual infeasiblity proven?
390   inline bool isProvenDualInfeasible() const  { return problemStatus_==2; }
391   /// Is the given primal objective limit reached?
392   bool isPrimalObjectiveLimitReached() const ;
393   /// Is the given dual objective limit reached?
394   bool isDualObjectiveLimitReached() const ;
395   /// Iteration limit reached?
396   inline bool isIterationLimitReached() const { return problemStatus_==3; }
397   /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
398   inline double optimizationDirection() const {
399      return  optimizationDirection_;
400   }
401   inline double getObjSense() const    { return optimizationDirection_; }
402   void setOptimizationDirection(double value);
403   /// Primal row solution
404   inline double * primalRowSolution() const    { return rowActivity_; }
405   inline const double * getRowActivity() const { return rowActivity_; }
406   /// Primal column solution
407   inline double * primalColumnSolution() const { return columnActivity_; }
408   inline const double * getColSolution() const { return columnActivity_; }
409   inline void setColSolution(const double * input)
410   { memcpy(columnActivity_,input,numberColumns_*sizeof(double));}
411   /// Dual row solution
412   inline double * dualRowSolution() const      { return dual_; }
413   inline const double * getRowPrice() const    { return dual_; }
414   /// Reduced costs
415   inline double * dualColumnSolution() const   { return reducedCost_; }
416   inline const double * getReducedCost() const { return reducedCost_; }
417   /// Row lower
418   inline double* rowLower() const              { return rowLower_; }
419   inline const double* getRowLower() const     { return rowLower_; }
420   /// Row upper
421   inline double* rowUpper() const              { return rowUpper_; }
422   inline const double* getRowUpper() const     { return rowUpper_; }
423    //-------------------------------------------------------------------------
424    /**@name Changing bounds on variables and constraints */
425    //@{
426       /** Set an objective function coefficient */
427       void setObjectiveCoefficient( int elementIndex, double elementValue );
428       /** Set an objective function coefficient */
429       inline void setObjCoeff( int elementIndex, double elementValue )
430       { setObjectiveCoefficient( elementIndex, elementValue);}
431
432      /** Set a single column lower bound<br>
433          Use -DBL_MAX for -infinity. */
434       void setColumnLower( int elementIndex, double elementValue );
435     
436      /** Set a single column upper bound<br>
437          Use DBL_MAX for infinity. */
438       void setColumnUpper( int elementIndex, double elementValue );
439
440      /** Set a single column lower and upper bound */
441      void setColumnBounds( int elementIndex,
442        double lower, double upper );
443
444      /** Set the bounds on a number of columns simultaneously<br>
445          The default implementation just invokes setColLower() and
446          setColUpper() over and over again.
447          @param indexFirst,indexLast pointers to the beginning and after the
448                 end of the array of the indices of the variables whose
449                 <em>either</em> bound changes
450          @param boundList the new lower/upper bound pairs for the variables
451      */
452      void setColumnSetBounds(const int* indexFirst,
453                                   const int* indexLast,
454                                   const double* boundList);
455     
456      /** Set a single column lower bound<br>
457          Use -DBL_MAX for -infinity. */
458       inline void setColLower( int elementIndex, double elementValue )
459       { setColumnLower(elementIndex, elementValue);}
460      /** Set a single column upper bound<br>
461          Use DBL_MAX for infinity. */
462       inline void setColUpper( int elementIndex, double elementValue )
463       { setColumnUpper(elementIndex, elementValue);}
464
465      /** Set a single column lower and upper bound */
466      inline void setColBounds( int elementIndex,
467        double lower, double upper )
468       { setColumnBounds(elementIndex, lower, upper);}
469
470      /** Set the bounds on a number of columns simultaneously<br>
471          @param indexFirst,indexLast pointers to the beginning and after the
472                 end of the array of the indices of the variables whose
473                 <em>either</em> bound changes
474          @param boundList the new lower/upper bound pairs for the variables
475      */
476      inline void setColSetBounds(const int* indexFirst,
477                                   const int* indexLast,
478                                   const double* boundList)
479      { setColumnSetBounds(indexFirst, indexLast, boundList);}
480     
481      /** Set a single row lower bound<br>
482          Use -DBL_MAX for -infinity. */
483      void setRowLower( int elementIndex, double elementValue );
484     
485      /** Set a single row upper bound<br>
486          Use DBL_MAX for infinity. */
487      void setRowUpper( int elementIndex, double elementValue ) ;
488   
489      /** Set a single row lower and upper bound */
490      void setRowBounds( int elementIndex,
491                                 double lower, double upper ) ;
492   
493      /** Set the bounds on a number of rows simultaneously<br>
494          @param indexFirst,indexLast pointers to the beginning and after the
495                 end of the array of the indices of the constraints whose
496                 <em>either</em> bound changes
497          @param boundList the new lower/upper bound pairs for the constraints
498      */
499      void setRowSetBounds(const int* indexFirst,
500                                   const int* indexLast,
501                                   const double* boundList);
502   
503    //@}
504   /// Scaling
505   inline const double * rowScale() const {return rowScale_;}
506   inline const double * columnScale() const {return columnScale_;}
507   inline void setRowScale(double * scale) { delete [] (double *) rowScale_; rowScale_ = scale;}
508   inline void setColumnScale(double * scale) { delete [] (double *) columnScale_; columnScale_ = scale;}
509  /// Scaling of objective
510  inline double objectiveScale() const 
511          { return objectiveScale_;} 
512  inline void setObjectiveScale(double value)
513          { objectiveScale_ = value;} 
514  /// Scaling of rhs and bounds
515  inline double rhsScale() const 
516          { return rhsScale_;} 
517  inline void setRhsScale(double value)
518          { rhsScale_ = value;} 
519   /// Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later)
520   void scaling(int mode=1);
521  /** If we constructed a "really" scaled model then this reverses the operation.
522      Quantities may not be exactly as they were before due to rounding errors */
523  void unscale();
524   /// Gets scalingFlag
525   inline int scalingFlag() const {return scalingFlag_;}
526   /// Objective
527   inline double * objective() const           
528  {
529    if (objective_) {
530      double offset; 
531      return objective_->gradient(NULL,NULL,offset,false);
532    } else {
533      return NULL;
534    }
535  }
536   inline double * objective(const double * solution, double & offset,bool refresh=true) const           
537  {
538    offset=0.0;
539    if (objective_) {
540      return objective_->gradient(NULL,solution,offset,refresh);
541    } else {
542      return NULL;
543    }
544  }
545   inline const double * getObjCoefficients() const 
546  { 
547    if (objective_) {
548      double offset; 
549      return objective_->gradient(NULL,NULL,offset,false);
550    } else {
551      return NULL;
552    }
553  }
554   /// Row Objective
555   inline double * rowObjective() const         { return rowObjective_; }
556   inline const double * getRowObjCoefficients() const {
557      return rowObjective_;
558   }
559   /// Column Lower
560   inline double * columnLower() const          { return columnLower_; }
561   inline const double * getColLower() const    { return columnLower_; }
562   /// Column Upper
563   inline double * columnUpper() const          { return columnUpper_; }
564   inline const double * getColUpper() const    { return columnUpper_; }
565   /// Matrix (if not ClpPackedmatrix be careful about memory leak
566   inline CoinPackedMatrix * matrix() const {
567     if ( matrix_ == NULL ) return NULL;
568     else return matrix_->getPackedMatrix();
569   }
570   /// Number of elements in matrix
571   inline int getNumElements() const 
572     { return matrix_->getNumElements();}
573   /** Small element value - elements less than this set to zero,
574      default is 1.0e-20 */
575   inline double getSmallElementValue() const
576  { return smallElement_;}
577  inline void setSmallElementValue(double value)
578  { smallElement_=value;} 
579   /// Row Matrix
580   inline ClpMatrixBase * rowCopy() const       { return rowCopy_; }
581   /// Clp Matrix
582   inline ClpMatrixBase * clpMatrix() const     { return matrix_; }
583  /** Replace Clp Matrix (current is not deleted unless told to
584      and new is used)
585      So up to user to delete current.  This was used where
586      matrices were being rotated. ClpModel takes ownership.
587  */
588   void replaceMatrix(ClpMatrixBase * matrix,bool deleteCurrent=false);
589  /** Replace Clp Matrix (current is not deleted unless told to
590      and new is used) So up to user to delete current.  This was used where
591      matrices were being rotated.  This version changes CoinPackedMatrix
592      to ClpPackedMatrix.  ClpModel takes ownership.
593  */
594   inline void replaceMatrix(CoinPackedMatrix * matrix,
595                             bool deleteCurrent=false)
596  { replaceMatrix(new ClpPackedMatrix(matrix),deleteCurrent);}
597   /// Objective value
598   inline double objectiveValue() const {
599      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
600   }
601  inline void setObjectiveValue(double value) {
602    objectiveValue_ = (value+ dblParam_[ClpObjOffset])/optimizationDirection_;
603   }
604   inline double getObjValue() const {
605      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
606   }
607   /// Integer information
608   inline char * integerInformation() const     { return integerType_; }
609   /** Infeasibility/unbounded ray (NULL returned if none/wrong)
610       Up to user to use delete [] on these arrays.  */
611   double * infeasibilityRay() const;
612   double * unboundedRay() const;
613  /// See if status (i.e. basis) array exists (partly for OsiClp)
614  inline bool statusExists() const
615  { return (status_!=NULL);}
616  /// Return address of status (i.e. basis) array (char[numberRows+numberColumns])
617  inline unsigned char *  statusArray() const
618  { return status_;}
619  /** Return copy of status (i.e. basis) array (char[numberRows+numberColumns]),
620      use delete [] */
621  unsigned char *  statusCopy() const;
622  /// Copy in status (basis) vector
623  void copyinStatus(const unsigned char * statusArray);
624
625  /// User pointer for whatever reason
626  inline void setUserPointer (void * pointer)
627  { userPointer_=pointer;}
628  inline void * getUserPointer () const
629  { return userPointer_;}
630  /// What has changed in model (only for masochistic users)
631  inline int whatsChanged() const 
632          { return whatsChanged_;} 
633  inline void setWhatsChanged(int value)
634          { whatsChanged_ = value;} 
635  /// Number of threads (not really being used)
636  inline int numberThreads() const 
637          { return numberThreads_;} 
638  inline void setNumberThreads(int value)
639          { numberThreads_ = value;} 
640  //@}
641  /**@name Message handling */
642  //@{
643   /// Pass in Message handler (not deleted at end)
644   void passInMessageHandler(CoinMessageHandler * handler);
645  /// Pass in Message handler (not deleted at end) and return current
646  CoinMessageHandler * pushMessageHandler(CoinMessageHandler * handler,
647                                          bool & oldDefault);
648  /// back to previous message handler
649  void popMessageHandler(CoinMessageHandler * oldHandler,bool oldDefault);
650   /// Set language
651   void newLanguage(CoinMessages::Language language);
652   inline void setLanguage(CoinMessages::Language language) { newLanguage(language); }
653   /// Return handler
654   inline CoinMessageHandler * messageHandler() const       { return handler_; }
655   /// Return messages
656   inline CoinMessages messages() const                     { return messages_; }
657   /// Return pointer to messages
658   inline CoinMessages * messagesPointer()                  { return & messages_; }
659   /// Return Coin messages
660   inline CoinMessages coinMessages() const                  { return coinMessages_; }
661   /// Return pointer to Coin messages
662   inline CoinMessages * coinMessagesPointer()                  { return & coinMessages_; }
663  /** Amount of print out:
664      0 - none
665      1 - just final
666      2 - just factorizations
667      3 - as 2 plus a bit more
668      4 - verbose
669      above that 8,16,32 etc just for selective debug
670  */
671   inline void setLogLevel(int value)    { handler_->setLogLevel(value); }
672   inline int logLevel() const           { return handler_->logLevel(); }
673   /// Return true if default handler
674   inline bool defaultHandler() const
675   { return defaultHandler_;}
676   /// Pass in Event handler (cloned and deleted at end)
677   void passInEventHandler(const ClpEventHandler * eventHandler);
678   /// Event handler
679   inline ClpEventHandler * eventHandler() const
680  { return eventHandler_;}
681   /// length of names (0 means no names0
682   inline int lengthNames() const { return lengthNames_; }
683#ifndef CLP_NO_STD
684   /// length of names (0 means no names0
685   inline void setLengthNames(int value) { lengthNames_=value; }
686   /// Row names
687   inline const std::vector<std::string> * rowNames() const {
688      return &rowNames_;
689   }
690   inline const std::string& rowName(int iRow) const {
691      return rowNames_[iRow];
692   }
693   /// Return name or Rnnnnnnn
694   std::string getRowName(int iRow) const;
695   /// Column names
696   inline const std::vector<std::string> * columnNames() const {
697      return &columnNames_;
698   }
699   inline const std::string& columnName(int iColumn) const {
700      return columnNames_[iColumn];
701   }
702   /// Return name or Cnnnnnnn
703   std::string getColumnName(int iColumn) const;
704#endif
705  /// Objective methods
706  inline ClpObjective * objectiveAsObject() const
707  { return objective_;}
708  void setObjective(ClpObjective * objective);
709  inline void setObjectivePointer(ClpObjective * objective)
710  { objective_ = objective;}
711  /** Solve a problem with no elements - return status and
712      dual and primal infeasibilites */
713  int emptyProblem(int * infeasNumber=NULL, double * infeasSum=NULL,bool printMessage=true);
714 
715  //@}
716
717  /**@name Matrix times vector methods
718     They can be faster if scalar is +- 1
719     These are covers so user need not worry about scaling
720     Also for simplex I am not using basic/non-basic split */
721  //@{
722    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
723        @pre <code>x</code> must be of size <code>numColumns()</code>
724        @pre <code>y</code> must be of size <code>numRows()</code> */
725   void times(double scalar,
726                       const double * x, double * y) const;
727    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
728        @pre <code>x</code> must be of size <code>numRows()</code>
729        @pre <code>y</code> must be of size <code>numColumns()</code> */
730    void transposeTimes(double scalar,
731                                const double * x, double * y) const ;
732  //@}
733
734
735  //---------------------------------------------------------------------------
736  /**@name Parameter set/get methods
737
738     The set methods return true if the parameter was set to the given value,
739     false otherwise. There can be various reasons for failure: the given
740     parameter is not applicable for the solver (e.g., refactorization
741     frequency for the volume algorithm), the parameter is not yet implemented
742     for the solver or simply the value of the parameter is out of the range
743     the solver accepts. If a parameter setting call returns false check the
744     details of your solver.
745
746     The get methods return true if the given parameter is applicable for the
747     solver and is implemented. In this case the value of the parameter is
748     returned in the second argument. Otherwise they return false.
749
750     ** once it has been decided where solver sits this may be redone
751  */
752  //@{
753    /// Set an integer parameter
754    bool setIntParam(ClpIntParam key, int value) ;
755    /// Set an double parameter
756    bool setDblParam(ClpDblParam key, double value) ;
757#ifndef CLP_NO_STD
758    /// Set an string parameter
759    bool setStrParam(ClpStrParam key, const std::string & value);
760#endif
761    // Get an integer parameter
762    inline bool getIntParam(ClpIntParam key, int& value) const {
763      if (key<ClpLastIntParam) {
764        value = intParam_[key];
765        return true;
766      } else {
767        return false;
768      }
769    }
770    // Get an double parameter
771    inline bool getDblParam(ClpDblParam key, double& value) const {
772      if (key<ClpLastDblParam) {
773        value = dblParam_[key];
774        return true;
775      } else {
776        return false;
777      }
778    }
779#ifndef CLP_NO_STD
780    // Get a string parameter
781    inline bool getStrParam(ClpStrParam key, std::string& value) const {
782      if (key<ClpLastStrParam) {
783        value = strParam_[key];
784        return true;
785      } else {
786        return false;
787      }
788    }
789#endif
790    /// Create C++ lines to get to current state
791    void generateCpp( FILE * fp);
792  /** For advanced options
793      1 - Don't keep changing infeasibility weight
794      2 - Keep nonLinearCost round solves
795      4 - Force outgoing variables to exact bound (primal)
796      8 - Safe to use dense initial factorization
797      16 -Just use basic variables for operation if column generation
798      32 -Clean up with primal before strong branching
799      64 -Treat problem as feasible until last minute (i.e. minimize infeasibilities)
800      128 - Switch off all matrix sanity checks
801      256 - No row copy
802      512 - If not in values pass, solution guaranteed, skip as much as possible
803      1024 - In branch and bound
804      2048 - Don't bother to re-factorize if < 20 iterations
805      4096 - Skip some optimality checks
806      8192 - Do Primal when cleaning up primal
807      16384 - In fast dual (so we can switch off things)
808      32678 - called from Osi
809      65356 - keep arrays around as much as possible
810      131072 - scale factor arrays have inverse values at end
811      NOTE - many applications can call Clp but there may be some short cuts
812             which are taken which are not guaranteed safe from all applications.
813             Vetted applications will have a bit set and the code may test this
814             At present I expect a few such applications - if too many I will
815             have to re-think.  It is up to application owner to change the code
816             if she/he needs these short cuts.  I will not debug unless in Coin
817             repository.  See COIN_CLP_VETTED comments.
818      0x01000000 is Cbc (and in branch and bound)
819      0x02000000 is in a different branch and bound
820  */
821#define COIN_CBC_USING_CLP 0x01000000
822  inline unsigned int specialOptions() const
823  { return specialOptions_;}
824  void setSpecialOptions(unsigned int value);
825  //@}
826
827  /**@name private or protected methods */
828  //@{
829protected:
830  /// Does most of deletion
831  void gutsOfDelete();
832  /** Does most of copying
833      If trueCopy false then just points to arrays */
834  void gutsOfCopy(const ClpModel & rhs, bool trueCopy=true);
835  /// gets lower and upper bounds on rows
836  void getRowBound(int iRow, double& lower, double& upper) const;
837  /// puts in format I like - 4 array matrix - may make row copy
838  void gutsOfLoadModel ( int numberRows, int numberColumns,
839                     const double* collb, const double* colub,   
840                     const double* obj,
841                     const double* rowlb, const double* rowub,
842                      const double * rowObjective=NULL);
843  /// Does much of scaling
844  void gutsOfScaling();
845   /// Objective value - always minimize
846   inline double rawObjectiveValue() const {
847      return objectiveValue_;
848   }
849  /// Create row names as char **
850  const char * const * rowNamesAsChar() const;
851  /// Create column names as char **
852  const char * const * columnNamesAsChar() const;
853  /// Delete char * version of names
854  void deleteNamesAsChar(const char * const * names,int number) const;
855  /// On stopped - sets secondary status
856  void onStopped();
857  //@}
858
859
860////////////////// data //////////////////
861protected:
862
863  /**@name data */
864  //@{
865  /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
866  double optimizationDirection_;
867  /// Array of double parameters
868  double dblParam_[ClpLastDblParam];
869  /// Objective value
870  double objectiveValue_;
871  /// Small element value
872  double smallElement_;
873  /// Scaling of objective
874  double objectiveScale_;
875  /// Scaling of rhs and bounds
876  double rhsScale_;
877  /// Number of rows
878  int numberRows_;
879  /// Number of columns
880  int numberColumns_;
881  /// Row activities
882  double * rowActivity_;
883  /// Column activities
884  double * columnActivity_;
885  /// Duals
886  double * dual_;
887  /// Reduced costs
888  double * reducedCost_;
889  /// Row lower
890  double* rowLower_;
891  /// Row upper
892  double* rowUpper_;
893  /// Objective
894  ClpObjective * objective_;
895  /// Row Objective (? sign)  - may be NULL
896  double * rowObjective_;
897  /// Column Lower
898  double * columnLower_;
899  /// Column Upper
900  double * columnUpper_;
901  /// Packed matrix
902  ClpMatrixBase * matrix_;
903  /// Row copy if wanted
904  ClpMatrixBase * rowCopy_;
905  /// Infeasible/unbounded ray
906  double * ray_;
907  /// Row scale factors for matrix
908  double * rowScale_;
909  /// Column scale factors
910  double * columnScale_;
911  /// Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic
912  int scalingFlag_;
913  /** Status (i.e. basis) Region.  I know that not all algorithms need a status
914      array, but it made sense for things like crossover and put
915      all permanent stuff in one place.  No assumption is made
916      about what is in status array (although it might be good to reserve
917      bottom 3 bits (i.e. 0-7 numeric) for classic status).  This
918      is number of columns + number of rows long (in that order).
919  */
920  unsigned char * status_;
921  /// Integer information
922  char * integerType_;
923  /// User pointer for whatever reason
924  void * userPointer_;
925  /// Array of integer parameters
926  int intParam_[ClpLastIntParam];
927  /// Number of iterations
928  int numberIterations_;
929  /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/
930  int solveType_;
931  /** Whats changed since last solve.  This is a work in progress
932      It is designed so careful people can make go faster.
933      It is only used when startFinishOptions used in dual or primal.
934      Bit 1 - number of rows/columns has not changed (so work arrays valid)
935          2 - matrix has not changed
936          4 - if matrix has changed only by adding rows
937          8 - if matrix has changed only by adding columns
938         16 - row lbs not changed
939         32 - row ubs not changed
940         64 - column objective not changed
941        128 - column lbs not changed
942        256 - column ubs not changed
943        512 - basis not changed (up to user to set this to 0)
944              top bits may be used internally
945  */
946  unsigned int whatsChanged_;
947  /// Status of problem
948  int problemStatus_;
949  /// Secondary status of problem
950  int secondaryStatus_;
951  /// length of names (0 means no names)
952  int lengthNames_;
953  /// Number of threads (not very operational)
954  int numberThreads_;
955  /** For advanced options
956      See get and set for meaning
957  */
958  unsigned int specialOptions_;
959  /// Message handler
960  CoinMessageHandler * handler_;
961  /// Flag to say if default handler (so delete)
962  bool defaultHandler_;
963  /// Event handler
964  ClpEventHandler * eventHandler_;
965#ifndef CLP_NO_STD
966  /// Row names
967  std::vector<std::string> rowNames_;
968  /// Column names
969  std::vector<std::string> columnNames_;
970#endif
971  /// Messages
972  CoinMessages messages_;
973  /// Coin messages
974  CoinMessages coinMessages_;
975#ifndef CLP_NO_STD
976  /// Array of string parameters
977  std::string strParam_[ClpLastStrParam];
978#endif
979  //@}
980};
981/** This is a tiny class where data can be saved round calls.
982 */
983class ClpDataSave {
984
985public:
986  /**@name Constructors and destructor
987   */
988  //@{
989    /// Default constructor
990    ClpDataSave (  );
991
992    /// Copy constructor.
993    ClpDataSave(const ClpDataSave &);
994    /// Assignment operator. This copies the data
995    ClpDataSave & operator=(const ClpDataSave & rhs);
996    /// Destructor
997    ~ClpDataSave (  );
998
999  //@}
1000
1001////////////////// data //////////////////
1002public:
1003
1004  /**@name data - with same names as in other classes*/
1005  //@{
1006  double dualBound_;
1007  double infeasibilityCost_;
1008  double pivotTolerance_;
1009  double acceptablePivot_;
1010  double objectiveScale_;
1011  int sparseThreshold_;
1012  int perturbation_;
1013  int forceFactorization_;
1014  int scalingFlag_;
1015  //@}
1016};
1017
1018#endif
Note: See TracBrowser for help on using the repository browser.