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