summaryrefslogtreecommitdiff
path: root/build/Bonmin/include/coin/CbcHeuristicDive.hpp
blob: ea583dbe4a92bb5a3be4a7d6bd1bdf70b6f01208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* $Id: CbcHeuristicDive.hpp 2093 2014-11-06 16:17:38Z forrest $ */
// Copyright (C) 2008, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#ifndef CbcHeuristicDive_H
#define CbcHeuristicDive_H

#include "CbcHeuristic.hpp"
class CbcSubProblem;
class OsiRowCut;
struct PseudoReducedCost {
    int var;
    double pseudoRedCost;
};


/** Dive class
 */

class CbcHeuristicDive : public CbcHeuristic {
public:

    // Default Constructor
    CbcHeuristicDive ();

    // Constructor with model - assumed before cuts
    CbcHeuristicDive (CbcModel & model);

    // Copy constructor
    CbcHeuristicDive ( const CbcHeuristicDive &);

    // Destructor
    ~CbcHeuristicDive ();

    /// Clone
    virtual CbcHeuristicDive * clone() const = 0;

    /// Assignment operator
    CbcHeuristicDive & operator=(const CbcHeuristicDive& rhs);

    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * ) {}

    /// Create C++ lines to get to current state - does work for base class
    void generateCpp( FILE * fp, const char * heuristic);

    /// Resets stuff if model changes
    virtual void resetModel(CbcModel * model);

    /// update model (This is needed if cliques update matrix etc)
    virtual void setModel(CbcModel * model);

    //  REMLOVE using CbcHeuristic::solution ;
    /** returns 0 if no solution, 1 if valid solution
        with better objective value than one passed in
        Sets solution values if good, sets objective value (only if good)
        This is called after cuts have been added - so can not add cuts
        This does Fractional Diving
    */
    virtual int solution(double & objectiveValue,
                         double * newSolution);
    /// inner part of dive
    int solution(double & objectiveValue, int & numberNodes,
		 int & numberCuts, OsiRowCut ** cuts,
		 CbcSubProblem ** & nodes,
		 double * newSolution);
    /** returns 0 if no solution, 1 if valid solution
        with better objective value than one passed in
	also returns list of nodes
        This does Fractional Diving
    */
    int fathom(CbcModel * model, int & numberNodes,CbcSubProblem ** & nodes);

    /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
    virtual void validate();

    /// Sets priorities if any
    void setPriorities();

    /// Select candidate binary variables for fixing
    void selectBinaryVariables();

    /// Set percentage of integer variables to fix at bounds
    void setPercentageToFix(double value) {
        percentageToFix_ = value;
    }

    /// Set maximum number of iterations
    void setMaxIterations(int value) {
        maxIterations_ = value;
    }

    /// Set maximum number of simplex iterations
    void setMaxSimplexIterations(int value) {
        maxSimplexIterations_ = value;
    }
    /// Get maximum number of simplex iterations
    inline int maxSimplexIterations() const {
        return maxSimplexIterations_;
    }

    /// Set maximum number of simplex iterations at root node
    void setMaxSimplexIterationsAtRoot(int value) {
        maxSimplexIterationsAtRoot_ = value;
    }

    /// Set maximum time allowed
    void setMaxTime(double value) {
        maxTime_ = value;
    }

    /// Tests if the heuristic can run
    virtual bool canHeuristicRun();

    /** Selects the next variable to branch on
        Returns true if all the fractional variables can be trivially
        rounded. Returns false, if there is at least one fractional variable
        that is not trivially roundable. In this case, the bestColumn
        returned will not be trivially roundable.
    */
    virtual bool selectVariableToBranch(OsiSolverInterface* solver,
                                        const double* newSolution,
                                        int& bestColumn,
                                        int& bestRound) = 0;
    /** Initializes any data which is going to be used repeatedly
        in selectVariableToBranch */
    virtual void initializeData() {}

    /// Perform reduced cost fixing on integer variables
    int reducedCostFix (OsiSolverInterface* solver);
    /// Fix other variables at bounds
    virtual int fixOtherVariables(OsiSolverInterface * solver,
                                  const double * solution,
                                  PseudoReducedCost * candidate,
                                  const double * random);

protected:
    // Data

    // Original matrix by column
    CoinPackedMatrix matrix_;

    // Original matrix by
    CoinPackedMatrix matrixByRow_;

    // Down locks
    unsigned short * downLocks_;

    // Up locks
    unsigned short * upLocks_;

    /// Extra down array (number Integers long)
    double * downArray_;

    /// Extra up array (number Integers long)
    double * upArray_;

    /// Array of priorities
    typedef struct {
      unsigned int direction:3; //  0 bit off, 1 bit (0 down first, 1 up first) 2 bit non zero don't try other way
      unsigned int priority:29;
    } PriorityType;
    PriorityType * priority_;
    // Indexes of binary variables with 0 objective coefficient
    // and in variable bound constraints
    std::vector<int> binVarIndex_;

    // Indexes of variable bound rows for each binary variable
    std::vector<int> vbRowIndex_;

    // Percentage of integer variables to fix at bounds
    double percentageToFix_;

    // Maximum time allowed
    double maxTime_;

    // Small objective (i.e. treat zero objective as this)
    double smallObjective_;

    // Maximum number of major iterations
    int maxIterations_;

    // Maximum number of simplex iterations
    int maxSimplexIterations_;

    // Maximum number of simplex iterations at root node
    int maxSimplexIterationsAtRoot_;

};
#endif