source: stable/1.11/Clp/src/ClpModel.hpp @ 1461

Last change on this file since 1461 was 1461, checked in by stefan, 11 years ago

fix compiler warnings declaration of XXX shadows a member of YYY; remove unnecessary include to avoid warnings from CoinFactorization?

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