source: branches/devel-1/include/ClpModel.hpp @ 19

Last change on this file since 19 was 19, checked in by ladanyi, 17 years ago

reordering Clp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpModel_H
4#define ClpModel_H
5
6#include <iostream>
7#include <cassert>
8#include <cmath>
9#include <vector>
10#include <string>
11
12#include "ClpMatrixBase.hpp"
13#include "CoinMessageHandler.hpp"
14#include "ClpParameters.hpp"
15
16#define CLP_INFINITY 1e30
17
18/** This is the base class for Linear Models
19    This knows nothing about the algorithm, but it seems to
20    have a reasonable amount of information
21
22    I would welcome suggestions for what should be in this and
23    how it relates to OsiSolverInterface.  Some methods look
24    very similar.
25
26*/
27
28class ClpModel {
29
30public:
31
32  /**@name Constructors and destructor
33     Note - copy methods copy ALL data so can chew up memory
34     until other copy is freed
35   */
36  //@{
37    /// Default constructor
38    ClpModel (  );
39
40    /// Copy constructor.
41    ClpModel(const ClpModel &);
42    /// Assignment operator. This copies the data
43    ClpModel & operator=(const ClpModel & rhs);
44    /// Destructor
45    ~ClpModel (  );
46  //@}
47
48  /**@name Load model - loads some stuff and initializes others */
49  //@{
50    /** Loads a problem (the constraints on the
51        rows are given by lower and upper bounds). If a pointer is 0 then the
52        following values are the default:
53        <ul>
54          <li> <code>colub</code>: all columns have upper bound infinity
55          <li> <code>collb</code>: all columns have lower bound 0
56          <li> <code>rowub</code>: all rows have upper bound infinity
57          <li> <code>rowlb</code>: all rows have lower bound -infinity
58          <li> <code>obj</code>: all variables have 0 objective coefficient
59        </ul>
60    */
61  void loadProblem (  const ClpMatrixBase& matrix,
62                     const double* collb, const double* colub,   
63                     const double* obj,
64                     const double* rowlb, const double* rowub,
65                      const double * rowObjective=NULL);
66  void loadProblem (  const CoinPackedMatrix& matrix,
67                     const double* collb, const double* colub,   
68                     const double* obj,
69                     const double* rowlb, const double* rowub,
70                      const double * rowObjective=NULL);
71
72  /** Just like the other loadProblem() method except that the matrix is
73        given in a standard column major ordered format (without gaps). */
74  void loadProblem (  const int numcols, const int numrows,
75                     const int* start, const int* index,
76                     const double* value,
77                     const double* collb, const double* colub,   
78                     const double* obj,
79                      const double* rowlb, const double* rowub,
80                      const double * rowObjective=NULL);
81  /// Read an mps file from the given filename
82  int readMps(const char *filename,
83              bool keepNames=false,
84              bool ignoreErrors = false);
85  /// Resizes rim part of model
86  void resize (int newNumberRows, int newNumberColumns);
87  /// Deletes rows
88  void deleteRows(int number, const int * which);
89  /// Deletes columns
90 
91  void deleteColumns(int number, const int * which);
92  /** Borrow model.  This is so we dont have to copy large amounts
93      of data around.  It assumes a derived class wants to overwrite
94      an empty model with a real one - while it does an algorithm */
95  void borrowModel(ClpModel & otherModel);
96  /** Return model - nulls all arrays so can be deleted safely
97      also updates any scalars */
98  void returnModel(ClpModel & otherModel);
99 
100  //@}
101  /**@name gets and sets */
102  //@{
103   /// Number of rows
104   inline int numberRows() const {
105      return numberRows_;
106   }
107   inline int getNumRows() const {
108      return numberRows_;
109   }
110   /// Number of columns
111   inline int getNumCols() const {
112      return numberColumns_;
113   }
114   inline int numberColumns() const {
115      return numberColumns_;
116   }
117   /// Primal tolerance to use
118   inline double primalTolerance() const {
119      return dblParam_[ClpPrimalTolerance];
120   }
121   void setPrimalTolerance( double value) ;
122   /// Dual tolerance to use
123   inline double dualTolerance() const  { return dblParam_[ClpDualTolerance]; }
124   void setDualTolerance( double value) ;
125   /// Number of iterations
126   inline int numberIterations() const  { return numberIterations_; }
127   inline int getIterationCount() const { return numberIterations_; }
128   /// Maximum number of iterations
129   inline int maximumIterations() const { return maximumIterations_; }
130   void setMaximumIterations(int value);
131   /** Status of problem:
132       0 - optimal
133       1 - primal infeasible
134       2 - dual infeasible
135       3 - stopped on iterations etc
136       4 - stopped due to errors
137   */
138   inline int status() const            { return problemStatus_; }
139   /// Are there a numerical difficulties?
140   bool isAbandoned() const             { return problemStatus_==4; }
141   /// Is optimality proven?
142   bool isProvenOptimal() const         { return problemStatus_==0; }
143   /// Is primal infeasiblity proven?
144   bool isProvenPrimalInfeasible() const { return problemStatus_==1; }
145   /// Is dual infeasiblity proven?
146   bool isProvenDualInfeasible() const  { return problemStatus_==2; }
147   /// Is the given primal objective limit reached?
148   bool isPrimalObjectiveLimitReached() const ;
149   /// Is the given dual objective limit reached?
150   bool isDualObjectiveLimitReached() const ;
151   /// Iteration limit reached?
152   bool isIterationLimitReached() const { return problemStatus_==3; }
153   /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
154   inline int optimizationDirection() const {
155      return (int) optimizationDirection_;
156   }
157   inline double getObjSense() const    { return optimizationDirection_; }
158   void setOptimizationDirection(int value);
159   /// Primal row solution
160   inline double * primalRowSolution() const    { return rowActivity_; }
161   inline const double * getRowActivity() const { return rowActivity_; }
162   /// Primal column solution
163   inline double * primalColumnSolution() const { return columnActivity_; }
164   inline const double * getColSolution() const { return columnActivity_; }
165   /// Dual row solution
166   inline double * dualRowSolution() const      { return dual_; }
167   inline const double * getRowPrice() const    { return dual_; }
168   /// Reduced costs
169   inline double * dualColumnSolution() const   { return reducedCost_; }
170   inline const double * getReducedCost() const { return reducedCost_; }
171   /// Row lower
172   inline double* rowLower() const              { return rowLower_; }
173   inline const double* getRowLower() const     { return rowLower_; }
174   /// Row upper
175   inline double* rowUpper() const              { return rowUpper_; }
176   inline const double* getRowUpper() const     { return rowUpper_; }
177   /// Objective
178   inline double * objective() const            { return objective_; }
179   inline const double * getObjCoefficients() const { return objective_; }
180   /// Row Objective
181   inline double * rowObjective() const         { return rowObjective_; }
182   inline const double * getRowObjCoefficients() const {
183      return rowObjective_;
184   }
185   /// Column Lower
186   inline double * columnLower() const          { return columnLower_; }
187   inline const double * getColLower() const    { return columnLower_; }
188   /// Column Upper
189   inline double * columnUpper() const          { return columnUpper_; }
190   inline const double * getColUpper() const    { return columnUpper_; }
191   /// Matrix (if not ClpPackedmatrix be careful about memory leak
192   inline CoinPackedMatrix * matrix() const {
193      return matrix_->getPackedMatrix();
194   }
195   /// Row Matrix
196   inline ClpMatrixBase * rowCopy() const       { return rowCopy_; }
197   /// Clp Matrix
198   inline ClpMatrixBase * clpMatrix() const     { return matrix_; }
199   /// Objective value
200   inline double objectiveValue() const {
201      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
202   }
203   inline double getObjValue() const {
204      return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
205   }
206   /// Integer information
207   inline char * integerInformation() const     { return integerType_; }
208   /** Infeasibility/unbounded ray (NULL returned if none/wrong)
209       Up to user to use delete [] on these arrays.  */
210   double * infeasibilityRay() const;
211   double * unboundedRay() const;
212  //@}
213  /**@name Message handling */
214  //@{
215   /// Pass in Message handler (not deleted at end)
216   void passInMessageHandler(CoinMessageHandler * handler);
217   /// Set language
218   void newLanguage(CoinMessages::Language language);
219   void setLanguage(CoinMessages::Language language) { newLanguage(language); }
220   /// Return handler
221   CoinMessageHandler * messageHandler() const       { return handler_; }
222   /// Return messages
223   CoinMessages messages() const                     { return messages_; }
224   /// Return pointer to messages
225   CoinMessages * messagesPointer()                  { return & messages_; }
226   /// Log level
227   void setLogLevel(int value)    { handler_->setLogLevel(value); }
228   int logLevel() const           { return handler_->logLevel(); }
229   /// length of names (0 means no names0
230   inline int lengthNames() const { return lengthNames_; }
231   /// Row names
232   const std::vector<std::string> * rowNames() const {
233      return &rowNames_;
234   }
235   const std::string& rowName(int iRow) const {
236      return rowNames_[iRow];
237   }
238   /// Column names
239   const std::vector<std::string> * columnNames() const {
240      return &columnNames_;
241   }
242   const std::string& columnName(int iColumn) const {
243      return columnNames_[iColumn];
244   }
245  //@}
246
247
248  //---------------------------------------------------------------------------
249  /**@name Parameter set/get methods
250
251     The set methods return true if the parameter was set to the given value,
252     false otherwise. There can be various reasons for failure: the given
253     parameter is not applicable for the solver (e.g., refactorization
254     frequency for the volume algorithm), the parameter is not yet implemented
255     for the solver or simply the value of the parameter is out of the range
256     the solver accepts. If a parameter setting call returns false check the
257     details of your solver.
258
259     The get methods return true if the given parameter is applicable for the
260     solver and is implemented. In this case the value of the parameter is
261     returned in the second argument. Otherwise they return false.
262
263     ** once it has been decided where solver sits this may be redone
264  */
265  //@{
266    /// Set an integer parameter
267    bool setIntParam(ClpIntParam key, int value) ;
268    /// Set an double parameter
269    bool setDblParam(ClpDblParam key, double value) ;
270    /// Set an string parameter
271    bool setStrParam(ClpStrParam key, const std::string & value);
272    // Get an integer parameter
273    inline bool getIntParam(ClpIntParam key, int& value) const {
274      if (key!=ClpLastIntParam) {
275        value = intParam_[key];
276        return true;
277      } else {
278        return false;
279      }
280    }
281    // Get an double parameter
282    inline bool getDblParam(ClpDblParam key, double& value) const {
283      if (key!=ClpLastDblParam) {
284        value = dblParam_[key];
285        return true;
286      } else {
287        return false;
288      }
289    }
290    // Get a string parameter
291    inline bool getStrParam(ClpStrParam key, std::string& value) const {
292      if (key!=ClpLastStrParam) {
293        value = strParam_[key];
294        return true;
295      } else {
296        return false;
297      }
298    }
299  //@}
300
301  /**@name private or protected methods */
302  //@{
303protected:
304  /// Does most of deletion
305  void gutsOfDelete();
306  /** Does most of copying
307      If trueCopy false then just points to arrays */
308  void gutsOfCopy(const ClpModel & rhs, bool trueCopy=true);
309  /// gets lower and upper bounds on rows
310  void getRowBound(int iRow, double& lower, double& upper) const;
311  /// puts in format I like - 4 array matrix - may make row copy
312  void gutsOfLoadModel ( int numberRows, int numberColumns,
313                     const double* collb, const double* colub,   
314                     const double* obj,
315                     const double* rowlb, const double* rowub,
316                      const double * rowObjective=NULL);
317  //@}
318
319
320////////////////// data //////////////////
321protected:
322
323  /**@name data */
324  //@{
325  /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
326  double optimizationDirection_;
327  /// Number of rows
328  int numberRows_;
329  /// Number of columns
330  int numberColumns_;
331  /// Row activities
332  double * rowActivity_;
333  /// Column activities
334  double * columnActivity_;
335  /// Duals
336  double * dual_;
337  /// Reduced costs
338  double * reducedCost_;
339  /// Row lower
340  double* rowLower_;
341  /// Row upper
342  double* rowUpper_;
343  /// Objective
344  double * objective_;
345  /// Row Objective (? sign)  - may be NULL
346  double * rowObjective_;
347  /// Column Lower
348  double * columnLower_;
349  /// Column Upper
350  double * columnUpper_;
351  /// Packed matrix
352  ClpMatrixBase * matrix_;
353  /// Row copy if wanted
354  ClpMatrixBase * rowCopy_;
355  /// Infeasible/unbounded ray
356  double * ray_;
357  /// Array of integer parameters
358  int intParam_[ClpLastIntParam];
359  /// Array of double parameters
360  double dblParam_[ClpLastDblParam];
361  /// Array of string parameters
362  std::string strParam_[ClpLastStrParam];
363  /// Objective value
364  double objectiveValue_;
365  /// Number of iterations
366  int numberIterations_;
367  /// Status of problem
368  int problemStatus_;
369  /// Maximum number of iterations
370  int maximumIterations_;
371  /// Message handler
372  CoinMessageHandler * handler_;
373  /// Flag to say if default handler (so delete)
374  bool defaultHandler_;
375  /// Messages
376  CoinMessages messages_;
377  /// length of names (0 means no names)
378  int lengthNames_;
379  /// Row names
380  std::vector<std::string> rowNames_;
381  /// Column names
382  std::vector<std::string> columnNames_;
383  /// Integer information
384  char * integerType_;
385  //@}
386};
387#endif
Note: See TracBrowser for help on using the repository browser.