1 | /* $Id: ClpModel.hpp 1525 2010-02-26 17:27:59Z mjs $ */ |
---|
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" |
---|
23 | class 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 | */ |
---|
33 | class CoinBuild; |
---|
34 | class CoinModel; |
---|
35 | class ClpModel { |
---|
36 | |
---|
37 | public: |
---|
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 | } |
---|
229 | /** Change row lower bounds */ |
---|
230 | void chgRowLower(const double * rowLower); |
---|
231 | /** Change row upper bounds */ |
---|
232 | void chgRowUpper(const double * rowUpper); |
---|
233 | /** Change column lower bounds */ |
---|
234 | void chgColumnLower(const double * columnLower); |
---|
235 | /** Change column upper bounds */ |
---|
236 | void chgColumnUpper(const double * columnUpper); |
---|
237 | /** Change objective coefficients */ |
---|
238 | void chgObjCoefficients(const double * objIn); |
---|
239 | /** Borrow model. This is so we don't have to copy large amounts |
---|
240 | of data around. It assumes a derived class wants to overwrite |
---|
241 | an empty model with a real one - while it does an algorithm */ |
---|
242 | void borrowModel(ClpModel & otherModel); |
---|
243 | /** Return model - nulls all arrays so can be deleted safely |
---|
244 | also updates any scalars */ |
---|
245 | void returnModel(ClpModel & otherModel); |
---|
246 | |
---|
247 | /// Create empty ClpPackedMatrix |
---|
248 | void createEmptyMatrix(); |
---|
249 | /** Really clean up matrix (if ClpPackedMatrix). |
---|
250 | a) eliminate all duplicate AND small elements in matrix |
---|
251 | b) remove all gaps and set extraGap_ and extraMajor_ to 0.0 |
---|
252 | c) reallocate arrays and make max lengths equal to lengths |
---|
253 | d) orders elements |
---|
254 | returns number of elements eliminated or -1 if not ClpPackedMatrix |
---|
255 | */ |
---|
256 | int cleanMatrix(double threshold = 1.0e-20); |
---|
257 | /// Copy contents - resizing if necessary - otherwise re-use memory |
---|
258 | void copy(const ClpMatrixBase * from, ClpMatrixBase * & to); |
---|
259 | #ifndef CLP_NO_STD |
---|
260 | /// Drops names - makes lengthnames 0 and names empty |
---|
261 | void dropNames(); |
---|
262 | /// Copies in names |
---|
263 | void copyNames(std::vector<std::string> & rowNames, |
---|
264 | std::vector<std::string> & columnNames); |
---|
265 | /// Copies in Row names - modifies names first .. last-1 |
---|
266 | void copyRowNames(const std::vector<std::string> & rowNames, int first, int last); |
---|
267 | /// Copies in Column names - modifies names first .. last-1 |
---|
268 | void copyColumnNames(const std::vector<std::string> & columnNames, int first, int last); |
---|
269 | /// Copies in Row names - modifies names first .. last-1 |
---|
270 | void copyRowNames(const char * const * rowNames, int first, int last); |
---|
271 | /// Copies in Column names - modifies names first .. last-1 |
---|
272 | void copyColumnNames(const char * const * columnNames, int first, int last); |
---|
273 | /// Set name of row |
---|
274 | void setRowName(int rowIndex, std::string & name) ; |
---|
275 | /// Set name of col |
---|
276 | void setColumnName(int colIndex, std::string & name) ; |
---|
277 | #endif |
---|
278 | /** Find a network subset. |
---|
279 | rotate array should be numberRows. On output |
---|
280 | -1 not in network |
---|
281 | 0 in network as is |
---|
282 | 1 in network with signs swapped |
---|
283 | Returns number of network rows |
---|
284 | */ |
---|
285 | int findNetwork(char * rotate, double fractionNeeded = 0.75); |
---|
286 | /** This creates a coinModel object |
---|
287 | */ |
---|
288 | CoinModel * createCoinModel() const; |
---|
289 | |
---|
290 | /** Write the problem in MPS format to the specified file. |
---|
291 | |
---|
292 | Row and column names may be null. |
---|
293 | formatType is |
---|
294 | <ul> |
---|
295 | <li> 0 - normal |
---|
296 | <li> 1 - extra accuracy |
---|
297 | <li> 2 - IEEE hex |
---|
298 | </ul> |
---|
299 | |
---|
300 | Returns non-zero on I/O error |
---|
301 | */ |
---|
302 | int writeMps(const char *filename, |
---|
303 | int formatType = 0, int numberAcross = 2, |
---|
304 | double objSense = 0.0) const ; |
---|
305 | //@} |
---|
306 | /**@name gets and sets */ |
---|
307 | //@{ |
---|
308 | /// Number of rows |
---|
309 | inline int numberRows() const { |
---|
310 | return numberRows_; |
---|
311 | } |
---|
312 | inline int getNumRows() const { |
---|
313 | return numberRows_; |
---|
314 | } |
---|
315 | /// Number of columns |
---|
316 | inline int getNumCols() const { |
---|
317 | return numberColumns_; |
---|
318 | } |
---|
319 | inline int numberColumns() const { |
---|
320 | return numberColumns_; |
---|
321 | } |
---|
322 | /// Primal tolerance to use |
---|
323 | inline double primalTolerance() const { |
---|
324 | return dblParam_[ClpPrimalTolerance]; |
---|
325 | } |
---|
326 | void setPrimalTolerance( double value) ; |
---|
327 | /// Dual tolerance to use |
---|
328 | inline double dualTolerance() const { |
---|
329 | return dblParam_[ClpDualTolerance]; |
---|
330 | } |
---|
331 | void setDualTolerance( double value) ; |
---|
332 | /// Primal objective limit |
---|
333 | inline double primalObjectiveLimit() const { |
---|
334 | return dblParam_[ClpPrimalObjectiveLimit]; |
---|
335 | } |
---|
336 | void setPrimalObjectiveLimit(double value); |
---|
337 | /// Dual objective limit |
---|
338 | inline double dualObjectiveLimit() const { |
---|
339 | return dblParam_[ClpDualObjectiveLimit]; |
---|
340 | } |
---|
341 | void setDualObjectiveLimit(double value); |
---|
342 | /// Objective offset |
---|
343 | inline double objectiveOffset() const { |
---|
344 | return dblParam_[ClpObjOffset]; |
---|
345 | } |
---|
346 | void setObjectiveOffset(double value); |
---|
347 | /// Presolve tolerance to use |
---|
348 | inline double presolveTolerance() const { |
---|
349 | return dblParam_[ClpPresolveTolerance]; |
---|
350 | } |
---|
351 | #ifndef CLP_NO_STD |
---|
352 | inline std::string problemName() const { |
---|
353 | return strParam_[ClpProbName]; |
---|
354 | } |
---|
355 | #endif |
---|
356 | /// Number of iterations |
---|
357 | inline int numberIterations() const { |
---|
358 | return numberIterations_; |
---|
359 | } |
---|
360 | inline int getIterationCount() const { |
---|
361 | return numberIterations_; |
---|
362 | } |
---|
363 | inline void setNumberIterations(int numberIterationsNew) { |
---|
364 | numberIterations_ = numberIterationsNew; |
---|
365 | } |
---|
366 | /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/ |
---|
367 | inline int solveType() const { |
---|
368 | return solveType_; |
---|
369 | } |
---|
370 | inline void setSolveType(int type) { |
---|
371 | solveType_ = type; |
---|
372 | } |
---|
373 | /// Maximum number of iterations |
---|
374 | inline int maximumIterations() const { |
---|
375 | return intParam_[ClpMaxNumIteration]; |
---|
376 | } |
---|
377 | void setMaximumIterations(int value); |
---|
378 | /// Maximum time in seconds (from when set called) |
---|
379 | inline double maximumSeconds() const { |
---|
380 | return dblParam_[ClpMaxSeconds]; |
---|
381 | } |
---|
382 | void setMaximumSeconds(double value); |
---|
383 | /// Returns true if hit maximum iterations (or time) |
---|
384 | bool hitMaximumIterations() const; |
---|
385 | /** Status of problem: |
---|
386 | -1 - unknown e.g. before solve or if postSolve says not optimal |
---|
387 | 0 - optimal |
---|
388 | 1 - primal infeasible |
---|
389 | 2 - dual infeasible |
---|
390 | 3 - stopped on iterations or time |
---|
391 | 4 - stopped due to errors |
---|
392 | 5 - stopped by event handler (virtual int ClpEventHandler::event()) |
---|
393 | */ |
---|
394 | inline int status() const { |
---|
395 | return problemStatus_; |
---|
396 | } |
---|
397 | inline int problemStatus() const { |
---|
398 | return problemStatus_; |
---|
399 | } |
---|
400 | /// Set problem status |
---|
401 | inline void setProblemStatus(int problemStatusNew) { |
---|
402 | problemStatus_ = problemStatusNew; |
---|
403 | } |
---|
404 | /** Secondary status of problem - may get extended |
---|
405 | 0 - none |
---|
406 | 1 - primal infeasible because dual limit reached OR (probably primal |
---|
407 | infeasible but can't prove it - main status was 4) |
---|
408 | 2 - scaled problem optimal - unscaled problem has primal infeasibilities |
---|
409 | 3 - scaled problem optimal - unscaled problem has dual infeasibilities |
---|
410 | 4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities |
---|
411 | 5 - giving up in primal with flagged variables |
---|
412 | 6 - failed due to empty problem check |
---|
413 | 7 - postSolve says not optimal |
---|
414 | 8 - failed due to bad element check |
---|
415 | 9 - status was 3 and stopped on time |
---|
416 | 100 up - translation of enum from ClpEventHandler |
---|
417 | */ |
---|
418 | inline int secondaryStatus() const { |
---|
419 | return secondaryStatus_; |
---|
420 | } |
---|
421 | inline void setSecondaryStatus(int newstatus) { |
---|
422 | secondaryStatus_ = newstatus; |
---|
423 | } |
---|
424 | /// Are there a numerical difficulties? |
---|
425 | inline bool isAbandoned() const { |
---|
426 | return problemStatus_ == 4; |
---|
427 | } |
---|
428 | /// Is optimality proven? |
---|
429 | inline bool isProvenOptimal() const { |
---|
430 | return problemStatus_ == 0; |
---|
431 | } |
---|
432 | /// Is primal infeasiblity proven? |
---|
433 | inline bool isProvenPrimalInfeasible() const { |
---|
434 | return problemStatus_ == 1; |
---|
435 | } |
---|
436 | /// Is dual infeasiblity proven? |
---|
437 | inline bool isProvenDualInfeasible() const { |
---|
438 | return problemStatus_ == 2; |
---|
439 | } |
---|
440 | /// Is the given primal objective limit reached? |
---|
441 | bool isPrimalObjectiveLimitReached() const ; |
---|
442 | /// Is the given dual objective limit reached? |
---|
443 | bool isDualObjectiveLimitReached() const ; |
---|
444 | /// Iteration limit reached? |
---|
445 | inline bool isIterationLimitReached() const { |
---|
446 | return problemStatus_ == 3; |
---|
447 | } |
---|
448 | /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore |
---|
449 | inline double optimizationDirection() const { |
---|
450 | return optimizationDirection_; |
---|
451 | } |
---|
452 | inline double getObjSense() const { |
---|
453 | return optimizationDirection_; |
---|
454 | } |
---|
455 | void setOptimizationDirection(double value); |
---|
456 | /// Primal row solution |
---|
457 | inline double * primalRowSolution() const { |
---|
458 | return rowActivity_; |
---|
459 | } |
---|
460 | inline const double * getRowActivity() const { |
---|
461 | return rowActivity_; |
---|
462 | } |
---|
463 | /// Primal column solution |
---|
464 | inline double * primalColumnSolution() const { |
---|
465 | return columnActivity_; |
---|
466 | } |
---|
467 | inline const double * getColSolution() const { |
---|
468 | return columnActivity_; |
---|
469 | } |
---|
470 | inline void setColSolution(const double * input) { |
---|
471 | memcpy(columnActivity_, input, numberColumns_ * sizeof(double)); |
---|
472 | } |
---|
473 | /// Dual row solution |
---|
474 | inline double * dualRowSolution() const { |
---|
475 | return dual_; |
---|
476 | } |
---|
477 | inline const double * getRowPrice() const { |
---|
478 | return dual_; |
---|
479 | } |
---|
480 | /// Reduced costs |
---|
481 | inline double * dualColumnSolution() const { |
---|
482 | return reducedCost_; |
---|
483 | } |
---|
484 | inline const double * getReducedCost() const { |
---|
485 | return reducedCost_; |
---|
486 | } |
---|
487 | /// Row lower |
---|
488 | inline double* rowLower() const { |
---|
489 | return rowLower_; |
---|
490 | } |
---|
491 | inline const double* getRowLower() const { |
---|
492 | return rowLower_; |
---|
493 | } |
---|
494 | /// Row upper |
---|
495 | inline double* rowUpper() const { |
---|
496 | return rowUpper_; |
---|
497 | } |
---|
498 | inline const double* getRowUpper() const { |
---|
499 | return rowUpper_; |
---|
500 | } |
---|
501 | //------------------------------------------------------------------------- |
---|
502 | /**@name Changing bounds on variables and constraints */ |
---|
503 | //@{ |
---|
504 | /** Set an objective function coefficient */ |
---|
505 | void setObjectiveCoefficient( int elementIndex, double elementValue ); |
---|
506 | /** Set an objective function coefficient */ |
---|
507 | inline void setObjCoeff( int elementIndex, double elementValue ) { |
---|
508 | setObjectiveCoefficient( elementIndex, elementValue); |
---|
509 | } |
---|
510 | |
---|
511 | /** Set a single column lower bound<br> |
---|
512 | Use -DBL_MAX for -infinity. */ |
---|
513 | void setColumnLower( int elementIndex, double elementValue ); |
---|
514 | |
---|
515 | /** Set a single column upper bound<br> |
---|
516 | Use DBL_MAX for infinity. */ |
---|
517 | void setColumnUpper( int elementIndex, double elementValue ); |
---|
518 | |
---|
519 | /** Set a single column lower and upper bound */ |
---|
520 | void setColumnBounds( int elementIndex, |
---|
521 | double lower, double upper ); |
---|
522 | |
---|
523 | /** Set the bounds on a number of columns simultaneously<br> |
---|
524 | The default implementation just invokes setColLower() and |
---|
525 | setColUpper() over and over again. |
---|
526 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
527 | end of the array of the indices of the variables whose |
---|
528 | <em>either</em> bound changes |
---|
529 | @param boundList the new lower/upper bound pairs for the variables |
---|
530 | */ |
---|
531 | void setColumnSetBounds(const int* indexFirst, |
---|
532 | const int* indexLast, |
---|
533 | const double* boundList); |
---|
534 | |
---|
535 | /** Set a single column lower bound<br> |
---|
536 | Use -DBL_MAX for -infinity. */ |
---|
537 | inline void setColLower( int elementIndex, double elementValue ) { |
---|
538 | setColumnLower(elementIndex, elementValue); |
---|
539 | } |
---|
540 | /** Set a single column upper bound<br> |
---|
541 | Use DBL_MAX for infinity. */ |
---|
542 | inline void setColUpper( int elementIndex, double elementValue ) { |
---|
543 | setColumnUpper(elementIndex, elementValue); |
---|
544 | } |
---|
545 | |
---|
546 | /** Set a single column lower and upper bound */ |
---|
547 | inline void setColBounds( int elementIndex, |
---|
548 | double lower, double upper ) { |
---|
549 | setColumnBounds(elementIndex, lower, upper); |
---|
550 | } |
---|
551 | |
---|
552 | /** Set the bounds on a number of columns simultaneously<br> |
---|
553 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
554 | end of the array of the indices of the variables whose |
---|
555 | <em>either</em> bound changes |
---|
556 | @param boundList the new lower/upper bound pairs for the variables |
---|
557 | */ |
---|
558 | inline void setColSetBounds(const int* indexFirst, |
---|
559 | const int* indexLast, |
---|
560 | const double* boundList) { |
---|
561 | setColumnSetBounds(indexFirst, indexLast, boundList); |
---|
562 | } |
---|
563 | |
---|
564 | /** Set a single row lower bound<br> |
---|
565 | Use -DBL_MAX for -infinity. */ |
---|
566 | void setRowLower( int elementIndex, double elementValue ); |
---|
567 | |
---|
568 | /** Set a single row upper bound<br> |
---|
569 | Use DBL_MAX for infinity. */ |
---|
570 | void setRowUpper( int elementIndex, double elementValue ) ; |
---|
571 | |
---|
572 | /** Set a single row lower and upper bound */ |
---|
573 | void setRowBounds( int elementIndex, |
---|
574 | double lower, double upper ) ; |
---|
575 | |
---|
576 | /** Set the bounds on a number of rows simultaneously<br> |
---|
577 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
578 | end of the array of the indices of the constraints whose |
---|
579 | <em>either</em> bound changes |
---|
580 | @param boundList the new lower/upper bound pairs for the constraints |
---|
581 | */ |
---|
582 | void setRowSetBounds(const int* indexFirst, |
---|
583 | const int* indexLast, |
---|
584 | const double* boundList); |
---|
585 | |
---|
586 | //@} |
---|
587 | /// Scaling |
---|
588 | inline const double * rowScale() const { |
---|
589 | return rowScale_; |
---|
590 | } |
---|
591 | inline const double * columnScale() const { |
---|
592 | return columnScale_; |
---|
593 | } |
---|
594 | inline const double * inverseRowScale() const { |
---|
595 | return inverseRowScale_; |
---|
596 | } |
---|
597 | inline const double * inverseColumnScale() const { |
---|
598 | return inverseColumnScale_; |
---|
599 | } |
---|
600 | inline double * mutableRowScale() const { |
---|
601 | return rowScale_; |
---|
602 | } |
---|
603 | inline double * mutableColumnScale() const { |
---|
604 | return columnScale_; |
---|
605 | } |
---|
606 | inline double * mutableInverseRowScale() const { |
---|
607 | return inverseRowScale_; |
---|
608 | } |
---|
609 | inline double * mutableInverseColumnScale() const { |
---|
610 | return inverseColumnScale_; |
---|
611 | } |
---|
612 | void setRowScale(double * scale) ; |
---|
613 | void setColumnScale(double * scale); |
---|
614 | /// Scaling of objective |
---|
615 | inline double objectiveScale() const { |
---|
616 | return objectiveScale_; |
---|
617 | } |
---|
618 | inline void setObjectiveScale(double value) { |
---|
619 | objectiveScale_ = value; |
---|
620 | } |
---|
621 | /// Scaling of rhs and bounds |
---|
622 | inline double rhsScale() const { |
---|
623 | return rhsScale_; |
---|
624 | } |
---|
625 | inline void setRhsScale(double value) { |
---|
626 | rhsScale_ = value; |
---|
627 | } |
---|
628 | /// Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3 auto, 4 auto-but-as-initialSolve-in-bab |
---|
629 | void scaling(int mode = 1); |
---|
630 | /** If we constructed a "really" scaled model then this reverses the operation. |
---|
631 | Quantities may not be exactly as they were before due to rounding errors */ |
---|
632 | void unscale(); |
---|
633 | /// Gets scalingFlag |
---|
634 | inline int scalingFlag() const { |
---|
635 | return scalingFlag_; |
---|
636 | } |
---|
637 | /// Objective |
---|
638 | inline double * objective() const { |
---|
639 | if (objective_) { |
---|
640 | double offset; |
---|
641 | return objective_->gradient(NULL, NULL, offset, false); |
---|
642 | } else { |
---|
643 | return NULL; |
---|
644 | } |
---|
645 | } |
---|
646 | inline double * objective(const double * solution, double & offset, bool refresh = true) const { |
---|
647 | offset = 0.0; |
---|
648 | if (objective_) { |
---|
649 | return objective_->gradient(NULL, solution, offset, refresh); |
---|
650 | } else { |
---|
651 | return NULL; |
---|
652 | } |
---|
653 | } |
---|
654 | inline const double * getObjCoefficients() const { |
---|
655 | if (objective_) { |
---|
656 | double offset; |
---|
657 | return objective_->gradient(NULL, NULL, offset, false); |
---|
658 | } else { |
---|
659 | return NULL; |
---|
660 | } |
---|
661 | } |
---|
662 | /// Row Objective |
---|
663 | inline double * rowObjective() const { |
---|
664 | return rowObjective_; |
---|
665 | } |
---|
666 | inline const double * getRowObjCoefficients() const { |
---|
667 | return rowObjective_; |
---|
668 | } |
---|
669 | /// Column Lower |
---|
670 | inline double * columnLower() const { |
---|
671 | return columnLower_; |
---|
672 | } |
---|
673 | inline const double * getColLower() const { |
---|
674 | return columnLower_; |
---|
675 | } |
---|
676 | /// Column Upper |
---|
677 | inline double * columnUpper() const { |
---|
678 | return columnUpper_; |
---|
679 | } |
---|
680 | inline const double * getColUpper() const { |
---|
681 | return columnUpper_; |
---|
682 | } |
---|
683 | /// Matrix (if not ClpPackedmatrix be careful about memory leak |
---|
684 | inline CoinPackedMatrix * matrix() const { |
---|
685 | if ( matrix_ == NULL ) return NULL; |
---|
686 | else return matrix_->getPackedMatrix(); |
---|
687 | } |
---|
688 | /// Number of elements in matrix |
---|
689 | inline int getNumElements() const { |
---|
690 | return matrix_->getNumElements(); |
---|
691 | } |
---|
692 | /** Small element value - elements less than this set to zero, |
---|
693 | default is 1.0e-20 */ |
---|
694 | inline double getSmallElementValue() const { |
---|
695 | return smallElement_; |
---|
696 | } |
---|
697 | inline void setSmallElementValue(double value) { |
---|
698 | smallElement_ = value; |
---|
699 | } |
---|
700 | /// Row Matrix |
---|
701 | inline ClpMatrixBase * rowCopy() const { |
---|
702 | return rowCopy_; |
---|
703 | } |
---|
704 | /// Set new row matrix |
---|
705 | void setNewRowCopy(ClpMatrixBase * newCopy); |
---|
706 | /// Clp Matrix |
---|
707 | inline ClpMatrixBase * clpMatrix() const { |
---|
708 | return matrix_; |
---|
709 | } |
---|
710 | /// Scaled ClpPackedMatrix |
---|
711 | inline ClpPackedMatrix * clpScaledMatrix() const { |
---|
712 | return scaledMatrix_; |
---|
713 | } |
---|
714 | /// Sets pointer to scaled ClpPackedMatrix |
---|
715 | inline void setClpScaledMatrix(ClpPackedMatrix * scaledMatrix) { |
---|
716 | delete scaledMatrix_; |
---|
717 | scaledMatrix_ = scaledMatrix; |
---|
718 | } |
---|
719 | /** Replace Clp Matrix (current is not deleted unless told to |
---|
720 | and new is used) |
---|
721 | So up to user to delete current. This was used where |
---|
722 | matrices were being rotated. ClpModel takes ownership. |
---|
723 | */ |
---|
724 | void replaceMatrix(ClpMatrixBase * matrix, bool deleteCurrent = false); |
---|
725 | /** Replace Clp Matrix (current is not deleted unless told to |
---|
726 | and new is used) So up to user to delete current. This was used where |
---|
727 | matrices were being rotated. This version changes CoinPackedMatrix |
---|
728 | to ClpPackedMatrix. ClpModel takes ownership. |
---|
729 | */ |
---|
730 | inline void replaceMatrix(CoinPackedMatrix * newmatrix, |
---|
731 | bool deleteCurrent = false) { |
---|
732 | replaceMatrix(new ClpPackedMatrix(newmatrix), deleteCurrent); |
---|
733 | } |
---|
734 | /// Objective value |
---|
735 | inline double objectiveValue() const { |
---|
736 | return objectiveValue_ * optimizationDirection_ - dblParam_[ClpObjOffset]; |
---|
737 | } |
---|
738 | inline void setObjectiveValue(double value) { |
---|
739 | objectiveValue_ = (value + dblParam_[ClpObjOffset]) / optimizationDirection_; |
---|
740 | } |
---|
741 | inline double getObjValue() const { |
---|
742 | return objectiveValue_ * optimizationDirection_ - dblParam_[ClpObjOffset]; |
---|
743 | } |
---|
744 | /// Integer information |
---|
745 | inline char * integerInformation() const { |
---|
746 | return integerType_; |
---|
747 | } |
---|
748 | /** Infeasibility/unbounded ray (NULL returned if none/wrong) |
---|
749 | Up to user to use delete [] on these arrays. */ |
---|
750 | double * infeasibilityRay() const; |
---|
751 | double * unboundedRay() const; |
---|
752 | /// See if status (i.e. basis) array exists (partly for OsiClp) |
---|
753 | inline bool statusExists() const { |
---|
754 | return (status_ != NULL); |
---|
755 | } |
---|
756 | /// Return address of status (i.e. basis) array (char[numberRows+numberColumns]) |
---|
757 | inline unsigned char * statusArray() const { |
---|
758 | return status_; |
---|
759 | } |
---|
760 | /** Return copy of status (i.e. basis) array (char[numberRows+numberColumns]), |
---|
761 | use delete [] */ |
---|
762 | unsigned char * statusCopy() const; |
---|
763 | /// Copy in status (basis) vector |
---|
764 | void copyinStatus(const unsigned char * statusArray); |
---|
765 | |
---|
766 | /// User pointer for whatever reason |
---|
767 | inline void setUserPointer (void * pointer) { |
---|
768 | userPointer_ = pointer; |
---|
769 | } |
---|
770 | inline void * getUserPointer () const { |
---|
771 | return userPointer_; |
---|
772 | } |
---|
773 | /// Trusted user pointer |
---|
774 | inline void setTrustedUserPointer (ClpTrustedData * pointer) { |
---|
775 | trustedUserPointer_ = pointer; |
---|
776 | } |
---|
777 | inline ClpTrustedData * getTrustedUserPointer () const { |
---|
778 | return trustedUserPointer_; |
---|
779 | } |
---|
780 | /// What has changed in model (only for masochistic users) |
---|
781 | inline int whatsChanged() const { |
---|
782 | return whatsChanged_; |
---|
783 | } |
---|
784 | inline void setWhatsChanged(int value) { |
---|
785 | whatsChanged_ = value; |
---|
786 | } |
---|
787 | /// Number of threads (not really being used) |
---|
788 | inline int numberThreads() const { |
---|
789 | return numberThreads_; |
---|
790 | } |
---|
791 | inline void setNumberThreads(int value) { |
---|
792 | numberThreads_ = value; |
---|
793 | } |
---|
794 | //@} |
---|
795 | /**@name Message handling */ |
---|
796 | //@{ |
---|
797 | /// Pass in Message handler (not deleted at end) |
---|
798 | void passInMessageHandler(CoinMessageHandler * handler); |
---|
799 | /// Pass in Message handler (not deleted at end) and return current |
---|
800 | CoinMessageHandler * pushMessageHandler(CoinMessageHandler * handler, |
---|
801 | bool & oldDefault); |
---|
802 | /// back to previous message handler |
---|
803 | void popMessageHandler(CoinMessageHandler * oldHandler, bool oldDefault); |
---|
804 | /// Set language |
---|
805 | void newLanguage(CoinMessages::Language language); |
---|
806 | inline void setLanguage(CoinMessages::Language language) { |
---|
807 | newLanguage(language); |
---|
808 | } |
---|
809 | /// Return handler |
---|
810 | inline CoinMessageHandler * messageHandler() const { |
---|
811 | return handler_; |
---|
812 | } |
---|
813 | /// Return messages |
---|
814 | inline CoinMessages messages() const { |
---|
815 | return messages_; |
---|
816 | } |
---|
817 | /// Return pointer to messages |
---|
818 | inline CoinMessages * messagesPointer() { |
---|
819 | return & messages_; |
---|
820 | } |
---|
821 | /// Return Coin messages |
---|
822 | inline CoinMessages coinMessages() const { |
---|
823 | return coinMessages_; |
---|
824 | } |
---|
825 | /// Return pointer to Coin messages |
---|
826 | inline CoinMessages * coinMessagesPointer() { |
---|
827 | return & coinMessages_; |
---|
828 | } |
---|
829 | /** Amount of print out: |
---|
830 | 0 - none |
---|
831 | 1 - just final |
---|
832 | 2 - just factorizations |
---|
833 | 3 - as 2 plus a bit more |
---|
834 | 4 - verbose |
---|
835 | above that 8,16,32 etc just for selective debug |
---|
836 | */ |
---|
837 | inline void setLogLevel(int value) { |
---|
838 | handler_->setLogLevel(value); |
---|
839 | } |
---|
840 | inline int logLevel() const { |
---|
841 | return handler_->logLevel(); |
---|
842 | } |
---|
843 | /// Return true if default handler |
---|
844 | inline bool defaultHandler() const { |
---|
845 | return defaultHandler_; |
---|
846 | } |
---|
847 | /// Pass in Event handler (cloned and deleted at end) |
---|
848 | void passInEventHandler(const ClpEventHandler * eventHandler); |
---|
849 | /// Event handler |
---|
850 | inline ClpEventHandler * eventHandler() const { |
---|
851 | return eventHandler_; |
---|
852 | } |
---|
853 | /// Thread specific random number generator |
---|
854 | inline CoinThreadRandom * randomNumberGenerator() { |
---|
855 | return &randomNumberGenerator_; |
---|
856 | } |
---|
857 | /// Thread specific random number generator |
---|
858 | inline CoinThreadRandom & mutableRandomNumberGenerator() { |
---|
859 | return randomNumberGenerator_; |
---|
860 | } |
---|
861 | /// Set seed for thread specific random number generator |
---|
862 | inline void setRandomSeed(int value) { |
---|
863 | randomNumberGenerator_.setSeed(value); |
---|
864 | } |
---|
865 | /// length of names (0 means no names0 |
---|
866 | inline int lengthNames() const { |
---|
867 | return lengthNames_; |
---|
868 | } |
---|
869 | #ifndef CLP_NO_STD |
---|
870 | /// length of names (0 means no names0 |
---|
871 | inline void setLengthNames(int value) { |
---|
872 | lengthNames_ = value; |
---|
873 | } |
---|
874 | /// Row names |
---|
875 | inline const std::vector<std::string> * rowNames() const { |
---|
876 | return &rowNames_; |
---|
877 | } |
---|
878 | inline const std::string& rowName(int iRow) const { |
---|
879 | return rowNames_[iRow]; |
---|
880 | } |
---|
881 | /// Return name or Rnnnnnnn |
---|
882 | std::string getRowName(int iRow) const; |
---|
883 | /// Column names |
---|
884 | inline const std::vector<std::string> * columnNames() const { |
---|
885 | return &columnNames_; |
---|
886 | } |
---|
887 | inline const std::string& columnName(int iColumn) const { |
---|
888 | return columnNames_[iColumn]; |
---|
889 | } |
---|
890 | /// Return name or Cnnnnnnn |
---|
891 | std::string getColumnName(int iColumn) const; |
---|
892 | #endif |
---|
893 | /// Objective methods |
---|
894 | inline ClpObjective * objectiveAsObject() const { |
---|
895 | return objective_; |
---|
896 | } |
---|
897 | void setObjective(ClpObjective * objective); |
---|
898 | inline void setObjectivePointer(ClpObjective * newobjective) { |
---|
899 | objective_ = newobjective; |
---|
900 | } |
---|
901 | /** Solve a problem with no elements - return status and |
---|
902 | dual and primal infeasibilites */ |
---|
903 | int emptyProblem(int * infeasNumber = NULL, double * infeasSum = NULL, bool printMessage = true); |
---|
904 | |
---|
905 | //@} |
---|
906 | |
---|
907 | /**@name Matrix times vector methods |
---|
908 | They can be faster if scalar is +- 1 |
---|
909 | These are covers so user need not worry about scaling |
---|
910 | Also for simplex I am not using basic/non-basic split */ |
---|
911 | //@{ |
---|
912 | /** Return <code>y + A * x * scalar</code> in <code>y</code>. |
---|
913 | @pre <code>x</code> must be of size <code>numColumns()</code> |
---|
914 | @pre <code>y</code> must be of size <code>numRows()</code> */ |
---|
915 | void times(double scalar, |
---|
916 | const double * x, double * y) const; |
---|
917 | /** Return <code>y + x * scalar * A</code> in <code>y</code>. |
---|
918 | @pre <code>x</code> must be of size <code>numRows()</code> |
---|
919 | @pre <code>y</code> must be of size <code>numColumns()</code> */ |
---|
920 | void transposeTimes(double scalar, |
---|
921 | const double * x, double * y) const ; |
---|
922 | //@} |
---|
923 | |
---|
924 | |
---|
925 | //--------------------------------------------------------------------------- |
---|
926 | /**@name Parameter set/get methods |
---|
927 | |
---|
928 | The set methods return true if the parameter was set to the given value, |
---|
929 | false otherwise. There can be various reasons for failure: the given |
---|
930 | parameter is not applicable for the solver (e.g., refactorization |
---|
931 | frequency for the volume algorithm), the parameter is not yet implemented |
---|
932 | for the solver or simply the value of the parameter is out of the range |
---|
933 | the solver accepts. If a parameter setting call returns false check the |
---|
934 | details of your solver. |
---|
935 | |
---|
936 | The get methods return true if the given parameter is applicable for the |
---|
937 | solver and is implemented. In this case the value of the parameter is |
---|
938 | returned in the second argument. Otherwise they return false. |
---|
939 | |
---|
940 | ** once it has been decided where solver sits this may be redone |
---|
941 | */ |
---|
942 | //@{ |
---|
943 | /// Set an integer parameter |
---|
944 | bool setIntParam(ClpIntParam key, int value) ; |
---|
945 | /// Set an double parameter |
---|
946 | bool setDblParam(ClpDblParam key, double value) ; |
---|
947 | #ifndef CLP_NO_STD |
---|
948 | /// Set an string parameter |
---|
949 | bool setStrParam(ClpStrParam key, const std::string & value); |
---|
950 | #endif |
---|
951 | // Get an integer parameter |
---|
952 | inline bool getIntParam(ClpIntParam key, int& value) const { |
---|
953 | if (key < ClpLastIntParam) { |
---|
954 | value = intParam_[key]; |
---|
955 | return true; |
---|
956 | } else { |
---|
957 | return false; |
---|
958 | } |
---|
959 | } |
---|
960 | // Get an double parameter |
---|
961 | inline bool getDblParam(ClpDblParam key, double& value) const { |
---|
962 | if (key < ClpLastDblParam) { |
---|
963 | value = dblParam_[key]; |
---|
964 | return true; |
---|
965 | } else { |
---|
966 | return false; |
---|
967 | } |
---|
968 | } |
---|
969 | #ifndef CLP_NO_STD |
---|
970 | // Get a string parameter |
---|
971 | inline bool getStrParam(ClpStrParam key, std::string& value) const { |
---|
972 | if (key < ClpLastStrParam) { |
---|
973 | value = strParam_[key]; |
---|
974 | return true; |
---|
975 | } else { |
---|
976 | return false; |
---|
977 | } |
---|
978 | } |
---|
979 | #endif |
---|
980 | /// Create C++ lines to get to current state |
---|
981 | void generateCpp( FILE * fp); |
---|
982 | /** For advanced options |
---|
983 | 1 - Don't keep changing infeasibility weight |
---|
984 | 2 - Keep nonLinearCost round solves |
---|
985 | 4 - Force outgoing variables to exact bound (primal) |
---|
986 | 8 - Safe to use dense initial factorization |
---|
987 | 16 -Just use basic variables for operation if column generation |
---|
988 | 32 -Create ray even in BAB |
---|
989 | 64 -Treat problem as feasible until last minute (i.e. minimize infeasibilities) |
---|
990 | 128 - Switch off all matrix sanity checks |
---|
991 | 256 - No row copy |
---|
992 | 512 - If not in values pass, solution guaranteed, skip as much as possible |
---|
993 | 1024 - In branch and bound |
---|
994 | 2048 - Don't bother to re-factorize if < 20 iterations |
---|
995 | 4096 - Skip some optimality checks |
---|
996 | 8192 - Do Primal when cleaning up primal |
---|
997 | 16384 - In fast dual (so we can switch off things) |
---|
998 | 32768 - called from Osi |
---|
999 | 65536 - keep arrays around as much as possible (also use maximumR/C) |
---|
1000 | 131072 - transposeTimes is -1.0 and can skip basic and fixed |
---|
1001 | 262144 - extra copy of scaled matrix |
---|
1002 | 524288 - Clp fast dual |
---|
1003 | 1048576 - don't need to finish dual (can return 3) |
---|
1004 | NOTE - many applications can call Clp but there may be some short cuts |
---|
1005 | which are taken which are not guaranteed safe from all applications. |
---|
1006 | Vetted applications will have a bit set and the code may test this |
---|
1007 | At present I expect a few such applications - if too many I will |
---|
1008 | have to re-think. It is up to application owner to change the code |
---|
1009 | if she/he needs these short cuts. I will not debug unless in Coin |
---|
1010 | repository. See COIN_CLP_VETTED comments. |
---|
1011 | 0x01000000 is Cbc (and in branch and bound) |
---|
1012 | 0x02000000 is in a different branch and bound |
---|
1013 | */ |
---|
1014 | inline unsigned int specialOptions() const { |
---|
1015 | return specialOptions_; |
---|
1016 | } |
---|
1017 | void setSpecialOptions(unsigned int value); |
---|
1018 | #define COIN_CBC_USING_CLP 0x01000000 |
---|
1019 | inline bool inCbcBranchAndBound() const { |
---|
1020 | return (specialOptions_ & COIN_CBC_USING_CLP) != 0; |
---|
1021 | } |
---|
1022 | //@} |
---|
1023 | |
---|
1024 | /**@name private or protected methods */ |
---|
1025 | //@{ |
---|
1026 | protected: |
---|
1027 | /// Does most of deletion (0 = all, 1 = most) |
---|
1028 | void gutsOfDelete(int type); |
---|
1029 | /** Does most of copying |
---|
1030 | If trueCopy 0 then just points to arrays |
---|
1031 | If -1 leaves as much as possible */ |
---|
1032 | void gutsOfCopy(const ClpModel & rhs, int trueCopy = 1); |
---|
1033 | /// gets lower and upper bounds on rows |
---|
1034 | void getRowBound(int iRow, double& lower, double& upper) const; |
---|
1035 | /// puts in format I like - 4 array matrix - may make row copy |
---|
1036 | void gutsOfLoadModel ( int numberRows, int numberColumns, |
---|
1037 | const double* collb, const double* colub, |
---|
1038 | const double* obj, |
---|
1039 | const double* rowlb, const double* rowub, |
---|
1040 | const double * rowObjective = NULL); |
---|
1041 | /// Does much of scaling |
---|
1042 | void gutsOfScaling(); |
---|
1043 | /// Objective value - always minimize |
---|
1044 | inline double rawObjectiveValue() const { |
---|
1045 | return objectiveValue_; |
---|
1046 | } |
---|
1047 | /// If we are using maximumRows_ and Columns_ |
---|
1048 | inline bool permanentArrays() const { |
---|
1049 | return (specialOptions_ & 65536) != 0; |
---|
1050 | } |
---|
1051 | /// Start using maximumRows_ and Columns_ |
---|
1052 | void startPermanentArrays(); |
---|
1053 | /// Stop using maximumRows_ and Columns_ |
---|
1054 | void stopPermanentArrays(); |
---|
1055 | /// Create row names as char ** |
---|
1056 | const char * const * rowNamesAsChar() const; |
---|
1057 | /// Create column names as char ** |
---|
1058 | const char * const * columnNamesAsChar() const; |
---|
1059 | /// Delete char * version of names |
---|
1060 | void deleteNamesAsChar(const char * const * names, int number) const; |
---|
1061 | /// On stopped - sets secondary status |
---|
1062 | void onStopped(); |
---|
1063 | //@} |
---|
1064 | |
---|
1065 | |
---|
1066 | ////////////////// data ////////////////// |
---|
1067 | protected: |
---|
1068 | |
---|
1069 | /**@name data */ |
---|
1070 | //@{ |
---|
1071 | /// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore |
---|
1072 | double optimizationDirection_; |
---|
1073 | /// Array of double parameters |
---|
1074 | double dblParam_[ClpLastDblParam]; |
---|
1075 | /// Objective value |
---|
1076 | double objectiveValue_; |
---|
1077 | /// Small element value |
---|
1078 | double smallElement_; |
---|
1079 | /// Scaling of objective |
---|
1080 | double objectiveScale_; |
---|
1081 | /// Scaling of rhs and bounds |
---|
1082 | double rhsScale_; |
---|
1083 | /// Number of rows |
---|
1084 | int numberRows_; |
---|
1085 | /// Number of columns |
---|
1086 | int numberColumns_; |
---|
1087 | /// Row activities |
---|
1088 | double * rowActivity_; |
---|
1089 | /// Column activities |
---|
1090 | double * columnActivity_; |
---|
1091 | /// Duals |
---|
1092 | double * dual_; |
---|
1093 | /// Reduced costs |
---|
1094 | double * reducedCost_; |
---|
1095 | /// Row lower |
---|
1096 | double* rowLower_; |
---|
1097 | /// Row upper |
---|
1098 | double* rowUpper_; |
---|
1099 | /// Objective |
---|
1100 | ClpObjective * objective_; |
---|
1101 | /// Row Objective (? sign) - may be NULL |
---|
1102 | double * rowObjective_; |
---|
1103 | /// Column Lower |
---|
1104 | double * columnLower_; |
---|
1105 | /// Column Upper |
---|
1106 | double * columnUpper_; |
---|
1107 | /// Packed matrix |
---|
1108 | ClpMatrixBase * matrix_; |
---|
1109 | /// Row copy if wanted |
---|
1110 | ClpMatrixBase * rowCopy_; |
---|
1111 | /// Scaled packed matrix |
---|
1112 | ClpPackedMatrix * scaledMatrix_; |
---|
1113 | /// Infeasible/unbounded ray |
---|
1114 | double * ray_; |
---|
1115 | /// Row scale factors for matrix |
---|
1116 | double * rowScale_; |
---|
1117 | /// Column scale factors |
---|
1118 | double * columnScale_; |
---|
1119 | /// Inverse row scale factors for matrix (end of rowScale_) |
---|
1120 | double * inverseRowScale_; |
---|
1121 | /// Inverse column scale factors for matrix (end of columnScale_) |
---|
1122 | double * inverseColumnScale_; |
---|
1123 | /** Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic, |
---|
1124 | 5 geometric on rows */ |
---|
1125 | int scalingFlag_; |
---|
1126 | /** Status (i.e. basis) Region. I know that not all algorithms need a status |
---|
1127 | array, but it made sense for things like crossover and put |
---|
1128 | all permanent stuff in one place. No assumption is made |
---|
1129 | about what is in status array (although it might be good to reserve |
---|
1130 | bottom 3 bits (i.e. 0-7 numeric) for classic status). This |
---|
1131 | is number of columns + number of rows long (in that order). |
---|
1132 | */ |
---|
1133 | unsigned char * status_; |
---|
1134 | /// Integer information |
---|
1135 | char * integerType_; |
---|
1136 | /// User pointer for whatever reason |
---|
1137 | void * userPointer_; |
---|
1138 | /// Trusted user pointer e.g. for heuristics |
---|
1139 | ClpTrustedData * trustedUserPointer_; |
---|
1140 | /// Array of integer parameters |
---|
1141 | int intParam_[ClpLastIntParam]; |
---|
1142 | /// Number of iterations |
---|
1143 | int numberIterations_; |
---|
1144 | /** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/ |
---|
1145 | int solveType_; |
---|
1146 | /** Whats changed since last solve. This is a work in progress |
---|
1147 | It is designed so careful people can make go faster. |
---|
1148 | It is only used when startFinishOptions used in dual or primal. |
---|
1149 | Bit 1 - number of rows/columns has not changed (so work arrays valid) |
---|
1150 | 2 - matrix has not changed |
---|
1151 | 4 - if matrix has changed only by adding rows |
---|
1152 | 8 - if matrix has changed only by adding columns |
---|
1153 | 16 - row lbs not changed |
---|
1154 | 32 - row ubs not changed |
---|
1155 | 64 - column objective not changed |
---|
1156 | 128 - column lbs not changed |
---|
1157 | 256 - column ubs not changed |
---|
1158 | 512 - basis not changed (up to user to set this to 0) |
---|
1159 | top bits may be used internally |
---|
1160 | shift by 65336 is 3 all same, 1 all except col bounds |
---|
1161 | */ |
---|
1162 | unsigned int whatsChanged_; |
---|
1163 | /// Status of problem |
---|
1164 | int problemStatus_; |
---|
1165 | /// Secondary status of problem |
---|
1166 | int secondaryStatus_; |
---|
1167 | /// length of names (0 means no names) |
---|
1168 | int lengthNames_; |
---|
1169 | /// Number of threads (not very operational) |
---|
1170 | int numberThreads_; |
---|
1171 | /** For advanced options |
---|
1172 | See get and set for meaning |
---|
1173 | */ |
---|
1174 | unsigned int specialOptions_; |
---|
1175 | /// Message handler |
---|
1176 | CoinMessageHandler * handler_; |
---|
1177 | /// Flag to say if default handler (so delete) |
---|
1178 | bool defaultHandler_; |
---|
1179 | /// Thread specific random number generator |
---|
1180 | CoinThreadRandom randomNumberGenerator_; |
---|
1181 | /// Event handler |
---|
1182 | ClpEventHandler * eventHandler_; |
---|
1183 | #ifndef CLP_NO_STD |
---|
1184 | /// Row names |
---|
1185 | std::vector<std::string> rowNames_; |
---|
1186 | /// Column names |
---|
1187 | std::vector<std::string> columnNames_; |
---|
1188 | #endif |
---|
1189 | /// Messages |
---|
1190 | CoinMessages messages_; |
---|
1191 | /// Coin messages |
---|
1192 | CoinMessages coinMessages_; |
---|
1193 | /// Maximum number of columns in model |
---|
1194 | int maximumColumns_; |
---|
1195 | /// Maximum number of rows in model |
---|
1196 | int maximumRows_; |
---|
1197 | /// Maximum number of columns (internal arrays) in model |
---|
1198 | int maximumInternalColumns_; |
---|
1199 | /// Maximum number of rows (internal arrays) in model |
---|
1200 | int maximumInternalRows_; |
---|
1201 | /// Base packed matrix |
---|
1202 | CoinPackedMatrix baseMatrix_; |
---|
1203 | /// Base row copy |
---|
1204 | CoinPackedMatrix baseRowCopy_; |
---|
1205 | /// Saved row scale factors for matrix |
---|
1206 | double * savedRowScale_; |
---|
1207 | /// Saved column scale factors |
---|
1208 | double * savedColumnScale_; |
---|
1209 | #ifndef CLP_NO_STD |
---|
1210 | /// Array of string parameters |
---|
1211 | std::string strParam_[ClpLastStrParam]; |
---|
1212 | #endif |
---|
1213 | //@} |
---|
1214 | }; |
---|
1215 | /** This is a tiny class where data can be saved round calls. |
---|
1216 | */ |
---|
1217 | class ClpDataSave { |
---|
1218 | |
---|
1219 | public: |
---|
1220 | /**@name Constructors and destructor |
---|
1221 | */ |
---|
1222 | //@{ |
---|
1223 | /// Default constructor |
---|
1224 | ClpDataSave ( ); |
---|
1225 | |
---|
1226 | /// Copy constructor. |
---|
1227 | ClpDataSave(const ClpDataSave &); |
---|
1228 | /// Assignment operator. This copies the data |
---|
1229 | ClpDataSave & operator=(const ClpDataSave & rhs); |
---|
1230 | /// Destructor |
---|
1231 | ~ClpDataSave ( ); |
---|
1232 | |
---|
1233 | //@} |
---|
1234 | |
---|
1235 | ////////////////// data ////////////////// |
---|
1236 | public: |
---|
1237 | |
---|
1238 | /**@name data - with same names as in other classes*/ |
---|
1239 | //@{ |
---|
1240 | double dualBound_; |
---|
1241 | double infeasibilityCost_; |
---|
1242 | double pivotTolerance_; |
---|
1243 | double zeroFactorizationTolerance_; |
---|
1244 | double zeroSimplexTolerance_; |
---|
1245 | double acceptablePivot_; |
---|
1246 | double objectiveScale_; |
---|
1247 | int sparseThreshold_; |
---|
1248 | int perturbation_; |
---|
1249 | int forceFactorization_; |
---|
1250 | int scalingFlag_; |
---|
1251 | unsigned int specialOptions_; |
---|
1252 | //@} |
---|
1253 | }; |
---|
1254 | |
---|
1255 | #endif |
---|