1 | /* $Id: CbcHeuristicDive.hpp 1252 2009-10-20 09:22:24Z stefan $ */ |
---|
2 | // Copyright (C) 2008, International Business Machines |
---|
3 | // Corporation and others. All Rights Reserved. |
---|
4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
---|
5 | |
---|
6 | #ifndef CbcHeuristicDive_H |
---|
7 | #define CbcHeuristicDive_H |
---|
8 | |
---|
9 | #include "CbcHeuristic.hpp" |
---|
10 | struct PseudoReducedCost { |
---|
11 | int var; |
---|
12 | double pseudoRedCost; |
---|
13 | }; |
---|
14 | |
---|
15 | |
---|
16 | /** Dive class |
---|
17 | */ |
---|
18 | |
---|
19 | class CbcHeuristicDive : public CbcHeuristic { |
---|
20 | public: |
---|
21 | |
---|
22 | // Default Constructor |
---|
23 | CbcHeuristicDive (); |
---|
24 | |
---|
25 | // Constructor with model - assumed before cuts |
---|
26 | CbcHeuristicDive (CbcModel & model); |
---|
27 | |
---|
28 | // Copy constructor |
---|
29 | CbcHeuristicDive ( const CbcHeuristicDive &); |
---|
30 | |
---|
31 | // Destructor |
---|
32 | ~CbcHeuristicDive (); |
---|
33 | |
---|
34 | /// Clone |
---|
35 | virtual CbcHeuristicDive * clone() const = 0; |
---|
36 | |
---|
37 | /// Assignment operator |
---|
38 | CbcHeuristicDive & operator=(const CbcHeuristicDive& rhs); |
---|
39 | |
---|
40 | /// Create C++ lines to get to current state |
---|
41 | virtual void generateCpp( FILE * ) {} |
---|
42 | |
---|
43 | /// Create C++ lines to get to current state - does work for base class |
---|
44 | void generateCpp( FILE * fp, const char * heuristic); |
---|
45 | |
---|
46 | /// Resets stuff if model changes |
---|
47 | virtual void resetModel(CbcModel * model); |
---|
48 | |
---|
49 | /// update model (This is needed if cliques update matrix etc) |
---|
50 | virtual void setModel(CbcModel * model); |
---|
51 | |
---|
52 | // REMLOVE using CbcHeuristic::solution ; |
---|
53 | /** returns 0 if no solution, 1 if valid solution |
---|
54 | with better objective value than one passed in |
---|
55 | Sets solution values if good, sets objective value (only if good) |
---|
56 | This is called after cuts have been added - so can not add cuts |
---|
57 | This does Fractional Diving |
---|
58 | */ |
---|
59 | virtual int solution(double & objectiveValue, |
---|
60 | double * newSolution); |
---|
61 | |
---|
62 | /// Validate model i.e. sets when_ to 0 if necessary (may be NULL) |
---|
63 | virtual void validate(); |
---|
64 | |
---|
65 | /// Select candidate binary variables for fixing |
---|
66 | void selectBinaryVariables(); |
---|
67 | |
---|
68 | /// Set percentage of integer variables to fix at bounds |
---|
69 | void setPercentageToFix(double value) { |
---|
70 | percentageToFix_ = value; |
---|
71 | } |
---|
72 | |
---|
73 | /// Set maximum number of iterations |
---|
74 | void setMaxIterations(int value) { |
---|
75 | maxIterations_ = value; |
---|
76 | } |
---|
77 | |
---|
78 | /// Set maximum number of simplex iterations |
---|
79 | void setMaxSimplexIterations(int value) { |
---|
80 | maxSimplexIterations_ = value; |
---|
81 | } |
---|
82 | |
---|
83 | /// Set maximum number of simplex iterations at root node |
---|
84 | void setMaxSimplexIterationsAtRoot(int value) { |
---|
85 | maxSimplexIterationsAtRoot_ = value; |
---|
86 | } |
---|
87 | |
---|
88 | /// Set maximum time allowed |
---|
89 | void setMaxTime(double value) { |
---|
90 | maxTime_ = value; |
---|
91 | } |
---|
92 | |
---|
93 | /// Tests if the heuristic can run |
---|
94 | virtual bool canHeuristicRun(); |
---|
95 | |
---|
96 | /** Selects the next variable to branch on |
---|
97 | Returns true if all the fractional variables can be trivially |
---|
98 | rounded. Returns false, if there is at least one fractional variable |
---|
99 | that is not trivially roundable. In this case, the bestColumn |
---|
100 | returned will not be trivially roundable. |
---|
101 | */ |
---|
102 | virtual bool selectVariableToBranch(OsiSolverInterface* solver, |
---|
103 | const double* newSolution, |
---|
104 | int& bestColumn, |
---|
105 | int& bestRound) = 0; |
---|
106 | /** Initializes any data which is going to be used repeatedly |
---|
107 | in selectVariableToBranch */ |
---|
108 | virtual void initializeData() {} |
---|
109 | |
---|
110 | /// Perform reduced cost fixing on integer variables |
---|
111 | int reducedCostFix (OsiSolverInterface* solver); |
---|
112 | /// Fix other variables at bounds |
---|
113 | virtual int fixOtherVariables(OsiSolverInterface * solver, |
---|
114 | const double * solution, |
---|
115 | PseudoReducedCost * candidate, |
---|
116 | const double * random); |
---|
117 | |
---|
118 | protected: |
---|
119 | // Data |
---|
120 | |
---|
121 | // Original matrix by column |
---|
122 | CoinPackedMatrix matrix_; |
---|
123 | |
---|
124 | // Original matrix by |
---|
125 | CoinPackedMatrix matrixByRow_; |
---|
126 | |
---|
127 | // Down locks |
---|
128 | unsigned short * downLocks_; |
---|
129 | |
---|
130 | // Up locks |
---|
131 | unsigned short * upLocks_; |
---|
132 | |
---|
133 | /// Extra down array (number Integers long) |
---|
134 | double * downArray_; |
---|
135 | |
---|
136 | /// Extra up array (number Integers long) |
---|
137 | double * upArray_; |
---|
138 | |
---|
139 | // Indexes of binary variables with 0 objective coefficient |
---|
140 | // and in variable bound constraints |
---|
141 | std::vector<int> binVarIndex_; |
---|
142 | |
---|
143 | // Indexes of variable bound rows for each binary variable |
---|
144 | std::vector<int> vbRowIndex_; |
---|
145 | |
---|
146 | // Percentage of integer variables to fix at bounds |
---|
147 | double percentageToFix_; |
---|
148 | |
---|
149 | // Maximum number of major iterations |
---|
150 | int maxIterations_; |
---|
151 | |
---|
152 | // Maximum number of simplex iterations |
---|
153 | int maxSimplexIterations_; |
---|
154 | |
---|
155 | // Maximum number of simplex iterations at root node |
---|
156 | int maxSimplexIterationsAtRoot_; |
---|
157 | |
---|
158 | // Maximum time allowed |
---|
159 | double maxTime_; |
---|
160 | |
---|
161 | }; |
---|
162 | #endif |
---|
163 | |
---|