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

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

undid last commit (patches incorrectly applied)

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