Osi 0.108.9
Loading...
Searching...
No Matches
OsiSpxSolverInterface.hpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// name: OSI Interface for SoPlex >= 1.4.2c
3// authors: Tobias Pfender
4// Ambros Gleixner
5// Wei Huang
6// Konrad-Zuse-Zentrum Berlin (Germany)
7// email: pfender@zib.de
8// date: 01/16/2002
9// license: this file may be freely distributed under the terms of the EPL
10//-----------------------------------------------------------------------------
11// Copyright (C) 2002, Tobias Pfender, International Business Machines
12// Corporation and others. All Rights Reserved.
13// Last edit: $Id$
14
15#ifndef OsiSpxSolverInterface_H
16#define OsiSpxSolverInterface_H
17
18#include <string>
20#include "CoinWarmStartBasis.hpp"
21#include <soplex.h>
22
27 friend void OsiSpxSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir);
28
29public:
30 //---------------------------------------------------------------------------
33
34 virtual void initialSolve();
35
37 virtual void resolve();
38
40 virtual void branchAndBound();
42
43 //---------------------------------------------------------------------------
59 // Set an integer parameter
60 bool setIntParam(OsiIntParam key, int value);
61 // Set an double parameter
62 bool setDblParam(OsiDblParam key, double value);
63 // Get an integer parameter
64 bool getIntParam(OsiIntParam key, int &value) const;
65 // Get an double parameter
66 bool getDblParam(OsiDblParam key, double &value) const;
67 // Get a string parameter
68 bool getStrParam(OsiStrParam key, std::string &value) const;
69 // Set timelimit
70 void setTimeLimit(double value);
71 // Get timelimit
72 double getTimeLimit() const;
74
75 //---------------------------------------------------------------------------
77
78
79 virtual bool isAbandoned() const;
81 virtual bool isProvenOptimal() const;
83 virtual bool isProvenPrimalInfeasible() const;
85 virtual bool isProvenDualInfeasible() const;
86 // Is the given primal objective limit reached? - use implementation from OsiSolverInterface
88 virtual bool isDualObjectiveLimitReached() const;
90 virtual bool isIterationLimitReached() const;
92 virtual bool isTimeLimitReached() const;
94
95 //---------------------------------------------------------------------------
98
99 inline CoinWarmStart *getEmptyWarmStart() const
100 {
101 return (dynamic_cast< CoinWarmStart * >(new CoinWarmStartBasis()));
102 }
104 virtual CoinWarmStart *getWarmStart() const;
107 virtual bool setWarmStart(const CoinWarmStart *warmstart);
109
110 //---------------------------------------------------------------------------
117
118 virtual void markHotStart();
120 virtual void solveFromHotStart();
122 virtual void unmarkHotStart();
124
125 //---------------------------------------------------------------------------
140
141 virtual int getNumCols() const;
142
144 virtual int getNumRows() const;
145
147 virtual int getNumElements() const;
148
150 virtual const double *getColLower() const;
151
153 virtual const double *getColUpper() const;
154
164 virtual const char *getRowSense() const;
165
174 virtual const double *getRightHandSide() const;
175
184 virtual const double *getRowRange() const;
185
187 virtual const double *getRowLower() const;
188
190 virtual const double *getRowUpper() const;
191
193 virtual const double *getObjCoefficients() const;
194
196 virtual double getObjSense() const;
197
199 virtual bool isContinuous(int colNumber) const;
200
201#if 0
203 virtual bool isBinary(int columnNumber) const;
204
209 virtual bool isInteger(int columnNumber) const;
210
212 virtual bool isIntegerNonBinary(int columnNumber) const;
213
215 virtual bool isFreeBinary(int columnNumber) const;
216#endif
217
219 virtual const CoinPackedMatrix *getMatrixByRow() const;
220
222 virtual const CoinPackedMatrix *getMatrixByCol() const;
223
225 virtual double getInfinity() const;
227
231 virtual const double *getColSolution() const;
232
234 virtual const double *getRowPrice() const;
235
237 virtual const double *getReducedCost() const;
238
241 virtual const double *getRowActivity() const;
242
244 virtual double getObjValue() const;
245
248 virtual int getIterationCount() const;
249
267 virtual std::vector< double * > getDualRays(int maxNumRays,
268 bool fullRay = false) const;
280 virtual std::vector< double * > getPrimalRays(int maxNumRays) const;
281
282#if 0
285 virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
286 const;
287#endif
289
290
291 //---------------------------------------------------------------------------
292
295 //-------------------------------------------------------------------------
299 virtual void setObjCoeff(int elementIndex, double elementValue);
300
303 virtual void setColLower(int elementIndex, double elementValue);
304
307 virtual void setColUpper(int elementIndex, double elementValue);
308
312 virtual void setColBounds(int elementIndex,
313 double lower, double upper);
314
315#if 0 // we are using the default implementation of OsiSolverInterface
324 virtual void setColSetBounds(const int* indexFirst,
325 const int* indexLast,
326 const double* boundList);
327#endif
328
331 virtual void setRowLower(int elementIndex, double elementValue);
332
335 virtual void setRowUpper(int elementIndex, double elementValue);
336
340 virtual void setRowBounds(int elementIndex,
341 double lower, double upper);
342
344 virtual void setRowType(int index, char sense, double rightHandSide,
345 double range);
346
347#if 0 // we are using the default implementation of OsiSolverInterface
355 virtual void setRowSetBounds(const int* indexFirst,
356 const int* indexLast,
357 const double* boundList);
358
368 virtual void setRowSetTypes(const int* indexFirst,
369 const int* indexLast,
370 const char* senseList,
371 const double* rhsList,
372 const double* rangeList);
373#endif
375
376 //-------------------------------------------------------------------------
380 virtual void setContinuous(int index);
382 virtual void setInteger(int index);
383#if 0 // we are using the default implementation of OsiSolverInterface
386 virtual void setContinuous(const int* indices, int len);
389 virtual void setInteger(const int* indices, int len);
390#endif
392
393 //-------------------------------------------------------------------------
395 virtual void setObjSense(double s);
396
407 virtual void setColSolution(const double *colsol);
408
419 virtual void setRowPrice(const double *rowprice);
420
421 //-------------------------------------------------------------------------
427 virtual void addCol(const CoinPackedVectorBase &vec,
428 const double collb, const double colub,
429 const double obj);
430
431#if 0 // we are using the default implementation of OsiSolverInterface
433 virtual void addCols(const int numcols,
434 const CoinPackedVectorBase * const * cols,
435 const double* collb, const double* colub,
436 const double* obj);
437#endif
438
440 virtual void deleteCols(const int num, const int *colIndices);
441
443 virtual void addRow(const CoinPackedVectorBase &vec,
444 const double rowlb, const double rowub);
446 virtual void addRow(const CoinPackedVectorBase &vec,
447 const char rowsen, const double rowrhs,
448 const double rowrng);
449
450#if 0 // we are using the default implementation of OsiSolverInterface
452 virtual void addRows(const int numrows,
453 const CoinPackedVectorBase * const * rows,
454 const double* rowlb, const double* rowub);
456 virtual void addRows(const int numrows,
457 const CoinPackedVectorBase * const * rows,
458 const char* rowsen, const double* rowrhs,
459 const double* rowrng);
460#endif
461
463 virtual void deleteRows(const int num, const int *rowIndices);
464
465#if 0 // we are using the default implementation of OsiSolverInterface
466 //-----------------------------------------------------------------------
488 virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
489 double effectivenessLb = 0.0);
490#endif
492
493
494 //---------------------------------------------------------------------------
495
509 virtual void loadProblem(const CoinPackedMatrix &matrix,
510 const double *collb, const double *colub,
511 const double *obj,
512 const double *rowlb, const double *rowub);
513
521 virtual void assignProblem(CoinPackedMatrix *&matrix,
522 double *&collb, double *&colub, double *&obj,
523 double *&rowlb, double *&rowub);
524
537 virtual void loadProblem(const CoinPackedMatrix &matrix,
538 const double *collb, const double *colub,
539 const double *obj,
540 const char *rowsen, const double *rowrhs,
541 const double *rowrng);
542
550 virtual void assignProblem(CoinPackedMatrix *&matrix,
551 double *&collb, double *&colub, double *&obj,
552 char *&rowsen, double *&rowrhs,
553 double *&rowrng);
554
557 virtual void loadProblem(const int numcols, const int numrows,
558 const int *start, const int *index,
559 const double *value,
560 const double *collb, const double *colub,
561 const double *obj,
562 const double *rowlb, const double *rowub);
563
566 virtual void loadProblem(const int numcols, const int numrows,
567 const int *start, const int *index,
568 const double *value,
569 const double *collb, const double *colub,
570 const double *obj,
571 const char *rowsen, const double *rowrhs,
572 const double *rowrng);
573
575 virtual int readMps(const char *filename,
576 const char *extension = "mps");
577
582 virtual void writeMps(const char *filename,
583 const char *extension = "mps",
584 double objSense = 0.0) const;
586
587 //---------------------------------------------------------------------------
588
593
595 virtual OsiSolverInterface *clone(bool copyData = true) const;
596
599
602
606
631 soplex::SoPlex *getLpPtr(int keepCached = KEEPCACHED_NONE);
632
633 soplex::SPxOut *getSPxOut() { return spxout_; }
634
635protected:
639 virtual void applyRowCut(const OsiRowCut &rc);
640
644 virtual void applyColCut(const OsiColCut &cc);
646
650 soplex::SPxOut *spxout_;
652 soplex::SoPlex *soplex_;
654
655private:
658
661
664
667
670
672 void freeCachedData(int keepCached = KEEPCACHED_NONE);
673
677
681 soplex::DIdxSet *spxintvars_;
682
689
693#if SOPLEX_VERSION < 200
694 mutable soplex::DVector *obj_;
695#else
696 mutable soplex::Vector *obj_;
697#endif
698
700 mutable char *rowsense_;
701
703 mutable double *rhs_;
704
706 mutable double *rowrange_;
707
708#if SOPLEX_VERSION < 200
710 mutable soplex::DVector *colsol_;
711
713 mutable soplex::DVector *rowsol_;
714
716 mutable soplex::DVector *redcost_;
717
719 mutable soplex::DVector *rowact_;
720#else
722 mutable soplex::Vector *colsol_;
723
725 mutable soplex::Vector *rowsol_;
726
728 mutable soplex::Vector *redcost_;
729
731 mutable soplex::Vector *rowact_;
732#endif
733
735 mutable CoinPackedMatrix *matrixByRow_;
736
738 mutable CoinPackedMatrix *matrixByCol_;
739
740#if SOPLEX_VERSION >= 200
742 mutable soplex::Vector *lower_;
743
745 mutable soplex::Vector *upper_;
746
747 // Vector of row left-hand side values (unscaled)
748 mutable soplex::Vector *lhsVector_;
749
750 // Vector of row right-hand side values (unscaled)
751 mutable soplex::Vector *rhsVector_;
752#endif
754
755};
756
757//#############################################################################
759void OsiSpxSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir);
760
761#endif
762
763/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
764*/
std::vector< int > OsiVectorInt
Vector of int.
Column Cut Class.
Definition OsiColCut.hpp:23
Collections of row cuts and column cuts.
Definition OsiCuts.hpp:19
Row Cut Class.
Definition OsiRowCut.hpp:29
Internal class for obtaining status from the applyCuts method.
Abstract Base Class for describing an interface to a solver.
virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05) const
Get vector of indices of primal variables which are integer variables but have fractional values in t...
virtual bool isFreeBinary(int colIndex) const
Return true if the variable is binary and not fixed.
virtual bool isIntegerNonBinary(int colIndex) const
Return true if the variable is general integer.
virtual void addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
Add a set of rows (constraints) to the problem.
virtual ApplyCutsReturnCode applyCuts(const OsiCuts &cs, double effectivenessLb=0.0)
Apply a collection of cuts.
virtual bool isBinary(int colIndex) const
Return true if the variable is binary.
virtual void setRowSetTypes(const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList)
Set the type of a set of rows.
virtual bool isInteger(int colIndex) const
Return true if the variable is integer.
SoPlex Solver Interface Instantiation of OsiSpxSolverInterface for SoPlex.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
double getTimeLimit() const
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use COIN_DBL_MAX for infinity.
virtual void loadProblem(const int numcols, const int numrows, const int *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng)
Just like the other loadProblem() methods except that the matrix is given in a standard column major ...
virtual bool isTimeLimitReached() const
Time limit reached?
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
Add a column (primal variable) to the problem.
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -COIN_DBL_MAX for -infinity.
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
OsiSpxSolverInterface()
Default Constructor.
virtual int getNumRows() const
Get number of rows.
friend void OsiSpxSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSpxSolverInterface class.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver.
virtual void deleteRows(const int num, const int *rowIndices)
Delete a set of rows (constraints) from the problem.
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng)
Load in an problem by copying the arguments (the constraints on the rows are given by sense/rhs/range...
soplex::DVector * rowsol_
Pointer to dual solution vector.
CoinPackedMatrix * matrixByRow_
Pointer to row-wise copy of problem matrix coefficients.
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
void freeCachedRowRim()
free cached row rim vectors
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
bool setIntParam(OsiIntParam key, int value)
Set an integer parameter.
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut. Return true if cut was applied.
OsiSpxSolverInterface(const OsiSpxSolverInterface &)
Copy constructor.
virtual void deleteCols(const int num, const int *colIndices)
Remove a set of columns (primal variables) from the problem.
virtual int readMps(const char *filename, const char *extension="mps")
Read an mps file from the given filename.
soplex::SoPlex * getLpPtr(int keepCached=KEEPCACHED_NONE)
void freeCachedColRim()
free cached column rim vectors
double * rhs_
Pointer to dense vector of row right-hand side values.
soplex::DVector * rowact_
Pointer to row activity (slack) vector.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
OsiSpxSolverInterface & operator=(const OsiSpxSolverInterface &rhs)
Assignment operator.
CoinWarmStart * getEmptyWarmStart() const
Get empty warm start object.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Get as many dual rays as the solver can provide.
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
soplex::SoPlex * soplex_
SoPlex solver object.
soplex::DVector * obj_
Pointer to objective Vector.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
void setTimeLimit(double value)
bool getStrParam(OsiStrParam key, std::string &value) const
Get a string parameter.
virtual void setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound The default implementation just invokes setRowUower and setRo...
char * rowsense_
Pointer to dense vector of row sense indicators.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
double * rowrange_
Pointer to dense vector of slack upper bounds for range constraints (undefined for non-range rows)
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (bound adjustment).
void freeCachedData(int keepCached=KEEPCACHED_NONE)
free all cached data (except specified entries, see getLpPtr())
virtual double getInfinity() const
Get solver's value for infinity.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
bool getIntParam(OsiIntParam key, int &value) const
Get an integer parameter.
virtual void initialSolve()
Solve initial LP relaxation.
virtual int getNumCols() const
Get number of columns.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use COIN_DBL_MAX for infinity.
virtual void unmarkHotStart()
Delete the snapshot.
void freeCachedResults()
free cached result vectors
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
soplex::DVector * redcost_
Pointer to reduced cost vector.
virtual void addRow(const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng)
Add a row (constraint) to the problem.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
soplex::SPxOut * spxout_
SoPlex output object.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
void freeAllMemory()
free all allocated memory
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
Add a row (constraint) to the problem.
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
Write the problem into an mps file of the given filename.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual void resolve()
Resolve an LP relaxation after problem modification.
soplex::DVector * colsol_
Pointer to primal solution vector.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
void * hotStartCStat_
Hotstart information.
void freeCachedMatrix()
free cached matrices
@ KEEPCACHED_MATRIX
problem matrix: matrix ordered by column and by row
@ KEEPCACHED_ALL
keep all cached data (similar to getMutableLpPtr())
@ FREECACHED_COLUMN
free only cached column and LP solution information
@ FREECACHED_RESULTS
free only cached LP solution information
@ FREECACHED_MATRIX
free only cached matrix and LP solution information
@ KEEPCACHED_PROBLEM
only discard cached LP solution
@ KEEPCACHED_NONE
discard all cached data (default)
@ FREECACHED_ROW
free only cached row and LP solution information
@ KEEPCACHED_ROW
row information: right hand sides, ranges and senses, lower and upper bounds for row
@ KEEPCACHED_RESULTS
LP solution: primal and dual solution, reduced costs, row activities.
@ KEEPCACHED_COLUMN
column information: objective values, lower and upper bounds, variable types
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng)
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by s...
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound The default implementation just invokes setColLower and se...
virtual bool isProvenOptimal() const
Is optimality proven?
virtual int getNumElements() const
Get number of nonzero elements.
virtual void solveFromHotStart()
Optimize starting from the hotstart.
bool getDblParam(OsiDblParam key, double &value) const
Get a double parameter.
CoinPackedMatrix * matrixByCol_
Pointer to row-wise copy of problem matrix coefficients.
virtual double getObjValue() const
Get objective function value.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub)
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by l...
virtual void loadProblem(const int numcols, const int numrows, const int *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Just like the other loadProblem() methods except that the matrix is given in a standard column major ...
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
soplex::DIdxSet * spxintvars_
indices of integer variables
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
bool setDblParam(OsiDblParam key, double value)
Set a double parameter.
virtual ~OsiSpxSolverInterface()
Destructor.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -COIN_DBL_MAX for -infinity.
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.