1 | // Copyright (C) 2006, International Business Machines |
2 | // Corporation and others. All Rights Reserved. |
3 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
4 | |
5 | #ifndef OsiAuxInfo_H |
6 | #define OsiAuxInfo_H |
7 | |
8 | class OsiSolverInterface; |
9 | |
10 | //############################################################################# |
11 | /** This class allows for a more structured use of algorithmic tweaking to |
12 | an OsiSolverInterface. It is designed to replace the simple use of |
13 | appData_ pointer. |
14 | |
15 | This has been done to make it easier to use NonLinear solvers and other |
16 | exotic beasts in a branch and bound mode. After this class definition |
17 | there is one for a derived class for just such a purpose. |
18 | |
19 | */ |
20 | |
21 | class OsiAuxInfo { |
22 | public: |
23 | // Default Constructor |
24 | OsiAuxInfo (void * appData = NULL); |
25 | |
26 | // Copy Constructor |
27 | OsiAuxInfo (const OsiAuxInfo & rhs); |
28 | // Destructor |
29 | virtual ~OsiAuxInfo(); |
30 | |
31 | /// Clone |
32 | virtual OsiAuxInfo * clone() const; |
33 | /// Assignment operator |
34 | OsiAuxInfo & operator=(const OsiAuxInfo& rhs); |
35 | |
36 | /// Get application data |
37 | inline void * getApplicationData() const |
38 | { return appData_;} |
39 | protected: |
40 | /// Pointer to user-defined data structure |
41 | void * appData_; |
42 | }; |
43 | //############################################################################# |
44 | /** This class allows for the use of more exotic solvers e.g. Non-Linear or Volume. |
45 | |
46 | You can derive from this although at present I can't see the need. |
47 | */ |
48 | |
49 | class OsiBabSolver : public OsiAuxInfo { |
50 | public: |
51 | // Default Constructor |
52 | OsiBabSolver (int solverType=0); |
53 | |
54 | // Copy Constructor |
55 | OsiBabSolver (const OsiBabSolver & rhs); |
56 | // Destructor |
57 | virtual ~OsiBabSolver(); |
58 | |
59 | /// Clone |
60 | virtual OsiAuxInfo * clone() const; |
61 | /// Assignment operator |
62 | OsiBabSolver & operator=(const OsiBabSolver& rhs); |
63 | |
64 | /// Update solver |
65 | inline void setSolver(const OsiSolverInterface * solver) |
66 | { solver_ = solver;} |
67 | /// Update solver |
68 | inline void setSolver(const OsiSolverInterface & solver) |
69 | { solver_ = &solver;} |
70 | |
71 | /** returns 0 if no heuristic solution, 1 if valid solution |
72 | with better objective value than one passed in |
73 | Sets solution values if good, sets objective value |
74 | numberColumns is size of newSolution |
75 | */ |
76 | int solution(double & objectiveValue, |
77 | double * newSolution, int numberColumns); |
78 | /** Set solution and objective value. |
79 | Number of columns and optimization direction taken from current solver. |
80 | Size of solution is numberColumns (may be padded or truncated in function) */ |
81 | void setSolution(const double * solution, int numberColumns, double objectiveValue); |
82 | |
83 | /** returns true if the object stores a solution, false otherwise. If there |
84 | is a solution then solutionValue and solution will be filled out as well. |
85 | In that case the user needs to allocate solution to be a big enough |
86 | array. |
87 | */ |
88 | bool hasSolution(double & solutionValue, double * solution); |
89 | |
90 | /** Sets solver type |
91 | 0 - normal LP solver |
92 | 1 - DW - may also return heuristic solutions |
93 | 2 - NLP solver or similar - can't compute objective value just from solution |
94 | check solver to see if feasible and what objective value is |
95 | - may also return heuristic solution |
96 | 3 - NLP solver or similar - can't compute objective value just from solution |
97 | check this (rather than solver) to see if feasible and what objective value is. |
98 | Using Outer Approximation so called lp based |
99 | - may also return heuristic solution |
100 | 4 - normal solver but cuts are needed for integral solution |
101 | */ |
102 | inline void setSolverType(int value) |
103 | { solverType_=value;} |
104 | /** gets solver type |
105 | 0 - normal LP solver |
106 | 1 - DW - may also return heuristic solutions |
107 | 2 - NLP solver or similar - can't compute objective value just from solution |
108 | check this (rather than solver) to see if feasible and what objective value is |
109 | - may also return heuristic solution |
110 | 3 - NLP solver or similar - can't compute objective value just from solution |
111 | check this (rather than solver) to see if feasible and what objective value is. |
112 | Using Outer Approximation so called lp based |
113 | - may also return heuristic solution |
114 | 4 - normal solver but cuts are needed for integral solution |
115 | */ |
116 | inline int solverType() const |
117 | { return solverType_;} |
118 | /** Return true if getting solution may add cuts so hot start etc will |
119 | be obsolete */ |
120 | inline bool solutionAddsCuts() const |
121 | { return solverType_==3;} |
122 | /// Return true if we should try cuts at root even if looks satisfied |
123 | inline bool alwaysTryCutsAtRootNode() const |
124 | { return solverType_==4;} |
125 | /** Returns true if can use solver objective or feasible values, |
126 | otherwise use mipBound etc */ |
127 | inline bool solverAccurate() const |
128 | { return solverType_==0||solverType_==2||solverType_==4;} |
129 | /// Returns true if can use reduced costs for fixing |
130 | inline bool reducedCostsAccurate() const |
131 | { return solverType_==0||solverType_==4;} |
132 | /// Get objective (well mip bound) |
133 | double mipBound() const; |
134 | /// Returns true if node feasible |
135 | bool mipFeasible() const; |
136 | /// Set mip bound (only used for some solvers) |
137 | inline void setMipBound(double value) |
138 | { mipBound_ = value;} |
139 | /// Get objective value of saved solution |
140 | inline double bestObjectiveValue() const |
141 | { return bestObjectiveValue_;} |
142 | /// Says whether we want to try cuts at all |
143 | inline bool tryCuts() const |
144 | { return solverType_!=2;} |
145 | /// Says whether we have a warm start (so can do strong branching) |
146 | inline bool warmStart() const |
147 | { return solverType_!=2;} |
148 | /** Get bit mask for odd actions of solvers |
149 | 1 - solution or bound arrays may move in mysterious ways e.g. cplex |
150 | 2 - solver may want bounds before branch |
151 | */ |
152 | inline int () const |
153 | { return extraCharacteristics_;} |
154 | /** Set bit mask for odd actions of solvers |
155 | 1 - solution or bound arrays may move in mysterious ways e.g. cplex |
156 | 2 - solver may want bounds before branch |
157 | */ |
158 | inline void (int value) |
159 | { extraCharacteristics_=value;} |
160 | /// Pointer to lower bounds before branch (only if extraCharacteristics set) |
161 | inline const double * beforeLower() const |
162 | { return beforeLower_;} |
163 | /// Set pointer to lower bounds before branch (only if extraCharacteristics set) |
164 | inline void setBeforeLower(const double * array) |
165 | { beforeLower_ = array;} |
166 | /// Pointer to upper bounds before branch (only if extraCharacteristics set) |
167 | inline const double * beforeUpper() const |
168 | { return beforeUpper_;} |
169 | /// Set pointer to upper bounds before branch (only if extraCharacteristics set) |
170 | inline void setBeforeUpper(const double * array) |
171 | { beforeUpper_ = array;} |
172 | protected: |
173 | /// Objective value of best solution (if there is one) (minimization) |
174 | double bestObjectiveValue_; |
175 | /// Current lower bound on solution ( if > 1.0e50 infeasible) |
176 | double mipBound_; |
177 | /// Solver to use for getting/setting solutions etc |
178 | const OsiSolverInterface * solver_; |
179 | /// Best integer feasible solution |
180 | double * bestSolution_; |
181 | /// Pointer to lower bounds before branch (only if extraCharacteristics set) |
182 | const double * beforeLower_; |
183 | /// Pointer to upper bounds before branch (only if extraCharacteristics set) |
184 | const double * beforeUpper_; |
185 | /** Solver type |
186 | 0 - normal LP solver |
187 | 1 - DW - may also return heuristic solutions |
188 | 2 - NLP solver or similar - can't compute objective value just from solution |
189 | check this (rather than solver) to see if feasible and what objective value is |
190 | - may also return heuristic solution |
191 | 3 - NLP solver or similar - can't compute objective value just from solution |
192 | check this (rather than solver) to see if feasible and what objective value is. |
193 | Using Outer Approximation so called lp based |
194 | - may also return heuristic solution |
195 | */ |
196 | int solverType_; |
197 | /// Size of solution |
198 | int sizeSolution_; |
199 | /** Bit mask for odd actions of solvers |
200 | 1 - solution or bound arrays may move in mysterious ways e.g. cplex |
201 | 2 - solver may want bounds before branch |
202 | */ |
203 | int ; |
204 | }; |
205 | |
206 | #endif |
207 | |