Debian Codegraph @

Osi/test/OsiTestSolverInterface.hpp

raw
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // This file is licensed under the terms of Eclipse Public License (EPL).
4
5 // this is a copy of OsiVolSolverInterface (trunk rev. 1466) renamed to OsiTestSolverInterface
6
7 #ifndef OsiTestSolverInterface_H
8 #define OsiTestSolverInterface_H
9
10 #include <string>
11
12 #include "OsiTestSolver.hpp"
13
14 #include "CoinPackedMatrix.hpp"
15
16 #include "OsiSolverInterface.hpp"
17
18 static const double OsiTestInfinity = 1.0e31;
19
20 //#############################################################################
21
22 /** Vol(ume) Solver Interface
23
24 Instantiation of OsiTestSolverInterface for the Volume Algorithm
25 */
26
27 class OsiTestSolverInterface :
28 virtual public OsiSolverInterface, public VOL_user_hooks {
29 friend void OsiTestSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
30
31 private:
32 class OsiVolMatrixOneMinusOne_ {
33 int majorDim_;
34 int minorDim_;
35
36 int plusSize_;
37 int * plusInd_;
38 int * plusStart_;
39 int * plusLength_;
40
41 int minusSize_;
42 int * minusInd_;
43 int * minusStart_;
44 int * minusLength_;
45
46 public:
47 OsiVolMatrixOneMinusOne_(const CoinPackedMatrix& m);
48 ~OsiVolMatrixOneMinusOne_();
49 void timesMajor(const double* x, double* y) const;
50 };
51
52 public:
53 //---------------------------------------------------------------------------
54 /**@name Solve methods */
55 //@{
56 /// Solve initial LP relaxation
57 virtual void initialSolve();
58
59 /// Resolve an LP relaxation after problem modification
60 virtual void resolve();
61
62 /// Invoke solver's built-in enumeration algorithm
63 virtual void branchAndBound() {
64 throw CoinError("Sorry, the Volume Algorithm doesn't implement B&B",
65 "branchAndBound", "OsiTestSolverInterface");
66 }
67 //@}
68
69 //---------------------------------------------------------------------------
70 /**@name Parameter set/get methods
71
72 The set methods return true if the parameter was set to the given value,
73 false otherwise. There can be various reasons for failure: the given
74 parameter is not applicable for the solver (e.g., refactorization
75 frequency for the volume algorithm), the parameter is not yet implemented
76 for the solver or simply the value of the parameter is out of the range
77 the solver accepts. If a parameter setting call returns false check the
78 details of your solver.
79
80 The get methods return true if the given parameter is applicable for the
81 solver and is implemented. In this case the value of the parameter is
82 returned in the second argument. Otherwise they return false.
83 */
84 //@{
85 // Set an integer parameter
86 bool setIntParam(OsiIntParam key, int value);
87 // Set an double parameter
88 bool setDblParam(OsiDblParam key, double value);
89 // Set a string parameter
90 bool setStrParam(OsiStrParam key, const std::string & value);
91 // Get an integer parameter
92 bool getIntParam(OsiIntParam key, int& value) const;
93 // Get an double parameter
94 bool getDblParam(OsiDblParam key, double& value) const;
95 // Get a string parameter
96 bool getStrParam(OsiStrParam key, std::string& value) const;
97 //@}
98
99 //---------------------------------------------------------------------------
100 ///@name Methods returning info on how the solution process terminated
101 //@{
102 /// Are there a numerical difficulties?
103 virtual bool isAbandoned() const;
104 /// Is optimality proven?
105 virtual bool isProvenOptimal() const;
106 /// Is primal infeasiblity proven?
107 virtual bool isProvenPrimalInfeasible() const;
108 /// Is dual infeasiblity proven?
109 virtual bool isProvenDualInfeasible() const;
110 /// Is the given primal objective limit reached?
111 virtual bool isPrimalObjectiveLimitReached() const;
112 /// Is the given dual objective limit reached?
113 virtual bool isDualObjectiveLimitReached() const;
114 /// Iteration limit reached?
115 virtual bool isIterationLimitReached() const;
116 //@}
117
118 //---------------------------------------------------------------------------
119 /**@name WarmStart related methods */
120 //@{
121 /*! \brief Get an empty warm start object
122
123 This routine returns an empty warm start object. Its purpose is
124 to provide a way to give a client a warm start object of the
125 appropriate type, which can resized and modified as desired.
126 */
127 virtual CoinWarmStart *getEmptyWarmStart () const ;
128
129 /// Get warmstarting information
130 virtual CoinWarmStart* getWarmStart() const;
131 /** Set warmstarting information. Return true/false depending on whether
132 the warmstart information was accepted or not. */
133 virtual bool setWarmStart(const CoinWarmStart* warmstart);
134 //@}
135
136 //---------------------------------------------------------------------------
137 /**@name Hotstart related methods (primarily used in strong branching). <br>
138 The user can create a hotstart (a snapshot) of the optimization process
139 then reoptimize over and over again always starting from there.<br>
140 <strong>NOTE</strong>: between hotstarted optimizations only
141 bound changes are allowed. */
142 //@{
143 /// Create a hotstart point of the optimization process
144 virtual void markHotStart();
145 /// Optimize starting from the hotstart
146 virtual void solveFromHotStart();
147 /// Delete the snapshot
148 virtual void unmarkHotStart();
149 //@}
150
151 //---------------------------------------------------------------------------
152 /**@name Problem information methods
153
154 These methods call the solver's query routines to return
155 information about the problem referred to by the current object.
156 Querying a problem that has no data associated with it result in
157 zeros for the number of rows and columns, and NULL pointers from
158 the methods that return vectors.
159
160 Const pointers returned from any data-query method are valid as
161 long as the data is unchanged and the solver is not called.
162 */
163 //@{
164 /**@name Methods related to querying the input data */
165 //@{
166 /// Get number of columns
167 virtual int getNumCols() const {
168 return rowMatrixCurrent_?
169 rowMatrix_.getNumCols() : colMatrix_.getNumCols(); }
170
171 /// Get number of rows
172 virtual int getNumRows() const {
173 return rowMatrixCurrent_?
174 rowMatrix_.getNumRows() : colMatrix_.getNumRows(); }
175
176 /// Get number of nonzero elements
177 virtual int getNumElements() const {
178 return rowMatrixCurrent_?
179 rowMatrix_.getNumElements() : colMatrix_.getNumElements(); }
180
181 /// Get pointer to array[getNumCols()] of column lower bounds
182 virtual const double * getColLower() const { return collower_; }
183
184 /// Get pointer to array[getNumCols()] of column upper bounds
185 virtual const double * getColUpper() const { return colupper_; }
186
187 /** Get pointer to array[getNumRows()] of row constraint senses.
188 <ul>
189 <li>'L' <= constraint
190 <li>'E' = constraint
191 <li>'G' >= constraint
192 <li>'R' ranged constraint
193 <li>'N' free constraint
194 </ul>
195 */
196 virtual const char * getRowSense() const { return rowsense_; }
197
198 /** Get pointer to array[getNumRows()] of rows right-hand sides
199 <ul>
200 <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i]
201 <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i]
202 <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i]
203 <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0
204 </ul>
205 */
206 virtual const double * getRightHandSide() const { return rhs_; }
207
208 /** Get pointer to array[getNumRows()] of row ranges.
209 <ul>
210 <li> if rowsense()[i] == 'R' then
211 rowrange()[i] == rowupper()[i] - rowlower()[i]
212 <li> if rowsense()[i] != 'R' then
213 rowrange()[i] is undefined
214 </ul>
215 */
216 virtual const double * getRowRange() const { return rowrange_; }
217
218 /// Get pointer to array[getNumRows()] of row lower bounds
219 virtual const double * getRowLower() const { return rowlower_; }
220
221 /// Get pointer to array[getNumRows()] of row upper bounds
222 virtual const double * getRowUpper() const { return rowupper_; }
223
224 /// Get pointer to array[getNumCols()] of objective function coefficients
225 virtual const double * getObjCoefficients() const { return objcoeffs_; }
226
227 /// Get objective function sense (1 for min (default), -1 for max)
228 virtual double getObjSense() const { return objsense_; }
229
230 /// Return true if column is continuous
231 virtual bool isContinuous(int colNumber) const;
232
233 #if 0
234 /// Return true if column is binary
235 virtual bool isBinary(int colNumber) const;
236
237 /** Return true if column is integer.
238 Note: This function returns true if the the column
239 is binary or a general integer.
240 */
241 virtual bool isInteger(int colNumber) const;
242
243 /// Return true if column is general integer
244 virtual bool isIntegerNonBinary(int colNumber) const;
245
246 /// Return true if column is binary and not fixed at either bound
247 virtual bool isFreeBinary(int colNumber) const;
248 #endif
249
250 /// Get pointer to row-wise copy of matrix
251 virtual const CoinPackedMatrix * getMatrixByRow() const;
252
253 /// Get pointer to column-wise copy of matrix
254 virtual const CoinPackedMatrix * getMatrixByCol() const;
255
256 /// Get solver's value for infinity
257 virtual double getInfinity() const { return OsiTestInfinity; }
258 //@}
259
260 /**@name Methods related to querying the solution */
261 //@{
262 /// Get pointer to array[getNumCols()] of primal solution vector
263 virtual const double * getColSolution() const { return colsol_; }
264
265 /// Get pointer to array[getNumRows()] of dual prices
266 virtual const double * getRowPrice() const { return rowprice_; }
267
268 /// Get a pointer to array[getNumCols()] of reduced costs
269 virtual const double * getReducedCost() const { return rc_; }
270
271 /** Get pointer to array[getNumRows()] of row activity levels (constraint
272 matrix times the solution vector */
273 virtual const double * getRowActivity() const { return lhs_; }
274
275 /// Get objective function value
276 virtual double getObjValue() const {
277 #if 1
278 // This does not pass unitTest if getObjValue is called before solve
279 return lagrangeanCost_;
280 #else
281 return OsiSolverInterface::getObjValue();
282 #endif
283 }
284
285 /** Get how many iterations it took to solve the problem (whatever
286 "iteration" mean to the solver. */
287 virtual int getIterationCount() const { return volprob_.iter(); }
288
289 /** Get as many dual rays as the solver can provide. (In case of proven
290 primal infeasibility there should be at least one.)
291
292 The first getNumRows() ray components will always be associated with
293 the row duals (as returned by getRowPrice()). If \c fullRay is true,
294 the final getNumCols() entries will correspond to the ray components
295 associated with the nonbasic variables. If the full ray is requested
296 and the method cannot provide it, it will throw an exception.
297
298 <strong>NOTE for implementers of solver interfaces:</strong> <br>
299 The double pointers in the vector should point to arrays of length
300 getNumRows() and they should be allocated via new[]. <br>
301
302 <strong>NOTE for users of solver interfaces:</strong> <br>
303 It is the user's responsibility to free the double pointers in the
304 vector using delete[].
305 */
306 virtual std::vector<double*> getDualRays(int maxNumRays,
307 bool fullRay = false) const;
308 /** Get as many primal rays as the solver can provide. (In case of proven
309 dual infeasibility there should be at least one.)
310
311 <strong>NOTE for implementers of solver interfaces:</strong> <br>
312 The double pointers in the vector should point to arrays of length
313 getNumCols() and they should be allocated via new[]. <br>
314
315 <strong>NOTE for users of solver interfaces:</strong> <br>
316 It is the user's responsibility to free the double pointers in the
317 vector using delete[].
318 */
319 virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
320
321 #if 0
322 /** Get indices of solution vector which are integer variables
323 presently at fractional values */
324 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
325 const;
326 #endif
327 //@}
328 //@}
329
330 //---------------------------------------------------------------------------
331
332 /**@name Problem modifying methods */
333 //@{
334 //-------------------------------------------------------------------------
335 /**@name Changing bounds on variables and constraints */
336 //@{
337 /** Set an objective function coefficient */
338 virtual void setObjCoeff( int elementIndex, double elementValue ) {
339 objcoeffs_[elementIndex] = elementValue;
340 }
341
342 using OsiSolverInterface::setColLower ;
343 /** Set a single column lower bound<br>
344 Use -COIN_DBL_MAX for -infinity. */
345 virtual void setColLower( int elementIndex, double elementValue ) {
346 collower_[elementIndex] = elementValue;
347 }
348
349 using OsiSolverInterface::setColUpper ;
350 /** Set a single column upper bound<br>
351 Use COIN_DBL_MAX for infinity. */
352 virtual void setColUpper( int elementIndex, double elementValue ) {
353 colupper_[elementIndex] = elementValue;
354 }
355
356 /** Set a single column lower and upper bound */
357 virtual void setColBounds( int elementIndex,
358 double lower, double upper ) {
359 collower_[elementIndex] = lower;
360 colupper_[elementIndex] = upper;
361 }
362
363 /** Set the bounds on a number of columns simultaneously<br>
364 The default implementation just invokes setColLower() and
365 setColUpper() over and over again.
366 @param indexFirst,indexLast pointers to the beginning and after the
367 end of the array of the indices of the variables whose
368 <em>either</em> bound changes
369 @param boundList the new lower/upper bound pairs for the variables
370 */
371 virtual void setColSetBounds(const int* indexFirst,
372 const int* indexLast,
373 const double* boundList);
374
375 /** Set a single row lower bound<br>
376 Use -COIN_DBL_MAX for -infinity. */
377 virtual void setRowLower( int elementIndex, double elementValue ) {
378 rowlower_[elementIndex] = elementValue;
379 convertBoundToSense(elementValue, rowupper_[elementIndex],
380 rowsense_[elementIndex], rhs_[elementIndex],
381 rowrange_[elementIndex]);
382 }
383
384 /** Set a single row upper bound<br>
385 Use COIN_DBL_MAX for infinity. */
386 virtual void setRowUpper( int elementIndex, double elementValue ) {
387 rowupper_[elementIndex] = elementValue;
388 convertBoundToSense(rowlower_[elementIndex], elementValue,
389 rowsense_[elementIndex], rhs_[elementIndex],
390 rowrange_[elementIndex]);
391 }
392
393 /** Set a single row lower and upper bound */
394 virtual void setRowBounds( int elementIndex,
395 double lower, double upper ) {
396 rowlower_[elementIndex] = lower;
397 rowupper_[elementIndex] = upper;
398 convertBoundToSense(lower, upper,
399 rowsense_[elementIndex], rhs_[elementIndex],
400 rowrange_[elementIndex]);
401 }
402
403 /** Set the type of a single row<br> */
404 virtual void setRowType(int index, char sense, double rightHandSide,
405 double range) {
406 rowsense_[index] = sense;
407 rhs_[index] = rightHandSide;
408 rowrange_[index] = range;
409 convertSenseToBound(sense, rightHandSide, range,
410 rowlower_[index], rowupper_[index]);
411 }
412
413 /** Set the bounds on a number of rows simultaneously<br>
414 The default implementation just invokes setRowLower() and
415 setRowUpper() over and over again.
416 @param indexFirst,indexLast pointers to the beginning and after the
417 end of the array of the indices of the constraints whose
418 <em>either</em> bound changes
419 @param boundList the new lower/upper bound pairs for the constraints
420 */
421 virtual void setRowSetBounds(const int* indexFirst,
422 const int* indexLast,
423 const double* boundList);
424
425 /** Set the type of a number of rows simultaneously<br>
426 The default implementation just invokes setRowType()
427 over and over again.
428 @param indexFirst,indexLast pointers to the beginning and after the
429 end of the array of the indices of the constraints whose
430 <em>any</em> characteristics changes
431 @param senseList the new senses
432 @param rhsList the new right hand sides
433 @param rangeList the new ranges
434 */
435 virtual void setRowSetTypes(const int* indexFirst,
436 const int* indexLast,
437 const char* senseList,
438 const double* rhsList,
439 const double* rangeList);
440 //@}
441
442 //-------------------------------------------------------------------------
443 /**@name Integrality related changing methods */
444 //@{
445 /** Set the index-th variable to be a continuous variable */
446 virtual void setContinuous(int index);
447 /** Set the index-th variable to be an integer variable */
448 virtual void setInteger(int index);
449 /** Set the variables listed in indices (which is of length len) to be
450 continuous variables */
451 virtual void setContinuous(const int* indices, int len);
452 /** Set the variables listed in indices (which is of length len) to be
453 integer variables */
454 virtual void setInteger(const int* indices, int len);
455 //@}
456
457 //-------------------------------------------------------------------------
458 /// Set objective function sense (1 for min (default), -1 for max,)
459 virtual void setObjSense(double s ) { objsense_ = s < 0 ? -1.0 : 1.0; }
460
461 /** Set the primal solution column values
462
463 colsol[numcols()] is an array of values of the problem column
464 variables. These values are copied to memory owned by the
465 solver object or the solver. They will be returned as the
466 result of colsol() until changed by another call to
467 setColsol() or by a call to any solver routine. Whether the
468 solver makes use of the solution in any way is
469 solver-dependent.
470 */
471 virtual void setColSolution(const double * colsol);
472
473 /** Set dual solution vector
474
475 rowprice[numrows()] is an array of values of the problem row
476 dual variables. These values are copied to memory owned by the
477 solver object or the solver. They will be returned as the
478 result of rowprice() until changed by another call to
479 setRowprice() or by a call to any solver routine. Whether the
480 solver makes use of the solution in any way is
481 solver-dependent.
482 */
483 virtual void setRowPrice(const double * rowprice);
484
485 //-------------------------------------------------------------------------
486 /**@name Methods to expand a problem.<br>
487 Note that if a column is added then by default it will correspond to a
488 continuous variable. */
489 //@{
490
491 using OsiSolverInterface::addCol ;
492 /** */
493 virtual void addCol(const CoinPackedVectorBase& vec,
494 const double collb, const double colub,
495 const double obj);
496
497 using OsiSolverInterface::addCols ;
498 /** */
499 virtual void addCols(const int numcols,
500 const CoinPackedVectorBase * const * cols,
501 const double* collb, const double* colub,
502 const double* obj);
503 #if 0
504 /** */
505 virtual void addCols(const CoinPackedMatrix& matrix,
506 const double* collb, const double* colub,
507 const double* obj);
508 #endif
509 /** */
510 virtual void deleteCols(const int num, const int * colIndices);
511
512 using OsiSolverInterface::addRow ;
513 /** */
514 virtual void addRow(const CoinPackedVectorBase& vec,
515 const double rowlb, const double rowub);
516 /** */
517 virtual void addRow(const CoinPackedVectorBase& vec,
518 const char rowsen, const double rowrhs,
519 const double rowrng);
520
521 using OsiSolverInterface::addRows ;
522 /** */
523 virtual void addRows(const int numrows,
524 const CoinPackedVectorBase * const * rows,
525 const double* rowlb, const double* rowub);
526 /** */
527 virtual void addRows(const int numrows,
528 const CoinPackedVectorBase * const * rows,
529 const char* rowsen, const double* rowrhs,
530 const double* rowrng);
531 #if 0
532 /** */
533 virtual void addRows(const CoinPackedMatrix& matrix,
534 const double* rowlb, const double* rowub);
535 /** */
536 virtual void addRows(const CoinPackedMatrix& matrix,
537 const char* rowsen, const double* rowrhs,
538 const double* rowrng);
539 #endif
540 /** */
541 virtual void deleteRows(const int num, const int * rowIndices);
542
543 //-----------------------------------------------------------------------
544 #if 0
545 /** Apply a collection of cuts.<br>
546 Only cuts which have an <code>effectiveness >= effectivenessLb</code>
547 are applied.
548 <ul>
549 <li> ReturnCode.numberIneffective() -- number of cuts which were
550 not applied because they had an
551 <code>effectiveness < effectivenessLb</code>
552 <li> ReturnCode.numberInconsistent() -- number of invalid cuts
553 <li> ReturnCode.numberInconsistentWrtIntegerModel() -- number of
554 cuts that are invalid with respect to this integer model
555 <li> ReturnCode.numberInfeasible() -- number of cuts that would
556 make this integer model infeasible
557 <li> ReturnCode.numberApplied() -- number of integer cuts which
558 were applied to the integer model
559 <li> cs.size() == numberIneffective() +
560 numberInconsistent() +
561 numberInconsistentWrtIntegerModel() +
562 numberInfeasible() +
563 nubmerApplied()
564 </ul>
565 */
566 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
567 double effectivenessLb = 0.0);
568 #endif
569 //@}
570 //@}
571
572 //---------------------------------------------------------------------------
573
574 protected:
575 /**@name Helper methods for problem input */
576 void initFromRlbRub(const int rownum,
577 const double* rowlb, const double* rowub);
578 void initFromRhsSenseRange(const int rownum, const char* rowsen,
579 const double* rowrhs, const double* rowrng);
580 void initFromClbCubObj(const int colnum, const double* collb,
581 const double* colub, const double* obj);
582 public:
583
584 /**@name Methods to input a problem */
585 //@{
586 /** Load in an problem by copying the arguments (the constraints on the
587 rows are given by lower and upper bounds). If a pointer is 0 then the
588 following values are the default:
589 <ul>
590 <li> <code>colub</code>: all columns have upper bound infinity
591 <li> <code>collb</code>: all columns have lower bound 0
592 <li> <code>rowub</code>: all rows have upper bound infinity
593 <li> <code>rowlb</code>: all rows have lower bound -infinity
594 <li> <code>obj</code>: all variables have 0 objective coefficient
595 </ul>
596 */
597 virtual void loadProblem(const CoinPackedMatrix& matrix,
598 const double* collb, const double* colub,
599 const double* obj,
600 const double* rowlb, const double* rowub);
601
602 /** Load in an problem by assuming ownership of the arguments (the
603 constraints on the rows are given by lower and upper bounds). For
604 default values see the previous method. <br>
605 <strong>WARNING</strong>: The arguments passed to this method will be
606 freed using the C++ <code>delete</code> and <code>delete[]</code>
607 functions.
608 */
609 virtual void assignProblem(CoinPackedMatrix*& matrix,
610 double*& collb, double*& colub, double*& obj,
611 double*& rowlb, double*& rowub);
612
613 /** Load in an problem by copying the arguments (the constraints on the
614 rows are given by sense/rhs/range triplets). If a pointer is 0 then the
615 following values are the default:
616 <ul>
617 <li> <code>colub</code>: all columns have upper bound infinity
618 <li> <code>collb</code>: all columns have lower bound 0
619 <li> <code>obj</code>: all variables have 0 objective coefficient
620 <li> <code>rowsen</code>: all rows are >=
621 <li> <code>rowrhs</code>: all right hand sides are 0
622 <li> <code>rowrng</code>: 0 for the ranged rows
623 </ul>
624 */
625 virtual void loadProblem(const CoinPackedMatrix& matrix,
626 const double* collb, const double* colub,
627 const double* obj,
628 const char* rowsen, const double* rowrhs,
629 const double* rowrng);
630
631 /** Load in an problem by assuming ownership of the arguments (the
632 constraints on the rows are given by sense/rhs/range triplets). For
633 default values see the previous method. <br>
634 <strong>WARNING</strong>: The arguments passed to this method will be
635 freed using the C++ <code>delete</code> and <code>delete[]</code>
636 functions.
637 */
638 virtual void assignProblem(CoinPackedMatrix*& matrix,
639 double*& collb, double*& colub, double*& obj,
640 char*& rowsen, double*& rowrhs,
641 double*& rowrng);
642
643 /** Just like the other loadProblem() methods except that the matrix is
644 given in a standard column major ordered format (without gaps). */
645 virtual void loadProblem(const int numcols, const int numrows,
646 const int* start, const int* index,
647 const double* value,
648 const double* collb, const double* colub,
649 const double* obj,
650 const double* rowlb, const double* rowub);
651
652 /** Just like the other loadProblem() methods except that the matrix is
653 given in a standard column major ordered format (without gaps). */
654 virtual void loadProblem(const int numcols, const int numrows,
655 const int* start, const int* index,
656 const double* value,
657 const double* collb, const double* colub,
658 const double* obj,
659 const char* rowsen, const double* rowrhs,
660 const double* rowrng);
661
662 using OsiSolverInterface::readMps ;
663 /** Read an mps file from the given filename */
664 virtual int readMps(const char *filename,
665 const char *extension = "mps");
666
667 /** Write the problem into an mps file of the given filename.
668 If objSense is non zero then -1.0 forces the code to write a
669 maximization objective and +1.0 to write a minimization one.
670 If 0.0 then solver can do what it wants */
671 virtual void writeMps(const char *filename,
672 const char *extension = "mps",
673 double objSense=0.0) const;
674 //@}
675
676 //---------------------------------------------------------------------------
677
678 /**@name OSL specific public interfaces */
679 //@{
680 /// Get pointer to Vol model
681 VOL_problem* volprob() { return &volprob_; }
682 //@}
683
684 //---------------------------------------------------------------------------
685
686 /**@name Constructors and destructors */
687 //@{
688 /// Default Constructor
689 OsiTestSolverInterface ();
690
691 /// Clone
692 virtual OsiSolverInterface * clone(bool copyData = true) const;
693
694 /// Copy constructor
695 OsiTestSolverInterface (const OsiTestSolverInterface &);
696
697 /// Assignment operator
698 OsiTestSolverInterface & operator=(const OsiTestSolverInterface& rhs);
699
700 /// Destructor
701 virtual ~OsiTestSolverInterface ();
702 //@}
703
704 //---------------------------------------------------------------------------
705
706 protected:
707 ///@name Protected methods
708 //@{
709 /** Apply a row cut (append to constraint matrix). */
710 virtual void applyRowCut(const OsiRowCut& rc);
711
712 /** Apply a column cut (adjust one or more bounds). */
713 virtual void applyColCut(const OsiColCut& cc);
714 //@}
715
716 //---------------------------------------------------------------------------
717
718 private:
719 /**@name Methods of <code>VOL_user_hooks</code> */
720 //@{
721 /// compute reduced costs
722 virtual int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
723 /// Solve the subproblem for the subgradient step.
724 virtual int solve_subproblem(const VOL_dvector& dual,
725 const VOL_dvector& rc,
726 double& lcost, VOL_dvector& x, VOL_dvector& v,
727 double& pcost);
728 /** Starting from the primal vector x, run a heuristic to produce
729 an integer solution. This is not done in LP solving. */
730 virtual int heuristics(const VOL_problem& /*p*/,
731 const VOL_dvector& /*x*/, double& heur_val) {
732 heur_val = COIN_DBL_MAX;
733 return 0;
734 }
735 //@}
736
737 //---------------------------------------------------------------------------
738
739 private:
740 /**@name Private helper methods */
741 //@{
742 /** Update the row ordered matrix from the column ordered one */
743 void updateRowMatrix_() const;
744 /** Update the column ordered matrix from the row ordered one */
745 void updateColMatrix_() const;
746
747 /** Test whether the Volume Algorithm can be applied to the given problem.
748 */
749 void checkData_() const;
750 /** Compute the reduced costs (<code>rc</code>) with respect to the dual
751 values given in <code>u</code>. */
752 void compute_rc_(const double* u, double* rc) const;
753 /** A method deleting every member data */
754 void gutsOfDestructor_();
755
756 /** A method allocating sufficient space for the rim vectors corresponding
757 to the rows. */
758 void rowRimAllocator_();
759 /** A method allocating sufficient space for the rim vectors corresponding
760 to the columns. */
761 void colRimAllocator_();
762
763 /** Reallocate the rim arrays corresponding to the rows. */
764 void rowRimResize_(const int newSize);
765 /** Reallocate the rim arrays corresponding to the columns. */
766 void colRimResize_(const int newSize);
767
768 /** For each row convert LB/UB style row constraints to sense/rhs style. */
769 void convertBoundsToSenses_();
770 /** For each row convert sense/rhs style row constraints to LB/UB style. */
771 void convertSensesToBounds_();
772
773 /** test whether the given matrix is 0/1/-1 entries only. */
774 bool test_zero_one_minusone_(const CoinPackedMatrix& m) const;
775 //@}
776
777 //---------------------------------------------------------------------------
778
779 private:
780
781 //---------------------------------------------------------------------------
782 /**@name The problem matrix in row and column ordered forms <br>
783 Note that at least one of the matrices is always current. */
784 //@{
785 /// A flag indicating whether the row ordered matrix is up-to-date
786 mutable bool rowMatrixCurrent_;
787 /// The problem matrix in a row ordered form
788 mutable CoinPackedMatrix rowMatrix_;
789 /// A flag indicating whether the column ordered matrix is up-to-date
790 mutable bool colMatrixCurrent_;
791 /// The problem matrix in a column ordered form
792 mutable CoinPackedMatrix colMatrix_;
793 //@}
794
795 //---------------------------------------------------------------------------
796 /**@name Data members used when 0/1/-1 matrix is detected */
797 //@{
798 /// An indicator whether the matrix is 0/1/-1
799 bool isZeroOneMinusOne_;
800 /// The row ordered matrix without the elements
801 OsiVolMatrixOneMinusOne_* rowMatrixOneMinusOne_;
802 /// The column ordered matrix without the elements
803 OsiVolMatrixOneMinusOne_* colMatrixOneMinusOne_;
804 //@}
805
806 //---------------------------------------------------------------------------
807 /**@name The rim vectors */
808 //@{
809 /// Pointer to dense vector of structural variable upper bounds
810 double *colupper_;
811 /// Pointer to dense vector of structural variable lower bounds
812 double *collower_;
813 /// Pointer to dense vector of bool to indicate if column is continuous
814 bool *continuous_;
815 /// Pointer to dense vector of slack variable upper bounds
816 double *rowupper_;
817 /// Pointer to dense vector of slack variable lower bounds
818 double *rowlower_;
819 /// Pointer to dense vector of row sense indicators
820 char *rowsense_;
821 /// Pointer to dense vector of row right-hand side values
822 double *rhs_;
823 /** Pointer to dense vector of slack upper bounds for range
824 constraints (undefined for non-range rows). */
825 double *rowrange_;
826 /// Pointer to dense vector of objective coefficients
827 double *objcoeffs_;
828 //@}
829
830 //---------------------------------------------------------------------------
831 /// Sense of objective (1 for min; -1 for max)
832 double objsense_;
833
834 //---------------------------------------------------------------------------
835 /**@name The solution */
836 //@{
837 /// Pointer to dense vector of primal structural variable values
838 double *colsol_;
839 /// Pointer to dense vector of dual row variable values
840 double *rowprice_;
841 /// Pointer to dense vector of reduced costs
842 double *rc_;
843 /// Pointer to dense vector of left hand sides (row activity levels)
844 double *lhs_;
845 /// The Lagrangean cost, a lower bound on the objective value
846 double lagrangeanCost_;
847 //@}
848
849 //---------------------------------------------------------------------------
850 /** An array to store the hotstart information between solveHotStart()
851 calls */
852 double *rowpriceHotStart_;
853
854 /// allocated size of the row related rim vectors
855 int maxNumrows_;
856 /// allocated size of the column related rim vectors
857 int maxNumcols_;
858
859 /// The volume solver
860 VOL_problem volprob_;
861 };
862
863 /** A function that tests the methods in the OsiTestSolverInterface class. */
864 void
865 OsiTestSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
866
867 #endif