source: trunk/Cbc/src/CbcHeuristicDive.hpp @ 2093

Last change on this file since 2093 was 2093, checked in by forrest, 4 years ago

changes for diving heuristic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: CbcHeuristicDive.hpp 2093 2014-11-06 16:17:38Z forrest $ */
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"
10class CbcSubProblem;
11class OsiRowCut;
12struct PseudoReducedCost {
13    int var;
14    double pseudoRedCost;
15};
16
17
18/** Dive class
19 */
20
21class CbcHeuristicDive : public CbcHeuristic {
22public:
23
24    // Default Constructor
25    CbcHeuristicDive ();
26
27    // Constructor with model - assumed before cuts
28    CbcHeuristicDive (CbcModel & model);
29
30    // Copy constructor
31    CbcHeuristicDive ( const CbcHeuristicDive &);
32
33    // Destructor
34    ~CbcHeuristicDive ();
35
36    /// Clone
37    virtual CbcHeuristicDive * clone() const = 0;
38
39    /// Assignment operator
40    CbcHeuristicDive & operator=(const CbcHeuristicDive& rhs);
41
42    /// Create C++ lines to get to current state
43    virtual void generateCpp( FILE * ) {}
44
45    /// Create C++ lines to get to current state - does work for base class
46    void generateCpp( FILE * fp, const char * heuristic);
47
48    /// Resets stuff if model changes
49    virtual void resetModel(CbcModel * model);
50
51    /// update model (This is needed if cliques update matrix etc)
52    virtual void setModel(CbcModel * model);
53
54    //  REMLOVE using CbcHeuristic::solution ;
55    /** returns 0 if no solution, 1 if valid solution
56        with better objective value than one passed in
57        Sets solution values if good, sets objective value (only if good)
58        This is called after cuts have been added - so can not add cuts
59        This does Fractional Diving
60    */
61    virtual int solution(double & objectiveValue,
62                         double * newSolution);
63    /// inner part of dive
64    int solution(double & objectiveValue, int & numberNodes,
65                 int & numberCuts, OsiRowCut ** cuts,
66                 CbcSubProblem ** & nodes,
67                 double * newSolution);
68    /** returns 0 if no solution, 1 if valid solution
69        with better objective value than one passed in
70        also returns list of nodes
71        This does Fractional Diving
72    */
73    int fathom(CbcModel * model, int & numberNodes,CbcSubProblem ** & nodes);
74
75    /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
76    virtual void validate();
77
78    /// Sets priorities if any
79    void setPriorities();
80
81    /// Select candidate binary variables for fixing
82    void selectBinaryVariables();
83
84    /// Set percentage of integer variables to fix at bounds
85    void setPercentageToFix(double value) {
86        percentageToFix_ = value;
87    }
88
89    /// Set maximum number of iterations
90    void setMaxIterations(int value) {
91        maxIterations_ = value;
92    }
93
94    /// Set maximum number of simplex iterations
95    void setMaxSimplexIterations(int value) {
96        maxSimplexIterations_ = value;
97    }
98    /// Get maximum number of simplex iterations
99    inline int maxSimplexIterations() const {
100        return maxSimplexIterations_;
101    }
102
103    /// Set maximum number of simplex iterations at root node
104    void setMaxSimplexIterationsAtRoot(int value) {
105        maxSimplexIterationsAtRoot_ = value;
106    }
107
108    /// Set maximum time allowed
109    void setMaxTime(double value) {
110        maxTime_ = value;
111    }
112
113    /// Tests if the heuristic can run
114    virtual bool canHeuristicRun();
115
116    /** Selects the next variable to branch on
117        Returns true if all the fractional variables can be trivially
118        rounded. Returns false, if there is at least one fractional variable
119        that is not trivially roundable. In this case, the bestColumn
120        returned will not be trivially roundable.
121    */
122    virtual bool selectVariableToBranch(OsiSolverInterface* solver,
123                                        const double* newSolution,
124                                        int& bestColumn,
125                                        int& bestRound) = 0;
126    /** Initializes any data which is going to be used repeatedly
127        in selectVariableToBranch */
128    virtual void initializeData() {}
129
130    /// Perform reduced cost fixing on integer variables
131    int reducedCostFix (OsiSolverInterface* solver);
132    /// Fix other variables at bounds
133    virtual int fixOtherVariables(OsiSolverInterface * solver,
134                                  const double * solution,
135                                  PseudoReducedCost * candidate,
136                                  const double * random);
137
138protected:
139    // Data
140
141    // Original matrix by column
142    CoinPackedMatrix matrix_;
143
144    // Original matrix by
145    CoinPackedMatrix matrixByRow_;
146
147    // Down locks
148    unsigned short * downLocks_;
149
150    // Up locks
151    unsigned short * upLocks_;
152
153    /// Extra down array (number Integers long)
154    double * downArray_;
155
156    /// Extra up array (number Integers long)
157    double * upArray_;
158
159    /// Array of priorities
160    typedef struct {
161      unsigned int direction:3; //  0 bit off, 1 bit (0 down first, 1 up first) 2 bit non zero don't try other way
162      unsigned int priority:29;
163    } PriorityType;
164    PriorityType * priority_;
165    // Indexes of binary variables with 0 objective coefficient
166    // and in variable bound constraints
167    std::vector<int> binVarIndex_;
168
169    // Indexes of variable bound rows for each binary variable
170    std::vector<int> vbRowIndex_;
171
172    // Percentage of integer variables to fix at bounds
173    double percentageToFix_;
174
175    // Maximum time allowed
176    double maxTime_;
177
178    // Small objective (i.e. treat zero objective as this)
179    double smallObjective_;
180
181    // Maximum number of major iterations
182    int maxIterations_;
183
184    // Maximum number of simplex iterations
185    int maxSimplexIterations_;
186
187    // Maximum number of simplex iterations at root node
188    int maxSimplexIterationsAtRoot_;
189
190};
191#endif
192
Note: See TracBrowser for help on using the repository browser.